Multiple Operating Systems On Single Btrfs Partition
The goal
My scenario is that I want to “reinstall” my ArchLinux, but I don’t want to completely replace my installation, instead I want to add another instance of said ArchLinux. This method doesn’t involve external drives. We will add new btrfs subvolume and install new instance of ArchLinux there.
The process
Analyzing partition situation
Before we start installing, let’s examine present setup. In this case I have 2 partitions:
- EFI Partition - where bootloader is located
- Root partition - where our OS is installed
# fdisk -l
Disk /dev/nvme0n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: [...]
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 329DE734-DECF-40F1-A227-5C13DE22E5D7
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1230847 1228800 600M EFI System
/dev/nvme0n1p2 1230848 3907028991 3903700992 1.8T Linux filesystem
Create new btrfs subvolume
Mount the /dev/nvme0n1p2
device on /mnt
folder
# mount /dev/nvme0n1p2 /mnt
$ ls /mnt
home root var
Notice the existing home
root
and var
btrfs subvolumes.
Create new subvolume
# btrfs subvolume create /mnt/newroot
# umount /dev/mnt
Install ArchLinux
Mount newly created subvolume along with boot partition and home
subvolume and proceed with instructions on ArchLinux wiki.
# mount /dev/nvme0n1p2 -o subvol=newroot,compress=zstd /mnt
# mkdir /mnt/home /mnt/boot
# mount /dev/nvme0n1p1 /mnt/boot
# mount /dev/nvme0n1p2 -o subvol=home,compress=zstd /mnt/home
At the end, don’t forget to change your bootloader’s parameters.
In my case, I copied the contents of /boot/loader/entries/arch.conf
file into /boot/loader/entries/arch2.conf
.
And modified the subviolume target in boot options as seen below.
Before
title Arch Linux
linux /vmlinuz-linux-zen
initrd /intel-ucode.img
initrd /initramfs-linux-zen.img
options root=UUID=d0aeca77-5f3e-4122-b523-8bd9d18b186f rootflags=subvol=/@root quiet rw
After
title Arch Linux
linux /vmlinuz-linux-zen
initrd /intel-ucode.img
initrd /initramfs-linux-zen.img
options root=UUID=d0aeca77-5f3e-4122-b523-8bd9d18b186f rootflags=subvol=/@newroot quiet rw
which could be simplified by this command
# sed 's/root/newroot/g' /boot/loader/entries/arch.conf > /boot/loader/entries/arch2.conf'
Conclusion
You should have now two fully functioning installations of your operating systems. This setup didn’t require creating new partitions nor preparing external drive. All of it was done from existing ArchLinux installation.