Replace defect SD-card with USB stick

If you found a clean solution for the workarounds below, patches are always welcome:

Chances are that you will not have to repeat those steps after each upgrade

Bypass hard-coded checks for SD-card

The script responsible for partitioning, formatting and mounting the SD-card contains '/dev/mmcblk0' in many places

We take a shortcut, and disable the automatic partition and format step, we will do this manually.

--- /usr/sbin/
+++ /usr/sbin/
@@ -320,7 +320,8 @@
 # and reboots. skip if card already mounted
 if ! "$SDO_ROOT_DIR"/bin/mountpoint -q /media/card; then
-    mount_sd
+    udevadm settle
+    "$SDO_ROOT_DIR"/bin/mount "$SDO_ROOT_DIR"/media/card
+    # mount_sd, function will fail since mmcblk0 is hardcoded in many places

 if "$SDO_ROOT_DIR"/bin/mountpoint -q /media/card; then

Then prepare the fstab to mount the USB in the same place as the SD-card

--- /etc/fstab.orig
+++ /etc/fstab
@@ -10,6 +10,7 @@
 #/dev/mmcblk0p1       /media/card          auto       defaults,sync,noauto  0  0

 # legacy kernel used aufs, 4.1.x kernels use overlayfs
-/dev/mmcblk0p1       /media/card                   auto  defaults,async,noatime,noauto  0  0
+#/dev/mmcblk0p1       /media/card                   auto  defaults,async,noatime,noauto  0  0
+/dev/sda1            /media/card                   auto  defaults,async,noatime,noauto  0  0
 aufs                 /var/log                      aufs  nodev,noatime,br:/media/card/sys/log=rw:/var/log=ro    0    0
 aufs                 /usr/share/dss/data/metering  aufs  nodev,noatime,br:/media/card/sys/metering=rw:/usr/share/dss/data/metering=ro    0    0

If you already prepared a USB stick, you're done. (this is what needs to be checked after a system upgrade)
Reboot, the mount table should look like this:

# mount
/dev/sda1 on /media/card type ext4 (rw,noatime)
overlay on /var/log type overlay (rw,nodev,noatime,lowerdir=/var/log,upperdir=/media/card/sys/log,workdir=/media/card/overlay_workdir/overlay0)
overlay on /usr/share/dss/data/metering type overlay (rw,nodev,noatime,lowerdir=/usr/share/dss/data/metering,upperdir=/media/card/sys/metering,workdir=/media/card/overlay_workdir/overlay1)
# df -k
/dev/sda1               988212      1308    936704   0% /media/card
overlay                 988212      1308    936704   0% /var/log
overlay                 988212      1308    936704   0% /usr/share/dss/data/metering

Prepare USB stick

We must prepare a USB stick with ext2 file format, this can be done on the dSS itself.

Plug USB stick into the dss-sdc and check it has been detected

# tail -f /var/log/messages
usb 1-1: new full-speed USB device number 2 using at91_ohci
usb 1-1: New USB device found, idVendor=058f, idProduct=6387
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: Mass Storage
usb 1-1: Manufacturer: USB
usb 1-1: SerialNumber: 1F5F0154
SCSI subsystem initialized
usb-storage 1-1:1.0: USB Mass Storage device detected
scsi host0: usb-storage 1-1:1.0
usbcore: registered new interface driver usb-storage
scsi 0:0:0:0: Direct-Access     USB      USB 2.0 Flash    8.07 PQ: 0 ANSI: 2
sd 0:0:0:0: [sda] 2019328 512-byte logical blocks: (1.03 GB/986 MiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00
sd 0:0:0:0: [sda] No Caching mode page found
sd 0:0:0:0: [sda] Assuming drive cache: write through
 sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk

We must reformat to ext or other filesystem that the overlay filesystem supports (can't be fat)

# mkfs.ext2 /dev/sda1
# tune2fs -O ^has_journal /dev/sda1


can't open '/dev/sdb': No such device or address

You might be hit by a bug, remove the /etc/dev.tar and reboot. The presence of this file prevents udev to make a full scan of all devices, resulting in the usb driver not being loaded.

overlay filesystems are not mounted after reboot

run the start script manually check for error messages

# /etc/init.d/sdcard-overlay start
SD-CARD: card not found, aborting... 

This particular error can be fixed by Replace_defect_SD-card_with_USB


remove hard-coded /dev/mmcblk0 from

rework partion/format functions

mountpoint /media/card check is unreliable, overlay /media/card/sys/log must be mounted, otherwise logging still goes to internal flash

    if mountpoint -q /media/card; then
        # card is available re-enable logging                            
        rm $STATUS 2> /dev/null   

/etc/fstab is ignored by tho script:

this change, shall ignore mounting /usr/share/dss/data/metering but is ignored since it is still present in /etc/sdcard-overlay.conf

# rule out rrdcached as source of many mmc writes
#aufs                 /usr/share/dss/data/metering  aufs  nodev,noatime,br:/media/card/sys/metering=rw:/usr/share/dss/data/metering=ro    0    0