Using OSTree in Arch Linux

Those are some notes on how to get Arch Linux to boot from OSTree-managed file system trees. Note that this could be useful for other distributions as well, especially the part about tweaking an initramfs to boot with OSTree.

OStree installation

There are PKGBUILDs in the Arch User Repository (AUR) for the needed components. Install both:

If you use a tool to automate installing packages from the AUR, it is enough to instruct it to install ostree and linux-user-chroot For example using Yaourt:

yaourt -S linux-user-chroot ostree

Populating the local repository

Follow the general instructions in the GnomeOSTree page, but for the last step instruct ostadmin to skip generating the initramfs image: we will be tweaking an initramfs to support booting using OSTree later. Commands summary (as root):

ostadmin init
cd /ostree
ostree --repo=repo remote add gnome http://ostree.gnome.org/repo \
       trees/gnomeos-3.6-i686-{runtime,devel}
ostree-pull --repo=repo --related --depth=3 gnome
ostadmin deploy --checkout-only gnomeos-3.6-i686-devel

Tweaking the initramfs

Changing an existing initramfs is a dirty hack, but the good thing is that this way everything will work just fine, even complex setups which LVM and/or LUKS encryption in the root file system. The bottom line is: if your system is working now, it will work with ostree as well.

First, create a work directory, and unpack the current initramfs. Note that you may need to change unxz to gunzip/bunzip2 depending on the compression method of your initramfs. As root:

mkdir /tmp/workdir
cd /tmp/workdir
unxz -c /boot/initramfs-linux.img | bsdcpio -i

Edit the init script, scroll to the end, and add the following lines before the last line (the one that uses exec to switch to the actual filesystem):

if [ -n "${ostree}" ] && [ ! -d "/new_root/ostree/${ostree}" ] ; then
  ostree='current'
fi

if [ -n "${ostree}" ] && \
   [ -x /new_root/ostree/ostree-init ] && \
   [ -d "/new_root/ostree/${ostree}" ]
then
  msg ":: Booting OSTree '${ostree}'"
  msg "::   command: ostree-init /new_root ${ostree} /sbin/init $*"
  exec env -i "TERM=$TERM" /new_root/ostree/ostree-init \
    "/new_root" "${ostree}" /sbin/init "$@" || true
  msg ":: Failed OSTree boot, will do a normal one :-("
fi

Note that the snippet above uses the ${ostree} variable, which was not defined anywhere. This will be passed as an argument in the kernel command line from the bootloader. Now, re-pack the initramfs and save it with a different name:

find . -print0 | bsdcpio -R 0:0 -0oH newc | xz --check=crc32 > /boot/initramfs-gnomeos.img

Adding a GRUB entry

You will need to add an entry to the GRUB configuration file that uses the modified initramfs, and passes a non-empty ostree= parameter in the kernel command line. As an example, this is how my entry looks like:

title  GNOME OS [/boot/vmlinuz-linux]
root   (hd0,0)
kernel /vmlinuz-linux root=/dev/mapper/vg-root cryptdevice=/dev/sda2 lvmcrypt ro quiet ostree=current
initrd /initramfs-gnomeos.img

As a rule of thumb, one can copy the default entry, change the path to use the modified initramfs and edit the kernel line to add ostree=current at the end.

Projects/OSTree/UsingOnArch (last edited 2016-01-20 12:53:23 by JavierJardon)