2.3 KiB
2.3 KiB
LFCS 1.6: Virtual machines
Installing libvirt, creating a VM from a cloud image, autostart, more memory and a second disk, snapshots, and deleting a VM.
Before you start
The VM you run this lab on needs nested virtualization (the CPU flag
vmx or svm inside it) and about 6 GiB of memory, plus internet access.
The lab downloads a small cloud image, CirrOS, to
/var/lib/le-lab/images/cirros.img; it needs no login for these tasks.
libvirt isn't installed: that's part of task 1.
Tasks
- Install libvirt and create a VM named
web1with 1 GiB of memory from the cloud image.virsh list --allshowsweb1running andvirsh domifaddr web1shows an address (give it a minute to boot). - Make
web1start whenever the host boots. - Give
web12 GiB of memory and a second 5 GiB disk that stay after it's restarted. Aftervirsh shutdownandvirsh start,virsh dominfoshows 2097152 KiB andvirsh domblklist web1shows two disks. CirrOS may ignorevirsh shutdownwhile it's still booting;virsh destroypowers it off. - Snapshot
web1, create a file inside the guest, and revert. Keep the snapshot. Check the revert yourself: the file is gone (log in onvirsh console web1as usercirros, passwordgocubsgo). - Create a second VM,
web2, from the same image, and take a snapshot of it. Write the full paths ofweb2's disk files to/root/lab-answers/5, one per line. Then deleteweb2and its disks:virsh destroy web2, delete its snapshots (virsh snapshot-delete, or add--snapshots-metadata), thenvirsh undefine web2 --remove-all-storage.
Hints
qemu-kvm libvirt virt-installon RHEL relatives;qemu-system-x86 libvirt-daemon-system virtinston Ubuntu. Ifvirsh listcan't connect on a RHEL relative, start thevirt*dsockets (the chapter has the loop).qemu-img create -f qcow2 -F qcow2 -b BACKING NEW.qcow2,virt-install --import,virt-install --osinfo list.virsh net-start default,virsh net-autostart default.virsh autostart,virsh dominfo.virsh setmaxmemandvirsh setmemwith--config;virsh attach-disk --persistent.virsh snapshot-create-as,virsh snapshot-list,virsh snapshot-revert.virsh domblklist,virsh undefine --remove-all-storage.