Difference between revisions of "Mkinitcpio-btrfs"

From ArchWiki
Jump to: navigation, search
(btrfs-progs in [core])
m (btrfs-progs-unstable: btrfs-progs is now in [core])
Line 61: Line 61:
 
# ... to remove grub
 
# ... to remove grub
 
</pre>
 
</pre>
 
==== btrfs-progs-unstable ====
 
 
Don't forget to also install the btrfs-progs-unstable package onto the new system. Without doing so, users will not be able to anything interesting with the filesystem.
 
  
 
=== AUR Packages ===
 
=== AUR Packages ===

Revision as of 10:21, 12 July 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

This article explains how to install Archlinux on a single btrfs device without a separate boot partition by using the extlinux bootloader. It notes the lack of swap file support. The mkinitcpio-btrfs initramfs hook providing rollback support is graced.

This setup does not support btrfs RAID because a separate boot partition/device is needed, ie. only one drive allowed. Pending releases of mkinitcpio-btrfs will attempt to provide solutions.

Warning: btrfs is experimental; article provided for academic use only.

Preparation

btrfs-progs package is now in [core] repo.

System to use for installation

It is recommended to boot and install using the lastest Archlinux image, another Archlinux system, or Archboot. The latter is capable of installing to a btrfs partition natively but does not support the unified setup detailed here; it is however a good option for this procedure because it includes recent builds of all the necessary packages.

Prepare hard drive

Create a partition for the installation, or allow btrfs to consume an entire device [recommended]. If you need swap support, either make a partition, or use the loop method detailed below. DO NOT simply use a swap file! Doing so will corrupt your btrfs filesystem. Mounting via loop device *probably* prevents this [unconfirmed].

Create/prepare the btrfs filesystem

Note: The following assumes you have dedicated an entire device to btrfs.
Tip: __active and __snapshot chosen for integration with current mkinitcpio-btrfs.
mkfs.btrfs -L btrfs-root /dev/sda
mkdir /btrfs
mount /dev/sda /btrfs
btrfs subvolume snapshot /btrfs /btrfs/__active
mkdir /btrfs/boot
mkdir /btrfs/__snapshot
mkdir /btrfs/__active/boot
mount -o subvol=__active /dev/sda /mnt
mkdir -p /mnt/var/lib/btrfs-root
mount --move /btrfs /mnt/var/lib/btrfs-root
mount --bind /mnt/var/lib/btrfs-root/boot /mnt/boot

Take your time, it's not difficult but everything must succeed... you now have a btrfs subvolume (__active, your system vol) mounted at /mnt, for final use as /. The last two steps --move the btrfs root to it's final location, and then --bind mounts (btrfs-root)/boot to /mnt/boot. For now, /boot MUST NOT be within a subvolume; syslinux cannot directly boot, or properly look within, subvolumes.

Installing the system

My favorite way of installing Archlinux, the manual installation :-)

Base

Note: You may need to uncomment a mirror from /mnt/etc/pacman.d/mirrorlist, and/or make other adjustments to /mnt/etc/pacman.conf.
cd /mnt
mkdir -p dev proc sys var/lib/pacman
mount -o bind /dev dev
mount -t proc none proc
mount -t sysfs none sys
pacman -r . -Sy base syslinux --ignore grub
# --ignore is currently broken for groups, use ...
# pacman -r . -Rd grub
# ... to remove grub

AUR Packages

If you like, build mkinitcpio-btrfs and install with:

pacman -r /mnt -U mkinitcpio-btrfs

After installing, add btrfs_advanced to the HOOKS section of /mnt/etc/mkinitcpio.conf, then rebuild the initramfs:

nano /mnt/etc/mkinitcpio.conf
chroot /mnt mkinitcpio -p kernel26
Tip: btrfs_advanced is needed specifically for rollback or multi-device (RAID) support, and the standard btrfs hook is needed only for multi-device support. The kernel is capable of booting a single-device btrfs root on it's own (see below).

/etc/fstab

Tip: Locations chosen for integration with upcoming release of mkinitcpio-btrfs

Add everything to /mnt/etc/fstab ... (btrfs-root)/boot will be --bind mounted so kernel upgrades work:

/dev/disk/by-label/btrfs-root  /                    btrfs  defaults,noatime             0  0
/dev/disk/by-label/btrfs-root  /var/lib/btrfs-root  btrfs  defaults,noatime,subvolid=0  0  0
/var/lib/btrfs-root/boot       /boot                none   bind                         0  0

A properly functional fsck.btrfs is not available yet.

It is not necessary to add a subvol=XX option for /, as it must be handled by either the initramfs [btrfs_advanced] or via the kernel boot line [extlinux], and it may not be accurate anyways (e.g. rollback mode). subvolid=0 corresponds to the btrfs root, and guarantees it will always be mounted correctly, even if the default is changed.

Installing the bootloader

cd /mnt
mkdir boot/extlinux
cp usr/lib/syslinux/*.c32 boot/extlinux
cat usr/lib/syslinux/mbr.bin > /dev/sda
chroot . extlinux --install /var/lib/btrfs-root/boot/extlinux
nano boot/extlinux/extlinux.conf

Sample extlinux.conf:

PROMPT 0
TIMEOUT 0
DEFAULT arch

LABEL arch
    KERNEL /boot/vmlinuz26
    INITRD /boot/kernel26.img
    APPEND root=/dev/disk/by-label/btrfs-root rootflags=subvol=__active ro

If you ARE using the mkinitcpio hook, remove rootflags=subvol=__active from the APPEND line.

Final

Almost done... be sure to edit /mnt/etc/rc.conf, set the root password, and similar. Good luck on reboot!

cd /
umount /mnt/{dev,proc,sys,boot,var/lib/btrfs-root}
umount /mnt
reboot
Warning: Rollback support, while fully functional, currently has one important caveat... it cannot handle kernel rollbacks because the kernel is not a part of the snapshot. This is due to the limitations of the bootloader described above. Until bootloaders support subvolumes, you must remember to manually backup your kernel + initramfs before a snapshot. Upcoming releases of mkinitcpio-btrfs will attempt to address this shortcoming.