A 'How-To' For LVM, with QEMU/KVM
I honestly am not in the state where I can write a neat introduction for this specific action so I will just proceed to the steps I took for having this successfully done.
The step-by-step instructions are as follows:-
- I installed
ovmf
by following the instructions specified on thearchwiki
; - Then proceeded to boot the
archiso
onQEMU
.
This is the command that I used:-qemu-system-x86_64 -enable-kvm -m 2G \ -device intel-hda -device hda-duplex -device virtio-balloon \ -drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd \ -drive if=pflash,format=raw,file=/path-to-my_uefi_vars.fd \ -drive file=/path-to-linux.img,if=virtio \ -virtfs local,path=/path-to-shared-folder,mount_tag=hostshare,security_model=none,id=fsdev0 \ -cdrom /path-to-archlinux-x86_64.iso -boot d
I explain below what the commands are used for:-- -device intel-hda -device hda-duplex: I made it a habit to have the sound device loaded even though I do not need it for my VM;
- the next two lines:
To enable
UEFI
support as instructed in the archwiki; & - the next two lines before the last line:
Virtio
loaded to enable its block device as well asfolder/file
sharing from Host OS to Guest OS.
- Once booted, I created an
ESP
partition as well as aLinux LVM
partition withgdisk
. Both were formatted asFAT32
andEXT4
respectively;This is how it looks like when loading the archiso on UEFI bootloader with QEMU/KVM. Do ping a website like google.com to see if the VM has network connected. Here, I ran lsblk
to see the available block devices. Obviously the last line is the virtual disk available which was created before loading the VM.
I then rangdisk
(my favorite table partition app) of that particular block device intended for the VM, printed the list of partition which surely is empty and created a new partition for ESP which is required for UEFI bootloader. - I mounted the
LVM
partition on /mnt, created a mount point for a shared folder and mounted it through the 'hostshare
'mount_tag
(I did this to copy all the base packages installed on Host OS into the Guest OS so that I no longer needed to wait for the packages to be downloaded) and continued with the general installation. Part of these steps may be seen in the images below:Result of running the ls
command for the mounted shared partition which contain the packages already installed on my host OS.The packages folder from the shared drive was copied into the pacman folder in VM so that I could save some time instead of downloading all the required packages to install the base system.
Quoted from ArchWiki ;"You could omit the installation of the firmware package when installing in a virtual machine or container."
- Since Arch Linux was installed on a LVM partition, '
lvm2
' needs to be added to 'HOOKS
' line in/etc/mkinitcpio.conf
file before running mkinitcpio:- - After that, I installed
grub
(grub2) as well asefibootmgr
and add 'lvm
' to a line where it says 'GRUB_PRELOAD_MODULES
' in/etc/default/grub
file. Next, I mounted theESP
partition on/mnt/boot
and run the following commands:-grub-install --target=x86_64-efi --efi-directory=/mnt/boot --boot-directory=/mnt/boot --bootloader-id=GRUB grub-mkconfig -o /mnt/boot/grub/grub.cfg
Basically, these are all the actions done to have a bootable Arch Linux installed on QEMU/KVM with UEFI enabled. Therefore, I stop at this point and will continue with 'resizing the partition without losing data' in my next post.