Install Arch Linux on Virtual Machine With UEFI Support Enabled

A 'How-To' For LVM, with QEMU/KVM


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 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,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 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;
    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 ran gdisk (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.

    The same thing happened here. Another partition created to install Arch Linux there.

    Confirming the partitions available and their type before proceeding with the installation.

    Here, the ESP partition was formatted with FAT32 filesystem, and LVM building blocks were created specifically for Arch Linux system with EXT4 filesystem.

  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 into the Guest OS so that I no longer needed to wait for the packages to be downloaded) and continued with the general installation.
    ❗   Command for mounting hostshare:-
    mount -t 9p -o trans=virtio,version=9p2000.L hostshare /mnt/share
    Part of these steps may be seen in the images below:
    As explained above.

    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."
    View of the base system successfully installed on the intended partition.

    Just a part of configuration after chrooted into the new virtual Arch.

  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
    As explained above.

    As explained above.

    Ensuring that use_lvmetad is set to 1 in /etc/lvm/lvm.conf file.


    I purposely had the 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 into another system such as archiso since the grub config file will not be affected by the corruption occurred to the main system.


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