Install Arch Linux on Qemu/KVM With Uefi Support Enabled

A 'How-To' For LVM


geeky stuff
#archlinux | #qemu | #kvm | #uefi | #lvm

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.

Brief Notes:-
  • Installation is done on Logical Volume Manager (LVM) partition;
  • Boot loader used is Grub2;
  • This is actually specifically set up to show how to resize a partition without losing any data which will be explained in the next entry. WARNING! Only tested on Ext4 formatted partition.

The step-by-step instructions are as follows:-

  1. I installed ovmf by following the instructions specified on the archwiki;
  2. Then proceeded to boot the archiso on Qemu.
    This is the command I used:-
    qemu-system-x86_64 -enable-kvm -m 1024M -soundhw hda \
    -drive if=pflash,format=raw,readonly,file=/usr/share/ovmf/x64/OVMF_CODE.fd \
    -drive if=pflash,format=raw,file=$HOME/qemu/linux/my_uefi_vars.bin \
    -drive file=$HOME/qemu/linux/linux.img,if=virtio \
    -fsdev local,security_model=passthrough,id=fsdev0,path=qemu/share -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \
    -cdrom $HOME/qemu/linux/archlinux-2017.08.01-x86_64.iso -boot d
    I explain below what the commands are used for:-
    • -soundhw hda: 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 network as well as folder/file sharing from Host OS to Guest OS.
  3. Once booted, I created an ESP partition as well as a Linux LVM partition with gdisk. Both were formatted as FAT32 and Ext4 respectively;

  4. 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 to 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:
  5. 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:-
  6. After that, I installed grub (grub2) as well as efibootmgr and add 'lvm' to a line where it says 'GRUB_PRELOAD_MODULES' in /etc/default/grub file. Next, I mounted the ESP 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


    I purposely had grub config file (via command line ‘grub-mkconfig’) on the ESP partition because should anything bad happen to the LVM partition containing the Arch Linux system, I can still boot another system such as archiso since the grub config file will not be affected by the corruption occurred to the main system.

    The WARNINGs about connection to lvmetad being failures are expected and can be ignored as advised on [archwiki].

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.



Kali terakhir halaman ini dikemaskini/disemak semula adalah pada .
Top