Install Alpine on a btrfs filesystem with refind as boot manager

From Alpine Linux

This Tutorial is about installing Alpine Linux as a btrfs subvolume Dualbooting with another Linux distribution and uses refind as boot manager.

Note: This tutorial assumes that your other OS is already installed and working with rEFInd as boot manager and your harddisk filesystem is btrfs. Eventhough, refind is available in the testing repository of Alpine Linux, this tutorial does not need it to be installed.

The below instructions are based on below partition layout as shown by blkid command.

 
/dev/nvme0n1p1: UUID="55C3-8AB4" TYPE="vfat"
/dev/nvme0n1p2: UUID="dab64e31-fb89-4364-b90f-b79400f73304" TYPE="swap"
/dev/nvme0n1p3: LABEL="BTRFSVOL" UUID="823a3283-30a7-4fef-b50b-8a2230c71b5b" TYPE="btrfs"
  1. Complete the Installation until the base configuration step.
  2. Once base configuration is complete, Identify your partition name and note the LABEL for the btrfs filesystem by using the command.

    # blkid

  3. Mount the btrfs partition to /mnt.

    # mount /dev/nvme0n1p3 /mnt -t btrfs

  4. To create a Btrfs subvolume for Alpine Linux install the btrfs-progs package .

    # apk add btrfs-progs

  5. Create a new Btrfs subvolume for Alpine.

    # btrfs subvolume create /mnt/@alpine

  6. Unmount the btrfs partition.

    # umount /mnt

  7. Mount the newly created subvolume to /mnt.

    # mount -o subvol=@alpine /dev/nvme0n1p3 /mnt

  8. Install the base system using the below command:

    # setup-disk -m sys /mnt

  9. This will install the base system to the mounted subvolume. Once the base system is installed, chroot into the new system:

    # chroot /mnt

  10. Check and ensure that /etc/fstab uses the correct subvolume for the root entry like below. Mounting the efi partition is optional. If you want to share your @home subvolume between both the operating systems, you can also add an entry for it now.

    Contents of /etc/fstab

    UUID=823a3283-30a7-4fef-b50b-8a2230c71b5b / btrfs rw,relatime,compress=zlib:3,ssd,discard=async,space_cache=v2,subvol=/@alpine 0 1 UUID=55C3-8AB4 /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro 0 2
  11. Verify linux kernel is installed successfully.

    # apk list --installed |grep lts

  12. If your other OS is already installed and working with refind as boot manager, then there is no need to install refind again. You may want to remove the grub and grub-efi packages.

    # apk del grub grub-efi

  13. Exit the chroot.

    # exit

  14. Mount the EFI partition to edit the refind.conf file.

    # mkdir /mnt/boot/efi && mount dev/nvme0n1p1 /mnt/boot/efi

  15. Edit /mnt/os/boot/efi/EFI/refind/refind.conf to boot alpine by adding an entry for Alpine Linux as shown below:

    Contents of /boot/efi/EFI/refind/refind.conf

    menuentry "Alpine Linux" { volume "BTRFSVOL" loader @alpine/boot/vmlinuz-lts initrd @alpine/boot/initramfs-lts options "root=UUID=823a3283-30a7-4fef-b50b-8a2230c71b5b rw rootflags=subvol=@alpine rootfstype=btrfs" }
  16. Unmount everything

    # umount -R /mnt

  17. Reboot your system.

    # reboot

  18. Now, you should now see an option to boot into Alpine Linux in the rEFInd boot menu.


See Also