Machine/template-focal: Difference between revisions
No edit summary |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 24: | Line 24: | ||
#* Basic Ubuntu Server | #* Basic Ubuntu Server | ||
#* OpenSSH server | #* OpenSSH server | ||
# GRUB: let the installer setup grub on /dev/ | # GRUB: let the installer setup grub on /dev/vda (which contains /boot) | ||
Line 38: | Line 38: | ||
The installer won't let you format the entire disk as a filesystem, so go ahead and partition | The installer won't let you format the entire disk as a filesystem, so go ahead and partition | ||
the 10GB disk too, then create a primary partition in it and format it as ext4, mounted as / | the 10GB disk too, then create a primary partition in it and format it as ext4, mounted as / | ||
and labeled "template- | and labeled "template-focal" ('''"template-focal-root" would exceed the ext4 limit'''). | ||
Preferably, when asked for size, remove the contents and replace it with 'max' | |||
And yes.. just in case you're wondering. We don't use swap partitions. | And yes.. just in case you're wondering. We don't use swap partitions. | ||
We'll have to fix the disk later. | We'll have to fix the disk later. | ||
== 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 |