Using ubuntu-vm-builder with libvirt to create VM and install os
What is vmbuilder
With vmbuilder, there is no need to download a JeOS ISO anymore. vmbuilder will fetch the various package and build a virtual machine tailored for your needs in about a minute. vmbuilder is a script that automates the process of creating a ready to use Linux based VM. The currently supported hypervisors are KVM and Xen.
What is libvirt The libvirt library is used to interface with different virtualization technologies.
With vmbuilder, there is no need to download a JeOS ISO anymore. vmbuilder will fetch the various package and build a virtual machine tailored for your needs in about a minute. vmbuilder is a script that automates the process of creating a ready to use Linux based VM. The currently supported hypervisors are KVM and Xen.
What is libvirt The libvirt library is used to interface with different virtualization technologies.
Step by step
Check that your CPU supports hardware virtualization
$ sudo apt-get install atfs
$ egrep -c '(vmx|svm)' /proc/cpuinfo
output != 0 表示有支援hardware virtualization
Installation of KVM, libvirt, ubuntu-vm-builder
$ sudo apt-get install kvm qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
$ sudo adduser YourUsername kvm
$ sudo adduser YourUsername libvirtd
check the groups exist
$ groups
Install Ubuntu VM builder
sudo apt-get install python-vm-builder
Modify /usr/lib/python2.7/dist-packages/VMBuilder/plugins/ubuntu/dapper.py
def unmount_dev(self):
self.context.cancel_cleanup(self.unmount_dev)
run_cmd('sync')
run_cmd('umount', '%s/dev' % self.context.chroot_dir)
Write a scrit to execute command(because the command a lot of parameter)
HOSTNAME=vm4
MEMORY=512
CPUS=1
DISK_SIZE=10000
IP=172.16.118.1
time vmbuilder kvm ubuntu \
-d /var/lib/libvirt/images/$HOSTNAME \
-m $MEMORY \
--cpus $CPUS \
--arch amd64 \
--hostname $HOSTNAME \
--domain test.com \
--ip $IP \
--mask 255.255.0.0 \
--gw 172.16.1.254 \
--dns 8.8.8.8 \
--bridge br0 \
--user wistor \
--pass wistor \
--suite oneiric \
--rootsize $DISK_SIZE \
--swapsize $MEMORY \
--flavour virtual \
--libvirt qemu:///system \
You can find the vm install completed in /var/lib/libvirt/images/$HOSTNAME
$HOSTNAME is your settings
Check the VM is exist
$ virsh list
Id Name State
----------------------------------
1 vm4 running
Host bridge settings
sudo apt-get bridge-utils
$ sudo vim /etc/network/interface
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 172.16.116.1
network 172.16.0.0
netmask 255.255.0.0
gateway 172.16.1.254
留言
張貼留言