====== KVM Management ====== * ssh to kvm server `ssh garkbit` * run `virt-manager` ====== Resize Qemu Image ====== * Convert the qcow2 disk image to raw format if needed qemu-img convert -f qcow2 mydisk.qcow2 -O raw mydisk.raw * Resize the raw image using dd (the file contents is not touched) dd if=/dev/zero of=mydisk.raw bs=1M count=0 seek=4096 (bs * seek must equal the total new size of drive) * Use losetup and fdisk to massage the image (while in fdisk: note swap's size, delete both partitions, recreate "/" with enough space for swap's size, then create a 2nd partition of type 82). sudo losetup /dev/loop0 mydisk.raw sudo fdisk /dev/loop0 sudo losetup -d /dev/loop0 * Convert back to the qcow2 format if originally in this format (only used blocks will take up diskspace) qemu-img convert -f raw mydisk.raw -O qcow2 newmydisk.qcow2 * Boot VM, and resize / sudo resize2fs /dev/sda1 * Recreate swap & turn swapon sudo mkswap /dev/sda2 sudo swapon /dev/sda2 ====== Mount Raw Image ====== lomount -t ext3 -diskimage /path/to/file.img -partition 1 /mnt ====== Removing KVM Host ====== ===== Update puppet certificate ===== See [[puppetoverview#update_puppet_certificate]] ====== New KVM Host ====== ===== Bootstrapping ===== ==== Expand /kvm Partition ==== * Always maintain /kvm with a minimum of 20% free disk space, expand if needed. 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 ==== VM Identification ==== === IP & MAC Address === Assign and document ([[69.30.44.0_26|69.30.44.0/26]] or [[69.30.44.128_26|69.30.44.128/26]]) an IP and MAC address. * Any IP address not on [[69.30.44.0_26|69.30.44.0/26]] must have the bridge group modified, br1 for example: * Typically the last octet is put into the MAC address of de:ad:00:00:0x:xx * Example: IP=69.30.44.158, MAC=de:ad:00:00:01:58 === Hostname === Assign a hostname (test hosts are typically named after the **real** client name) ==== Build Host ==== 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 === Postfix Package Question === During this build process, postfix will be installed; you will be prompted to select a default postfix configuration. Select **No configuration**. ===== While VM instance is building ===== * add the hostname to appropriate DnsServers * start building your puppet manifest (or copy and edit an existing one) * Note: puppetmaster must be restarted for new node manifests. * Update zaphod puppet manifest with the proper libvirt kvm template * Note: use `uuidgen` to generate a unique UUID. ===== Once VM instance is running ===== ==== Set root's password ==== - Launch "virt-manager" on host-machine, as root - Login to new VM's console as 'ubuntu' - unlock root account passwd -u root - set root password passwd root ==== Apply latest package updates ==== === Update VM's /etc/apt/sources.list === 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 === SSH to VM and run === sudo aptitude update; sudo aptitude upgrade === UTF8 Question === When prompted for the default LANGUAGE value, select UTF8 (default highlighted value). ==== Install and update puppet ==== See [[PuppetOverview#install_and_update_puppet]] ====== Common Errors, Issues & Concerns ====== ===== Puppet ===== **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. ===== Shutdown Quirks ===== ==== Ubuntu 8.04 amd64 ==== * Manually touch and shutdown each VM, before powering-off the host. ===== Startup Quirks ===== ==== Ubuntu 8.04 amd64 ==== * Do not use SMP as it causes bare metal host instability * VMs must be brought online 3 at a time due to a clock issue. If too many VMs are booted at once, the VM clock runs very fast; the only fix is rebooting the VM. * Manually check all VM clocks after a bare metal reboot. ====== Ubuntu 9.04 Pre-Use Notes ====== 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 ====== Ubuntu 8.04 Fsck Error ====== 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/. 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 ====== See Also ====== * [[varntvar]] * [[vogon]] ====== Reference ====== * http://www.linux-kvm.org/page/FAQ * http://manpages.ubuntu.com/manpages/natty/man1/virsh.1.html * http://www.cyberciti.biz/faq/troubleshooting-kvm-virtualization-problem-with-log-files/