Btrfs boot

From PCLinuxOS Knowledgebase
Jump to navigation Jump to search
  • Relevant to all editions of PCLinuxOS.

This page deals with installing and running PCLinuxOS from a BTRFS filesystem.

Booting BTRFS subvolumes

Although the PCLinuxOS installer will format and install to BTRFS partitions it will NOT use subvolumes. This procedure will take a standard installation on BTRFS partitions and convert them to use subvolumes at boot time. This is intended for advanced users that understand BTRFS subvolumes and Linux boot and File System administration.

In this procedure:

  • /dev/sda1 is the root partition
  • /dev/sda5 is the home partition

When the normal PCLinuxOS installation is finished and tested, reboot the live media. Then open a terminal and follow the following steps :

1. Mount the partitions and create the subvolumes

    mkdir /mnt
    mkdir /mnt/sda1 && mount /dev/sda1 /mnt/sda1
    mkdir /mnt/sda5 && mount /dev/sda5 /mnt/sda5
    btrfs subvolume create /mnt/sda1/@boot
    btrfs subvolume create /mnt/sda1/@root
    btrfs subvolume create /mnt/sda5/@home

2. Mount the subvolumes

    mkdir /mnt/root && mount -o subvol=@root /dev/sda1 /mnt/root
    mkdir /mnt/boot && mount -o subvol=@boot /dev/sda1 /mnt/boot
    mkdir /mnt/home && mount -o subvol=@home /dev/sda5 /mnt/home

3. Move the data to the subvolumes

    shopt -s extglob
    cd /mnt/sda1
    mv ./boot/* /mnt/boot
    mv !(@*) /mnt/root
    cd /mnt/sda5
    mv !(@*) /mnt/home
    cd

4. Unmount everything, then remount correctly using subvolumes and enter a chroot

    for i in /home /boot /root /sda5 /sda1; do umount /mnt$i; done
    mkdir /mnt/chroot
    mount -o subvol=@root /dev/sda1 /mnt/chroot
    mount -o subvol=@boot /dev/sda1 /mnt/chroot/boot
    for i in /sys /proc /dev; do mount -B $i /mnt/chroot$i; done
    chroot /mnt/chroot

5. Edit /etc/fstab to correctly mount the subvolumes

  • The entries should look something like:
    # Entry for /dev/sda1 :
    /dev/sda1 / btrfs relatime,subvol=@root 1 1
    # Entry for /dev/sda5 :
    /dev/sda5 /home btrfs relatime,subvol=@home 1 2
    none /proc proc defaults 0 0
    none /dev/pts devpts defaults 0 0

6. Reinstall GRUB2 and remake the configuration

    grub2-install /dev/sda
    update-grub2

7. Remake the initrd which should include the btrfs module

    mkinitrd -f -v /boot/initrd-$(uname -r).img $(uname -r)

Once this is done you exit the chroot, unmount everything and reboot into the new system. Good luck!