Boot to a root filesystem on a USB Mass Storage Device

Executive summary

For those who already have experience with the u-boot shell on the dSS, this might be all the information that you need:

u-boot:

setenv bootargs console=ttyS0,115200 root=/dev/sda1 ubi.mtd=$rootfs_part,4096 rw $mtdparts rootdelay=20
setenv boot_system run select_setup;nboot 0x22000000 0 $kernel_addr;bootm 0x22000000

dSS shell:

mount -t ubifs /dev/ubi0_0 /media/mountpoint

For those needing a detailed description of steps, read further...

Prerequisites

This technique requires a serial connection to the dSS's RS-232 physical interface, which is exposed via a small, 14-pin header connector on the dSS.

It also requires a USB Mass storage device with:
  • an fdisk partition table
  • at least 1 ext2- or ext3-formatted partition
  • containing a valid root filesystem for the dSS

Note: other configurations may work, but have not yet been tested or verified.

Preparing the root filesystem on the external storage device

The USB storage device should be partitioned using fdisk. GUID partition tables are not supported.

Note: partitioning and formatting the USB device is beyond the scope of this wiki entry. Check the man pages or search for the relevant documentation of fdsik and mkfs.ext2/mkfs.ext3

Note: rsync is the recommended tool for syncing the root filesystem to the USB storage device. It's not installed on the dSS by default, however, it should be possible to install it with the following command:

opkg install rsync
  1. Boot the dSS with the USB storage device plugged in
  2. Locate the desired target partition (the partitions should already be mounted in the /media directory - /media/sda1, /media/sda2, ...)
  3. Sync the root filesystem of the dSS to the USB partition (sda1 in this example)
rsync -avDH --exclude=/mnt/ --exclude=/proc/ --exclude=/sys/ --exclude=/dev/.udev/ / /media/sda1/
mkdir /media/sda1/proc
mkdir /media/sda1/sys

Note: the user may want to consider excluding the /var/log directory as well; it may contain a lot of data and it is being actively written to during the sync operation, which may have some unexpected consequences.

Booting to the USB device

  1. Open the dSS and connect to the serial interface
  2. Configure the terminal program with the following settings: 115200bps, 8 data bits, no parity, 1 stop bit, no flow control
  3. Boot the dSS and press a key to prevent uboot from loading the kernel with the default settings
  4. Enter the following commands at the uboot prompt:
setenv bootargs console=ttyS0,115200 root=/dev/sda1 ubi.mtd=$rootfs_part,4096 rw $mtdparts rootdelay=20
setenv boot_system run select_setup;nboot 0x22000000 0 $kernel_addr;bootm 0x22000000

The system should boot upon pressing enter after the second line.

Note: this assumes that the root filesystem is located on the first partition of the flash drive, sda1. If it's located on the second partition, substitute sda2. Likewise for later partitions. It's not yet been verified whether extended partitions can be used for a root filesystem.

Mounting the internal flash with read/write access

The user should be able to find a device file called /dev/ubi0_0

root@dSS:~# ls -l /dev/ubi*
crw-------    1 root     root      252,   0 Jul 10  2012 /dev/ubi0
crw-------    1 root     root      252,   1 Jul 10  2012 /dev/ubi0_0
crw-------    1 root     root       10,  63 Jul 10  2012 /dev/ubi_ctrl

In order to mount this, the filesystem type (ubifs) must be specified:

mkdir /media/mountpoint
mount -t ubifs /dev/ubi0_0 /media/mountpoint

Log of a typical session (using partition 3 of the USB mass storage device as the root filesystem)

C�NAND:  ONFI flash detected
ONFI param page 0 valid
1024 MiB
SF: Detected M25P40 with page size 64 KiB, total 512 KiB
In:    serial
Out:   serial
Err:   serial
Net:   (small V005/V006) macb0
Hit any key to stop autoboot:  0 
digitalSTROM> setenv bootargs console=ttyS0,115200 root=/dev/sda3 ubi.mtd=$rootfs_part,4096 rw $mtdparts rootdelay=20
digitalSTROM> setenv boot_system run select_setup;nboot 0x22000000 0 $kernel_addr;bootm 0x22000000

Loading from nand0, offset 0x200000
   Image Name:   Linux-3.0.17
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1996460 Bytes = 1.9 MiB
   Load Address: 20008000
   Entry Point:  20008000
## Booting kernel from Legacy Image at 22000000 ...
   Image Name:   Linux-3.0.17
   Image Type:   ARM Linux Kernel Image (uncompressed)
   Data Size:    1996460 Bytes = 1.9 MiB
   Load Address: 20008000
   Entry Point:  20008000
   Verifying Checksum ... OK
   Loading Kernel Image ... OK
OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
[    0.000000] Linux version 3.0.17 (oebuild@oe-build) (gcc version 4.5.4 20110917 (prerelease) (GCC) ) #1 PREEMPT Fri Mar 16 12:35:43 CET 2012
[    0.000000] CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177
[    0.000000] CPU: VIVT data cache, VIVT instruction cache
[    0.000000] Machine: Atmel AT91SAM9G20-EK
[    0.000000] Memory policy: ECC disabled, Data cache writeback
[    0.000000] Clocks: CPU 396 MHz, master 132 MHz, main 18.432 MHz
[    0.000000] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256
[    0.000000] Kernel command line: console=ttyS0,115200 root=/dev/sda3 ubi.mtd=3,4096 rw mtdparts=atmel_nand:2M(kernel-rescue),2M(kernel-prod),32M(rootfs-rescue),980
[    0.000000] PID hash table entries: 256 (order: -2, 1024 bytes)

Mounting and verifying the internal flash:

root@dSS:~# mkdir /media/internalflash
root@dSS:~# mount -t ubifs /dev/ubi0_0 /media/internalflash/
[  146.350000] UBIFS: mounted UBI device 0, volume 0, name "dss11-1gb-rootfs" 
[  146.360000] UBIFS: file system size:   994516992 bytes (971208 KiB, 948 MiB, 1927 LEBs)
[  146.370000] UBIFS: journal size:       10452992 bytes (10208 KiB, 9 MiB, 21 LEBs)
[  146.380000] UBIFS: media format:       w4/r0 (latest is w4/r0)
[  146.380000] UBIFS: default compressor: lzo
[  146.390000] UBIFS: reserved for root:  0 bytes (0 KiB)

root@dSS:~# df -h | grep internal
/dev/ubi0_0             889.3M     79.8M    809.5M   9% /media/internalflash

Special use case: syncing/replacing a root filesystem on the dSS

This subsection covers the special case that one may be interested in syncing a root filesystem from the USB storage device to the dSS. This is typically done to duplicate the exact state of one dSS to another.

Sync the root filesystem from the USB device to the dSS internal flash. In this case, we will assume that we're syncing partition 1 of the USB device (sda1) to the dSS flash mounted at /media/internalflash

WARNING: mistakes could render the dSS un-bootable. Proceed at your own risk.

rsync -avDH --delete /mnt/sda1/ /media/internalflash/

Remove the udev persistent network device rule. Otherwise the ethernet interface will not function properly on restart.

rm /media/internalflash/etc/udev/rules.d/70-persistent-net.rules

Reboot to the newly synced filesystem on the dSS.