Search code examples
linuxcentosvirtual-machinevirtualizationxen

xen create new virtual machine using command line


I want to create (CentOS) virtual machine using xen by virt-install command

I am using kickstart and put it in http://192.168.1.8/centos/kickstart.cfg
and put Centos 6.5 in http://192.168.1.8/centos/os/ enter image description here

use

[root@CentOS ~]# dd if=/dev/zero of=/var/lib/xen/images/vserver.img bs=1M count=4000

[root@CentOS ~]# virt-install -p -n vserver -r 512 -f /var/lib/xen/images/vserver.img -l http://192.168.1.8/centos/os -x ks=http://192.168.1.8/centos/kickstart.cfg -w bridge:xenbr0 --vcpus=1

the result

Starting install... ERROR Could not find an installable distribution at 'http://192.168.1.8/centos/os' The location must be the root directory of an install tree. Domain installation does not appear to have been successful. If it was, you can restart your domain by running: virsh --connect xen:/// start vserver otherwise, please restart your installation.


Solution

  • it's need the .treeinfo file,

    vi /var/www/html/centos/os/.treeinfo
    

    and add this lines:

    [general]
    family = CentOS
    timestamp = 1341518023.56
    variant = 
    totaldiscs = 1
    version = 6.5
    discnum = 1
    packagedir = 
    arch = i386
    
    [images-i386]
    
    initrd = images/pxeboot/initrd.img
    
    [images-xen]
    
    initrd = isolinux/initrd.img
    kernel = isolinux/vmlinuz
    
    [stage2]
    mainimage = images/install.img
    

    don't copy it directly from the browser, write it by keyboard or copy it to a text file first, in order to remove any special characters.

    finally give Apache ownership to the files:

    chown -R apache:apache /var/www/html/*
    

    In the virt-install command add the CentOS (URL) as string and use --bridge=xenbr0 instead of bridge:xenbr0

    [root@CentOS ~]# virt-install -p -n vserver -r 512 -f /var/lib/xen/images/vserver.img  -l "http://192.168.1.8/centos/os" -x -w --bridge=xenbr0 --vcpus=1
    

    P.S: change the arch field if you are using 64bit version to x86_64