Skip to main content
1 of 4
starfry
  • 356
  • 1
  • 3
  • 12

This explains how you can boot the Raspberry Pi into a system with the root partition on an LVM volume. LVM is Linux Volume Management.

Configuration

In order for early-boot to be able to access an LVM volume the kernel must be able to load the LVM module before the root partition is mounted. This requires that an initial ramdisk (initrd) is configured and added to the boot configuration. Fortunately, this is quite straightforward.

Kernel Support

To be able to use an initial ramdisk, the kernel must be built with initrd support included. The stock Raspberry Pi ArchLinux kernel is. However, to be sure, verify this:

# zgrep INITRD /proc/config.gz
CONFIG_BLK_DEV_INITRD=y

It is not necessary to build a custom kernel if the CONFIG_BLK_DEV_INITRD option is enabled. Building a custom kernel is beyond the scope of this answer.

Build the initrd

Firstly, install the mkinitcpio package:

# pacman -S mkinitcpio

Next, edit /etc/mkinitcpio.conf to add the lvm2 hook; locate the HOOKS= line and amend accordingly:

HOOKS="base udev autodetect modconf block lvm2 filesystems keyboard fsck"

Then generate the initrd:

# mkinitcpio -g /boot/initrd

Amend the boot configuration

The Raspberry Pi's boot is configured in two files, /boot/config.txt and /boot/cmdline.txt. Both need to be modified to install the initrd.

First, add the following line to the end of the `/boot/config.txt' file:

initramfs initrd 0x00f00000

Note that, unlike the other items in this file, the initramfs entry does not contain an equals = sign.

Next, amend the /boot/cmdline.txt file to add

...root=/dev/mmcblk0p1 initrd=0x00f00000 rootfstype=ext4...

Also, append an 'rw' otherwise the rootfs gets mounted read-only.

Reboot

With the above configuration in place, re-boot. If all is well, the system should come back up as before, but will have used the initial ramdisk during boot. The next step is to move the current root partition onto an LVM volume.

Move Root partitition to LVM

For the purpose of this example, we assume that you have a spare disk connected to the RPi's USB that is recognised as /dev/sdaand has a partition on it for LVM, say /dev/sda1. We will copy the existing root partition into a new volume created inside LVM.

Set up LVM

Set up LVM: create a new volume group and, within it, a logical volume for the root partition:

# pvcreate /dev/sda1
# vgcreate storage /dev/sda5
# lvcreate -L 5G storage -n root

This creates a volume group called storage and adds the partition /dev/sda1 to it. It creates a 5Gb logical voulume called root which can then be formatted and used like a regular partiton:

# mkfs.ext4 /dev/storage/root
# mount /dev/storage/root /mnt

Copy the current root onto it:

# rsync --progress -axv / /mnt/

Configure the Boot process

Configuring the boot process is a simple matter of changing the location of the root partition in /boot/cmdline.txt. Change root=/dev/mmcblk0p1 so that it points to the new volume: root=/dev/storage/root.

Re-boot once more and, if all things go well, the system should reboot with its root partition on the LVM volume.

starfry
  • 356
  • 1
  • 3
  • 12