The following guide was written for beginners and experts alike and will assist in setting up Debian Linux to boot as Read-Only for robustness against power failures (as mentioned in the "Preventing Filesystem Corruption in Embedded Linux" whitepaper). The guide will include the following:
This document is time sensitive. That is, it's not to be used verbatim too far past the date written. Updates are applied to images and files/locations sometimes change. The principles generally stay the same, so keep this in the back of your mind while working through this guide.
For convenience sake*, the unionfs.ko module, kernel image, linuxrc file, and entire 512MB SD image have been made available on the FTP site in the respective locations:
* You will still need to refer to steps 6 through 11 in the Compiling and Installing unionfs.ko and Modifying linuxrc section.
BACKUP YOUR FILES AND IMAGES!
The following is a step-by-step guide to compiling a custom TS-Kernel specifically for the TS-7350. These steps have been verified and will work if they are followed in the exact, step-by-step order. This was written with beginners in mind, but may still be a bit too advanced for some. Remember to backup file and images so you may revert back to them if something goes wrong.
- Must be logged in as root on a Linux PC separate from the SBC
- These packages need to be installed for kernel compiling:
yum install ncurses-devel ncursesDebian/Ubuntu:
sudo apt-get install libncurses5-dev libncursesw5-dev
- TS-7350 SBC
- USB SD Card Reader
- Development PC with Linux installed
- The Cross Toolchain (crosstool-linux-gnueabi-2005q3-2.tar.gz)
- The kernel Source(linux-2.6.21-ts-src-feb022010.tar.gz)
- ts7350_defconfig file for Kernel Options (Included in the kernel Source)
- The unionfs patch (unionfs-2.5.3_for_18.104.22.168.diff)
01.) Download the cross compile toolchain from Technologic Systems: * wget ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7350-linux/\ cross-toolchains/crosstool-linux-gnueabi-2005q3-2.tar.gz 02.) Extract to current working directory and remove old tar.gz file: * tar xvf crosstool-linux-gnueabi-2005q3-2.tar.gz * rm crosstool-linux-gnueabi-2005q3-2.tar.gz 03.) Obtain the TS-7350 kernel source tree * wget ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7350-linux/\ sources/linux-2.6.21-ts-src-feb022010.tar.gz 04.) Extract the TS-7350 kernel source tree (this is silent) and remove old tar.gz file: * tar xzf linux-2.6.21-ts-src-feb022010.tar.gz * rm linux-2.6.21-ts-src-feb022010.tar.gz 05.) Move into the newly extracted directory * cd linux-2.6.21-ts-src-feb022010/ 06.) Edit the Makefile at the kernel root dir to point to the appropriate cross-compiler path. In our case, with the toolchain decompressed into the same directory as the kernel, we'll change line 186 of the Makefile to read: * CROSS_COMPILE ?= ../arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi- 07.) Edit the scripts/mod/sumversion.c to include a definition to the PATH_MAX variable and set it to 1024 (insert below other #define lines). * #define PATH_MAX 1024 08.) Type "make ts7350_defconfig" to make the kernel with the options that Technologic Systems uses for the TS-7350 (More options can be found by listing the contents of arch/arm/configs)
The unionfs patch was originally obtained from the main unionfs website here: http://www.filesystems.org/project-unionfs.html. Please keep in mind that modifying the default kernel supplied by Technologic Systems is not supported. If you have difficulties, custom engineering is available and you can commission us to find a solution for your product.
01.) While still in the linux-2.6.21-ts-src-feb022010 folder, download the required unionfs kernel patch: * wget ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7350-linux/sources/\ unionfs-2.5.3_for_22.214.171.124.diff 02.) Apply the patch: * patch -p1 < unionfs-2.5.3_for_126.96.36.199.diff 03.) Type "make menuconfig" and include the UnionFS support. Use the arrow and Enter keys to navigate to Filesystems -> Layered filesystems -> Union file system (EXPERIMENTAL). Press "m" to modularize it (this will give you the unionfs.ko file). Keep hitting "exit" until you're prompted to save the changes, choose "yes". 04.) Type "make" to compile the kernel and modules. 05.) The new kernel image will be at "arch/arm/boot" in both uncompressed (Image) and an compressed (zImage). It is REQUIRED that it be < 3.1MB (3145728 bytes in size). Since we did not add anything to the kernel, the uncompressed Image size is acceptable. This Image is required for the unionfs module to insert correctly. 06.) Copy the binary Image to the second partition (in most cases, this is mounted as /dev/sdb2, verify this with fdisk -l before running the commands). This will erase any data which is on /dev/sdb2 card now, so a backup is advised. * TO BACKUP: dd if=/dev/sdb2 of=../ImageBak * TO COPY zImage: dd if=arch/arm/boot/Image of=/dev/sdb2 07.) Mount the fourth partition of the SD card to /mnt/p4 and copy the unionfs.ko module to the proper location: * mkdir /mnt/p4 * mount /dev/sdb4 /mnt/p4 * mkdir -p /mnt/p4/lib/modules/2.6.21-ts/kernel/fs/unionfs/ * cp fs/unionfs/unionfs.ko /mnt/p4/lib/modules/2.6.21-ts/kernel/fs/unionfs/ 08.) Mount the third partition of the SD card to /mnt/p3 and edit the linuxrc files to boot to Debian as read-only: * mkdir /mnt/p3 * mount /dev/sdb3 /mnt/p3 * cd /mnt/p3 * cp linuxrc-sdroot linuxrc-sdroot-readonly * vi linuxrc-sdroot-readonly -- Use the following diff -u report as reference for what changes need to be made -- Note that the power.wav and splash.gz files are removed to make room for the new directories /mnt/root.ro and /mnt/root.rw ================================================================================ --- linuxrc-sdroot 1969-12-31 17:00:39.000000000 -0700 +++ linuxrc-sdroot-readonly 2010-04-01 12:00:31.000000000 -0700 @@ -31,7 +31,21 @@ if [ -e /dev/tssdcarda4 -a -e /mnt/root/notrootfs ]; then mount -o ro /dev/tssdcarda4 /mnt/root fsck /dev/tssdcarda4 - mount -o remount,rw /mnt/root + rm power.wav splash.gz + + insmod /mnt/root/lib/modules/2.6.21-ts/kernel/fs/unionfs/unionfs.ko + mkdir /mnt/root.ro /mnt/root.rw + mount --move /mnt/root /mnt/root.ro + mount -t tmpfs root.rw /mnt/root.rw + mount -t unionfs -o dirs=/mnt/root.rw=rw:/mnt/root.ro=ro unionfs /mnt/root/ + + chmod 755 /mnt/root + + mkdir /mnt/root/ro /mnt/root/rw + mount --move /mnt/root.ro /mnt/root/ro + mount --move /mnt/root.rw /mnt/root/rw + + rm -f /mnt/root/etc/rcS.d/S[0-9][0-9]checkroot.sh + fi ) > /dev/null 2>&1 @@ -68,7 +82,7 @@ wait killall busybox telnetd > /dev/null 2>&1 -echo ">> Booting Linux..." > $CONSOLE +echo ">> Booting Read-Only Linux..." > $CONSOLE cd /mnt/root pivot_root . ./initrd ./bin/mount -n --move ./initrd/sys ./sys ================================================================================ 09.) Now, simply create a symlink to linuxrc-sdroot-readonly to boot directly to Debian as Read-Only. * ln -sf linuxrc-sdroot-readonly linuxrc 10.) Sync the changes to the SD card and unmount it * sync * cd ~ * umount /dev/sdc[3,4] 11.) Take the card out of the SD card reader and insert it into the TS-73x0. Apply power and observe that it is indeed booting to Debian as Read-Only by trying to create a file and then recycling power. The file will no longer be there. You should also see the following when using the 'mount' command: /dev/tssdcarda4 on /ro type jfs (ro) root.rw on /rw type tmpfs (rw) With this setup, it is safe to remove power at any time without running 'shutdown -h now' for a graceful shutdown. Read more about filesystem corruption in the "Preventing Filesystem Corruption in Embedded Linux" whitepaper located here: http://www.embeddedarm.com/about/resource.php?item=459