2.2 KiB
2.2 KiB
Linux+ 1.7.2: Managing virtual machines
Creating a VM from a cloud image with virt-install, suspending, resizing and shutting it down, and a snapshot to undo a mistake.
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 installs QEMU, libvirt and virt-install (the KVM host from chapter
1.7.1) and downloads a small cloud image, CirrOS, to
/var/lib/le-lab/images/cirros.img. Use it where the chapter downloads a
Rocky Linux or Ubuntu image (or download one of those yourself). Its user
is cirros, password gocubsgo.
Tasks
- Create a VM named
lab1from the cloud image: copy it to/var/lib/libvirt/images/lab1.qcow2, grow that to 10 GiB, and import it with virt-install, with 1 GiB of memory, one vCPU, a VirtIO disk, a VirtIO network card on thedefaultnetwork, and a generated root password from cloud-init.virsh list --allshows it, andvirsh domifaddr lab1shows its address once it has booted. - Suspend and resume
lab1, give it 768 MiB of memory while it runs, then shut it down. Not graded. - Start
lab1again, snapshot it asclean, break something inside it (log in onvirsh console lab1and runrm -rf /etc/ssh; Ctrl+] leaves the console), and revert to the snapshot.
When le-lab check passes, clean up as the chapter shows (task 4: delete
the snapshot, then destroy and undefine lab1 with its storage), or leave
it to le-lab reset.
Hints
- On the RHEL family, start the libvirt sockets first:
systemctl enable --now virtqemud.socket virtnetworkd.socket virtstoraged.socket. qemu-img resize;virt-install --import --disk PATH,bus=virtio --network network=default,model=virtio --os-variant detect=on,require=off --cloud-init root-password-generate=on --noautoconsole.virsh suspend,virsh resume,virsh setmem lab1 768M --live,virsh shutdown,virsh domstate; CirrOS may ignorevirsh shutdownwhile it's still booting, andvirsh destroypowers it off.virsh snapshot-create-as lab1 clean,virsh snapshot-list lab1,virsh snapshot-revert lab1 clean.