qemu-img convert -f qcow2 mydisk.qcow2 -O raw mydisk.raw
dd if=/dev/zero of=mydisk.raw bs=1M count=0 seek=4096 (bs * seek must equal the total new size of drive)
sudo losetup /dev/loop0 mydisk.raw sudo fdisk /dev/loop0 sudo losetup -d /dev/loop0
qemu-img convert -f raw mydisk.raw -O qcow2 newmydisk.qcow2
sudo resize2fs /dev/sda1
sudo mkswap /dev/sda2 sudo swapon /dev/sda2
lomount -t ext3 -diskimage /path/to/file.img -partition 1 /mnt
Check, and confirm that /kvm will sustain a minimum of 20% free space:
~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 3.8G 1.2G 2.7G 30% / varrun 12G 84K 12G 1% /var/run varlock 12G 0 12G 0% /var/lock udev 12G 60K 12G 1% /dev devshm 12G 0 12G 0% /dev/shm /dev/mapper/vg_sda2-tmp 1.0G 33M 992M 4% /tmp /dev/mapper/vg_sda2-var 5.0G 236M 4.8G 5% /var /dev/mapper/vg_sda2-kvm 160G 127G 34G 79% /kvm
Check the “kvm” LV's current LSize:
~$ sudo lvs LV VG Attr LSize Origin Snap% Move Log Copy% kvm vg_sda2 -wi-ao 160.00G swap vg_sda2 -wi-ao 2.00G tmp vg_sda2 -wi-ao 1.00G var vg_sda2 -wi-ao 5.00G
Check the VFree size:
~$ sudo vgs VG #PV #LV #SN Attr VSize VFree vg_sda2 1 4 0 wz--n- 269.51G 101.51G
If you need to expand the logical volume, do so in 10GB chunks:
~$ sudo lvextend --size +10G /dev/vg_sda2/kvm Extending logical volume kvm to 170.00 GB Logical volume kvm successfully resized
Then, resize the filesystem:
~$ sudo resize_reiserfs /dev/vg_sda2/kvm resize_reiserfs 3.6.19 (2003 www.namesys.com) resize_reiserfs: On-line resizing finished successfully.
Confirm your work:
~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 3.8G 1.2G 2.7G 30% / varrun 12G 84K 12G 1% /var/run varlock 12G 0 12G 0% /var/lock udev 12G 60K 12G 1% /dev devshm 12G 0 12G 0% /dev/shm /dev/mapper/vg_sda2-tmp 1.0G 33M 992M 4% /tmp /dev/mapper/vg_sda2-var 5.0G 236M 4.8G 5% /var /dev/mapper/vg_sda2-kvm 170G 127G 44G 75% /kvm
Assign and document (69.30.44.0/26 or 69.30.44.128/26) an IP and MAC address.
Assign a hostname (test hosts are typically named after the real client name)
On an Ubuntu 8.04 server (Hardy), use the 'ubuntu-vm-builder' tool:
In the command below, replace the following items with their appropriate values, or set them in the environment.
$hostname | FQDN |
$ip | IP Address |
$gw | Default Gateway |
ubuntu-vm-builder kvm hardy \ --hostname $hostname \ --mem 256 \ --pass t00tyfruits \ --ip $ip \ --mask 255.255.255.192 \ --gw $gw \ --dns 4.2.2.2 \ --libvirt qemu:///system \ --addpkg openssh-server \ --addpkg cron \ --addpkg postfix \ --tmp /root/tmp \ --mirror http://mirrors.kernel.org/ubuntu \ -d /kvm/$hostname
During this build process, postfix will be installed; you will be prompted to select a default postfix configuration. Select No configuration.
passwd -u root
passwd root
deb http://mirrors.cat.pdx.edu/ubuntu/ hardy main restricted universe deb http://mirrors.cat.pdx.edu/ubuntu/ hardy-updates main restricted universe deb http://security.ubuntu.com/ubuntu/ hardy-security main restricted universe deb http://svn.opensourcery.com/public/ubuntu hardy main
sudo aptitude update; sudo aptitude upgrade
When prompted for the default LANGUAGE value, select UTF8 (default highlighted value).
Before puppet is installed and put into service, you may see the following error while running an apt-get or aptitude process:
perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_US.UTF-8"
Ignore the above error. Kris indicates that a 'locale' class, included in the puppet 'linux_base' class, resolves this during the host's initial puppet push/configuration.
sudo vmbuilder kvm ubuntu --suite=jaunty --flavour=virtual --arch=amd64 \ -o --libvirt=qemu:///system --tmpfs=- --templates=templates --user=myusername \ --name="My User Name" --pass=mypassword --addpkg=acpid --firstboot=boot.sh \ --mem=512 --hostname=vm1 --rootsize=15000 --swapsize=1250 qemu-img convert disk0.qcow2 -O raw disk0.raw dd if=disk0.raw of=/dev/vg01/vm1 bs=1M <disk type='block' device='disk'> <source dev='/dev/vg01/vm1'/> <target dev='hda' bus='ide'/> </disk>
Mainly on zaphod, if a VM guest begins to fsck it will crash. You have to unwrap the disk on the VM host and fsck. Disk files for hosts are stored under /kvm/<fqdn>.
qemu-img convert root.qcow2 -O raw root.raw losetup /dev/loop0 root.raw kpartx -a /dev/loop0 fsck /dev/mapper/loop0p1 kpartx -d /dev/loop0 losetup -d /dev/loop0 qemu-img convert root.raw -O qcow2 root.qcow2