Difference between revisions of "Mkinitcpio-btrfs"

From ArchWiki
Jump to navigation Jump to search
(btrfs-progs in [core])
(this article discusses an ancient fork of mkinitcpio (see comments on the AUR page) and has otherwise issues (see comments on the discussion page) -> redirect)
 
(58 intermediate revisions by 25 users not shown)
Line 1: Line 1:
[[Category:HOWTOs (English)]]
+
#REDIRECT: [[mkinitcpio]]
[[Category:Getting and installing Arch (English)]]
 
{{i18n|Installing on Btrfs root}}
 
 
 
This article explains how to install Archlinux on a single [[btrfs]] device '''without''' a separate boot partition by using the [[syslinux|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!  [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=35054394c4b3cecd52577c2662c84da1f3e73525 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]].}}
 
 
 
<pre>
 
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
 
</pre>
 
 
 
Take your time, it's not difficult but everything must succeed... you now have a btrfs subvolume (''__active'', your system vol) mounted at <code>/mnt</code>, for final use as <code>/</code>.  The last two steps --move the btrfs root to it's final location, and then --bind mounts <code>(btrfs-root)/boot</code> to <code>/mnt/boot</code>.  For now, <code>/boot</code> '''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 <code>/mnt/etc/pacman.d/mirrorlist</code>, and/or make other adjustments to <code>/mnt/etc/pacman.conf</code>.}}
 
 
 
<pre>
 
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
 
</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 ===
 
 
 
If you like, build [http://aur.archlinux.org/packages.php?ID=33376 mkinitcpio-btrfs] and install with:
 
 
 
<pre>
 
pacman -r /mnt -U mkinitcpio-btrfs
 
</pre>
 
 
 
After installing, add ''btrfs_advanced'' to the HOOKS section of <code>/mnt/etc/mkinitcpio.conf</code>, then rebuild the initramfs:
 
 
 
<pre>
 
nano /mnt/etc/mkinitcpio.conf
 
chroot /mnt mkinitcpio -p kernel26
 
</pre>
 
 
 
{{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 <code>/mnt/etc/fstab</code> ... <code>(btrfs-root)/boot</code> will be --bind mounted so kernel upgrades work:
 
 
 
<pre>
 
/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
 
</pre>
 
 
 
A properly functional fsck.btrfs is not available yet.
 
 
 
It is not necessary to add a <code>subvol=XX</code> 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).  <code>subvolid=0</code> corresponds to the btrfs root, and guarantees it will always be mounted correctly, even if the default is changed.
 
 
 
=== Installing the bootloader ===
 
 
 
<pre>
 
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
 
</pre>
 
 
 
Sample extlinux.conf:
 
 
 
<pre>
 
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
 
</pre>
 
 
 
If you '''ARE''' using the mkinitcpio hook, remove <code>rootflags=subvol=__active</code> from the APPEND line.
 
 
 
== Final ==
 
 
 
Almost done...  be sure to edit <code>/mnt/etc/rc.conf</code>, set the root password, and similar.  Good luck on reboot!
 
 
 
<pre>
 
cd /
 
umount /mnt/{dev,proc,sys,boot,var/lib/btrfs-root}
 
umount /mnt
 
reboot
 
</pre>
 
 
 
{{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.}}
 

Latest revision as of 16:43, 22 August 2016

Redirect to: