Changes

Jump to navigation Jump to search
2,621 bytes added ,  11:48, 16 November 2020
Line 25: Line 25:  
#* OpenSSH server
 
#* OpenSSH server
 
# GRUB: let the installer setup grub on /dev/vda (which contains /boot)
 
# GRUB: let the installer setup grub on /dev/vda (which contains /boot)
 +
 +
 +
== Switch the root filesystem to an LV ==
 +
 +
When the machine is offline, go to the host to recreate the root filesystem directly as an LV (as opposed to a partitioned volume)
 +
 +
First of all, we need to set up the device mapping for the first and only partition where the root filesystem resides.
 +
 +
kpartx -av  /dev/justice/template-focal-root
 +
 +
Mount the root partition:
 +
 +
mkdir /mnt/template-focal-root
 +
mount /dev/mapper/justice-template--focal-root1 /mnt/template-focal-root
 +
 +
Now create and format a new LV:
 +
 +
  lvcreate -L 10G -n template-focal-root2 justice
 +
  mkfs.ext4 -L template-focal -O flex_bg,extent,uninit_bg,sparse_super /dev/justice/template-focal-root2
 +
  tune2fs -c -1 -i 0 /dev/justice/template-focal-root2
 +
  mkdir /mnt/template-focal-root2
 +
  mount /dev/justice/template-focal-root2 /mnt/template-focal-root2
 +
 +
Move the files over:
 +
 +
  rsync -HAXphax --numeric-ids /mnt/template-focal-root/ /mnt/template-focal-root2/
 +
 +
'''NOTE''': By default, Ubuntu 20.04 uses UUID in /etc/fstab in order to mount partitions. Since we have changed the root
 +
partition to a new disk, the UUID will change. Aside from that, the grub.cfg also specifies the location of the root filesystem
 +
using UUID notation (ex: /vmlinuz-4.4.0-89-generic root=UUID=0ad5d004-e5dd-4b93-abe4-2bb0ba4fd94a).
 +
 +
Before we umount the filesystems, let's create a chroot environment and fix previous issues:
 +
 +
  kpartx -av /var/lib/libvirt/images/boot/template-focal-boot.img
 +
  mount /dev/mapper/loop0 /mnt/template-focal-root2/boot
 +
  mount --bind /dev/ /mnt/template-focal-root2/dev/
 +
  mount -t proc proc /mnt/template-focal-root2/proc/
 +
  mount -t sysfs sys /mnt/template-focal-root2/sys/
 +
  chroot /mnt/template-focal-root2/
 +
 +
Once inside the chroot environment:
 +
 +
* Fix serial console access by making getty listen on /dev/ttyS0:
 +
  systemctl enable serial-getty@ttyS0.service
 +
 +
* Replace UUID with device name for root fs location inside /boot/grub/grub.cfg
 +
  sed -i -r "s/root=UUID=[0-9a-f-]+/root=\/dev\/vdb/" /boot/grub/grub.cfg
 +
 +
* Adjust /etc/fstab to mount the filesystems from "LABEL=boot" and "LABEL=template-focal".
 +
 +
 +
Finally (VERY IMPORTANT), umount all filesystems before starting the VM:
 +
  umount /mnt/template-focal-root2/boot/
 +
  umount /mnt/template-focal-root2/dev/
 +
  umount /mnt/template-focal-root2/proc/
 +
  umount /mnt/template-focal-root2/sys/
 +
  umount /mnt/template-focal-root2/ /mnt/template-focal-root/
 +
 +
Get rid of the old root and rename the new one on top of it
 +
 +
  kpartx -d /var/lib/libvirt/images/boot/template-focal-boot.img
 +
  lvremove /dev/justice/template-focal-root
 +
  lvrename justice template-focal-root2 template-focal-root
    
== Partitioning ==
 
== Partitioning ==
79

edits

Navigation menu