Posts Tagged XenServer

How to create the first VM on XenServer automatically without XenCenter

Environment:
httprepo: 192.168.92.128
xenserver: 192.168.92.140
vm: 192.168.92.142

1. Create a http repo
# yum install httpd
# wget http://linux.mirrors.es.net/centos/6/isos/x86_64/CentOS-6.4-x86_64-minimal.iso

# mkdir -p /var/www/html/repo/centos/6
# mkdir /var/www/html/repo/ks
# mount -o loop CentOS-6.4-x86_64-minimal.iso /var/www/html/repo/centos/6/

# service httpd start

2. Create the kickstart configuration file
# vi /var/www/html/repo/ks/centos-6.4-x86_64-minimal.ks

cmdline
skipx
install
cdrom
lang en_US.UTF-8
keyboard us

network --onboot yes --device eth0 --bootproto=static --ip=192.168.92.142 --netmask=255.255.255.0 --gateway=192.168.92.2 --nameserver=192.168.92.2 --noipv6

rootpw mypasswd

firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Etc/UTC

bootloader --location=mbr --driveorder=xvda --append="crashkernel=auto"

zerombr
clearpart --all --initlabel
autopart

reboot

%packages --nobase
@core
%end

3. Install the first vm automatically
Get the Local storage uuid
# xe sr-list | grep -C 1 "Local"

uuid ( RO) : fbeda99f-b5a7-3100-5e3d-fbb48a46fca0
name-label ( RW): Local storage
name-description ( RW):

Create an empty vm
# xe vm-install new-name-label=centos6_template sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 template=Other\ install\ media

2fe3c706-9506-50d5-a557-0d61ebde651b

Configure the cpu,memory of the vm
# xe vm-param-set VCPUs-max=1 uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set VCPUs-at-startup=1 uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

# xe vm-param-set memory-dynamic-max=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-static-max=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-dynamic-min=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-static-min=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

Configure the bootloader,httprepo,kickstart of the vm installation
# xe vm-param-set HVM-boot-policy="" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set PV-bootloader="eliloader" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set other-config:install-repository="http://192.168.92.128/repo/centos/6/" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set PV-args="ip=192.168.92.142 netmask=255.255.255.0 gateway=192.168.92.2 ns=192.168.92.2 noipv6 ks=http://192.168.92.128/repo/ks/centos-6.4-x86_64-minimal.ks ksdevice=eth0" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

Add a virtual disk to the vm
# xe vm-disk-add uuid=2fe3c706-9506-50d5-a557-0d61ebde651b sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 device=0 disk-size=20GiB

Make the virtual disk bootable
# xe vbd-list vm-uuid=2fe3c706-9506-50d5-a557-0d61ebde651b userdevice=0 params=uuid --minimal
d304bbbd-f4e2-d648-a668-fe6a803bc301

# xe vbd-param-set bootable=true uuid=d304bbbd-f4e2-d648-a668-fe6a803bc301

Create a network connection of the vm
# xe network-list bridge=xenbr0 --minimal
a6fcd4a1-fb61-6f73-2b31-2a20ad45e0cc

# xe vif-create vm-uuid=2fe3c706-9506-50d5-a557-0d61ebde651b network-uuid=a6fcd4a1-fb61-6f73-2b31-2a20ad45e0cc mac=random device=0
aaf0a04d-c721-fae8-aca1-eb63e047ea93

Start the VM, it will be installed automatically with basic packages and start sshd
# xe vm-start uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

4. Wait for 20 minutes then try to login the vm
# ssh root@192.168.92.142

The authenticity of host '192.168.92.142 (192.168.92.142)' can't be established.
RSA key fingerprint is d5:de:ac:6a:7f:33:0c:ca:84:aa:d5:62:43:d2:9a:23.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.92.142' (RSA) to the list of known hosts.
root@192.168.92.142's password: mypasswd
Last login: Thu Oct 10 22:17:48 2013 from 192.168.92.140
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog
[root@localhost ~]#

,

1 Comment

Fork me on GitHub