bersama catatan peribadi & teknikalnya.

#Lvm

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.

How to Resize A LVM Partition Without Losing Data With Gdisk
An Alternative to Parted/Gparted

This post is awfully outdated.

Warning!
  • Please back up your data prior to doing this. I will not be held liable should you incur any data loss by following this tutorial.
  • This action was done in a VM (QEMU/KVM) and was only tested on a partition formatted as EXT4. I cannot guarantee that it works with other type of formats.
  • Quoted from archwiki:
    "Warning: While enlarging, a file system can often be done on-line (i.e. while it is mounted), even for the root partition, shrinking will nearly always require to first unmount the file system so as to prevent data loss. Make sure your FS supports what you are trying to do."

As mentioned in my previous (Archived) entry, I am writing this post to explain how to resize a partition without losing any data with gdisk. By this, I mean resizing the physical partition itself, not the physical volume.
  1. Boot the archiso on the VM with QEMU. If you have installed grub on ESP partition, chances are you will be dropped to the installed grub bootloader as shown in [this image] instead of the one that comes with the archiso. In this case, press 'c' for a command-line and run commands as indicated in the image below in order to be able to boot into it:-
  2. Heads-Up: Do take note that I am shrinking my physical partition. Should there be a need for you to enlarge your physical partition, the order of the steps will be in the reverse/opposite sequence. In that case, you have to resize the involved partition with gdisk first, followed by pvresize and lastly lvresize.
    Please ensure that the file system is unmounted (in this case it would be the Logical Volume containing the / partition). One way to know is by running 'lsblk' command. It will list information about all available block devices including the MOUNTPOINT of those devices. If MOUNTPOINT returns no output for the device, that means it is not mounted.
    First, resize the Logical Volume and its file system all at once (with '-r' option) by running this command:
    lvresize -L new-size -r vgname>/lvname
  3. Next, run pvresize with the below command:-
    pvresize --setphysicalvolumesize new-size /dev/vdaX
    The new size of the PV is advisable to be slightly bigger than the shrunken LV's otherwise it may prompt you an error.
  4. And then, run 'gdisk /dev/vda', enter 'p' to print the partition table, and enter 'i' to obtain the information of the partition that we want to resize where we will take note of its Partition unique GUID.
  5. After that, enter 'd' and the number of the partition we want to delete. Create a new partition by entering 'n', enter a new size which I recommend being slightly bigger than the resized Physical Volume's and change the type of partition to Linux LVM (8e00) which is of the same type to the previous partition prior to deletion. Enter 'x' for expert command followed by letter 'c' to key in the partition's unique GUID which we took note of previously. Be careful with this action and ensure that the unique GUID is identical before writing the changes or otherwise you may encounter data loss.
  6. Reboot and see if the installed Arch system is booting successfully after the shrinking process.

Well, actually! There is an easier way to have this exact purpose done without all these hassles (with the exception of lvresize and pvresize. They are still required to be done before you execute the task with any partitioning tool of your choice, if you are shrinking it).

Use parted or Gparted!

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