Set Rootflags at Debian Embedded Devices

2016/10/10

When running debian on embedded devices like the ts119 flash-linux is used to flash the kernel and an initrd image to the devices flash memory. At some devices the kernel command line is statically defined by the manufacturer.

root@ts:~#cat /proc/cmdline
console=ttyS0,115200 root=/dev/ram initrd=0xa00000,0x900000 ramdisk=32768

Therefore three isn't the possibility to set root device and flags with the kernel command line. Another way is to define them within the initial ram disk using the initramfs-tools. This is what flash-kernel does for the root partition with /usr/share/initramfs-tools/hooks/flash_kernel_set_root. It sets the ROOT variable at conf/param.conf which is sourced before the final root partition is mounted.

tl;dr

To set or override the rootflags the variable ROOTFLAGS is set in conf/param.conf at the initrd. Therefore a hook is added at /etc/initramfs-tools/hooks/:

#!/bin/sh

ROOT_MOUNT_OPTIONS="-o defaults,noatime"
PREREQ=""

prereqs() {
	echo "$PREREQ"
}

case $1 in
prereqs)
	prereqs
	exit 0
	;;
esac

. /usr/share/initramfs-tools/hook-functions
echo "ROOTFLAGS=\"$ROOT_MOUNT_OPTIONS\"" >> $DESTDIR/conf/param.conf

Be aware that your device won't boot with incorrect configurations. You may want to check the generated initrd.img and have a look the manpages of flash-kernel and initramfs-tools.