bersama catatan peribadi & teknikalnya.

#Kvm

VM Arch Linux (UEFI); (LVM2 + XFS) dalam LUKS2 & Btrfs dalam LUKS2
QEMU/KVM (Manual)

  • Saya sediakan tulisan ini sebagai nota untuk rujukan saya sendiri.
  • I used the command provided in my previous post applicable for Linux (UEFI) to load the Live CD.
  • Walaupun tiada keperluan kerana saya memang sudah menggunakan sistem ini sebagai sistem operasi utama saya, tetapi apa yang saya catatkan ini berguna untuk saya aplikasikan bagi tujuan pemasangan di komputer riba sebagai hos di lain-lain masa. Pun begitu, sekiranya tuan / puan membaca dan menggunakan nota saya ini sebagai rujukan, perlu saya ingatkan bahawa akan ada beberapa perkara yang perlu dilaras mengikut keadaan misalnya sambungan WiFi tidak terpakai dalam VM tetapi ia perlu dikonfigurasi bagi sistem hos.

Sila pastikan sistem hos sudah bersambung dengan rangkaian Internet.

Perintah Baris QEMU/KVM: NVMe Emulation; Linux, FreeBSD & Windows 11 Sebagai Sistem Tetamu (Guest OSs)
Virtual Machines / Mesin Maya

Windows 11: Ada beberapa perkara yang perlu dilakukan untuk memasang VM Windows 11. Hal ini adalah diakibatkan oleh cip komputer (microcontroller) yang dilekatkan kepada motherboard di dalam kebanyakan peranti moden sekarang ini yang dinamakan sebagai Trusted Platform Module (TPM). Perlu pasang pakej swtpm terlebih dahulu sama ada dari git stefanberger / swtpm atau dari distribusi masing-masing. Arch Linux ada menyediakan pakej ini dalam repositori community.

Load Distribusi Linux (Live CD) di VM untuk UEFI
Dengan Aplikasi GUI Virt-Manager

Ada sesetengah orang, sebelum mula bereksperimentasi dengan pemasangan di mesin sebenar, mesti cuba melalui mesin maya dulu. Manalah tahu, kot-kot ada yang mahu cuba belajar dual-boot Windows dengan sistem Linux kan?

Jadi di sini, saya terangkan sikitlah cara untuk load live CD sistem operasi Linux dengan UEFI dibolehdayakan. Sebagaimana biasa, cedok dari ArchWiki-lah.

Oleh sebab saya gunakan Arch Linux, maka di sini juga saya akan gunakan live CD Arch Linux sebagai demo.

Pemasangan VM Windows 10 (Manual)
Dengan QEMU/KVM

DITULIS SEMULA SEBAGAI PENAMBAH BAIK.
Merata-rata mencari pelbagai sumber rujukan demi membolehkan perkara-perkara yang saya hajati berikut:-
  1. Pemasangan melalui QEMU/KVM secara manual.
  2. Penting perkara di atas ini kerana mahu set up samba untuk perkongsian direktori / fail.
    Satu-satunya kaedah untuk berkongsi direktori / fail apabila menggunakan aplikasi GUI virt-manager / virt-viewer melalui Spice WEBDAV Daemon adalah tidak stabil bagi saya. Disebabkan itu, saya beralih kepada kaedah manual ini yang membenarkan opsyen medium kepada samba.
  3. Dan dalam masa yang sama, masih boleh set up Spice Client demi memperolehi kemudahan menyalin (Clipboard; copy & paste) di antara kedua-dua sistem hos dan tetamu.

  4. Sila pastikan sistem hos sudah bersambung dengan rangkaian Internet.

Hantaran kali ini berkisar pemasangan Windows di mesin maya.

Install Arch Linux on Virtual Machine With UEFI Support Enabled
A 'How-To' For LVM, with QEMU/KVM

This post is awfully outdated.

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=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 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.
    :exclamation:   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.

Top