Overview:
This is in continuation to my article on 'Read only root filesystem using AUFS'. Unionfs is a Unification File System in Linux can be seen as alternative to AUFS, philosophically trying to solve similar kind of problems.
The changes were easy to incorporate into my existing build set up compared to AUFS. But the forum seems to be not as active .I never got any response to my post.
Contents of init file .
#init file
#!/bin/busybox sh
# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys
busybox --install -s
mknod /dev/null c 1 3
mknod /dev/tty c 5 0
# Select partitions here. This hardcodes the partitions inside the initramfs. It is also possible to parse
# kernel's command line .
echo "This script mounts rootfs RO with an unionfs RW layer."
mdev -s
#create mount folders in initramfs
mkdir -p /mnt/rw /mnt/ro
# Mount the partitions
# 1) mount the ro partition
ubiattach /dev/ubi_ctrl -m 4 -O 2048
mount -t ubifs -o ro,noatime ubi0:rootfs /mnt/ro
# 2) mount the rw partition, it could be any writable filesystem in the current case it is tmpfs
mount -t tmpfs -o size=30M tmpfs /mnt/rw
# 3) mount the writable overlay to the static image
mount -t unionfs -o dirs=/mnt/rw=rw:/mnt/ro=ro none /mnt/union
# Clean up.
mkdir -p /mnt/union/rw /mnt/union/ro
mount --move /mnt/rw /mnt/union/rw
if [ $? -ne 0 ]; then
echo root-unionfs error: Failed to move /mnt/rw /mnt/union/rw
exit 0
fi
mount --move /mnt/ro /mnt/union/ro
if [ $? -ne 0 ]; then
echo root-unionfs error: Failed to move /mnt/ro /mnt/union/ro
exit 0
fi
umount /proc
umount /sys
mount -t devtmpfs none /mnt/union/dev
if [ $? -ne 0 ]; then
echo root-unionfs error: Failed to mount devtmpfs /mnt/union/dev
exit 0
fi
# Boot the real thing
exec switch_root /mnt/union /sbin/init
echo "Failed to switch_root, dropping to a shell"
exec /bin/sh
patch kernel 2.6.37 with unionfs patch
Get and patch from the below link.
http://download.filesystems.org/unionfs/unionfs-2.x-latest/unionfs-2.6_for_2.6.37.6.diff.gz
#Extract the patch and navigate to the kernl directory.
Gunzip unionfs-2.6_for_2.6.37.6.diff.gz
cd /'PATH of TI linux'/kernel ;
#Now Patch the TI kernel
patch -p1 /'PATH of unionfs patch file'/unionfs-2.6_for_2.6.37.6.diff
Kernel menuconfig captured in .config with respect to unionfs
CONFIG_INITRAMFS_SOURCE="initramfs.cpio"
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_INITRAMFS_ROOT_GID=0
CONFIG_INITRAMFS_COMPRESSION_NONE=y
CONFIG_UNION_FS=y
CONFIG_UNION_FS_XATTR=y
CONFIG_UNION_FS_DEBUG=y
Create intramfs.cpio archive as mentioned in folder and create an archive file and copy into the kernel source.
Recompile the kernel with initramfs and flash it on the kernel partition of the board, now reboot the system with unionfs file system.
To make changes in read-only directory
mount -o remount,rw /ro
mount -t unionfs -o remount,rw unionfs /