Xcp/xenserver automated installation of VMS with command line mode

Source: Internet
Author: User
Tags mkdir uuid ssh

Background information:
In my previous article, "Xcp/xenserver Automation creates and initializes a virtual machine," explains how to clone a VM and initialize it with a new host name, IP address, and so on by passing kernel parameters.
But before that, there should be another question, how can the first VM be created automatically? In order to solve this problem, I consulted a lot of people, but most of them gave me the answer is to use Xencenter.
But this is not what we want, after constant trial and error, finally successfully completed the first VM Automation installation, in fact, the principle is very simple, that is, through the command line VM initialization, binding virtual hard disk, network, and then through the Httprepo to the Network load ISO, Then cooperate with kickstart for automatic installation. But in a number of specific steps, but also a step-by-step trap, some very small parameters are set incorrectly will cause failure, and these, in the official document is basically ignored.
The following are the specific steps involved:

Environment Introduction:
httprepo:192.168.92.128
xenserver:192.168.92.140
vm:192.168.92.142

1. Create HTTP Repo

The code is as follows Copy Code

# 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 Kickstart configuration file

The
  code is as follows copy code

# 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 VM automatically
Get the local storage UUID

The code is as follows Copy Code

# XE Sr-list | Grep-c 1 "Local"

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


Initialize an empty VM

The code is as follows Copy Code

# XE Vm-install new-name-label=centos6_template sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 template=Other Install Media

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

Set the VM's CPU, memory

The code is as follows Copy Code

# 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

Setting up Bootloader,httprepo,kickstart for an automated installation VM

The code is as follows Copy Code
# 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= "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 hard disk to the VM

The code is as follows Copy Code
# XE Vm-disk-add uuid=2fe3c706-9506-50d5-a557-0d61ebde651b sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 device=0 Disk-size=20gib

Set virtual hard disk as bootable

The code is as follows Copy Code

# 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 for a VM

The code is as follows Copy Code

# 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, next, the VM will automate the installation of all the underlying packages and start the SSH service

The code is as follows Copy Code
# XE Vm-start uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

4. Wait about 20 minutes, login VM

The code is as follows Copy Code

# 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 your 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 22:17:48 2013 from 192.168.92.140
[Root@localhost ~]# ls
Anaconda-ks.cfg Install.log Install.log.syslog
[Root@localhost ~]#

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.