Booting from an SD Card

The second part of this week’s 2-Bullet Tuesday! See the first part here.
You can subscribe to the newsletter on the 2-Bullet Tuesday page!

Omega Tip of the Week: Booting from an SD Card

Extra storage space on the filesystem allows you to make more complex projects with lots of moving parts and storage space for media. So this week we’ll cover how to boot your Omega2+ filesystem from an SD Card.

We will be using the pivot-overlay procedure to move the writeable portion of the Omega’s filesystem to an SD card.

A few warnings before we proceed:

  • Performing a firmware update will undo this process
  • Booting your Omega without the SD card connected will force it to boot from the on-board flash storage, meaning the files, installed packages, and configuration from your SD card will not be available
    • Don’t worry though, just reboot your Omega with the SD card plugged in to get your data back!

First we will be mounting the SD card to the Omega’s filesystem, then we’ll copy over the writeable portion of the filesystem over to the SD card, and finally configure the system so that it uses the filesystem from the SD card when the Omega boots up!

The SD card will need to be formatted to an ext4 filesystem for everything to work properly, you can use our ext4 formatting guide.

Once you connect your SD card, the device will be mapped to the filesystem as /dev/mmcblk0 (or something very similar) and the filesystem will automatically be mounted at /tmp/mounts/SD-P (again, or something very similar).
Let’s unmount it: umount /tmp/mounts/SD-P and then duplicate the /overlay directory, the writeable portion of the Omega’s filesystem over to the SD card:

mount /dev/mmcblk0 /mnt
tar -C /overlay -cvf - . | tar -C /mnt -xf -
umount /mnt

Almost done, we just need to configure the Omega so that it uses the /overlay directory from the SD card whenever it boots up. We’ll install block-mount and use it to generate the filesystem table (fstab) configuration entry for the SD card:

opkg update
opkg install block-mount
block detect > /etc/config/fstab

Let’s edit the configuration file: vi /etc/config/fstab
Find the line option target ‘/mnt/mmcblk0’ and change it to option target ‘/overlay’.
Then find the line option enabled ‘0’ and change it to option enabled ‘1’
Save and close the file by hitting the escape key and typing :wq and you’re done!

Reboot your Omega and check out all the room for activities:

root@Omega-665D:/# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 5.5M      5.5M         0 100% /rom
tmpfs                    61.4M    100.0K     61.3M   0% /tmp
/dev/mmcblk0              7.0G     33.4M      6.6G   0% /overlay
overlayfs:/overlay        7.0G     33.4M      6.6G   0% /
tmpfs                   512.0K         0    512.0K   0% /dev

Check out the full article on booting from external storage in our documentation and, if you’re curious, see the OpenWrt wiki for more info on fstab and block-mount.

Let us know what kind of stuff you would like to see featured on 2-Bullet Tuesday! Send a tweet to @OnionIoT with your suggestions!

Thanks for reading! Have a great week!

Team Onion

Share

Lazar Demin

One Customer comments “Booting from an SD Card

  • Jamie

    27 Nov 2018 10:44 pm

    Does this need to be refreshed? I had this working and updated the firmware so it broke. my SD card is there but does not get mounted after doing these steps. There is an fstab is /etc AND /etc/config. Was that always the case? Not the end of the world but I’d like to get this back together if possible. Cheers

Leave your comment