How to use an SD card as the root file system

How to use an SD card as the root file system (Source URL: http://www.plugcomputer.org/plugwiki/index.php/SD_Card_As_Root_File_System)

This is the procedure I followed in order to use an SD card, rather than the internal NAND flash, as the root file system. My reasons to do this are in order to have a bigger root FS (I’m using 8GB), in order to avoid hammering the internal flash & wearing it out, & to make it effortless to make duplicate plugs, by simply by duplicating the SD card. It moreover seems to run quite a bit faster, though I haven’t measured anything.

I did this with a very early sheevaPlug, running u-boot 1.1.4, & the built-in debian/ubuntu.
How to test the read & write speed of your SD card

Type in the following command to write a file to the SD card that is 1GB big.

if you want a smaller file like 50MB to be written then just alter it to

count determines the size of the file you are going to write.

After the command is finished it should print out the write speed like this (mine is very slow by the way)

To test the read speed run this command on the file you just created

It should donate you a print out like this

Now you will know if your SD card is swift enough to run a file system from.
Create a bootable file system on the SD card

The first step is to make a bootable file system on the SD card. Insert the card into the slot of a running plug. Enter the following commands:

You’ve now received an empty file system mounted on /mnt/sdcard. The df that you just typed should show you something like the following. Note the last line, which is the new SD file system. This one is an 8GB card, & because it’s an ext3 journaling file system, a bunch of it is already set aside for directories, journals & such.

Now copy your existing nand file system onto the sd card. The second cp of /dev is required because the first cp doesn’t populate the new /dev directory. The first cp takes 10–15 minutes, so relax for a bit.

If you are like me, & you want to see that there is something going on, add a “v” to the commands below, if not, exclude it.

The SD card should now mirror your internal nand flash, which you can confirm with df -h, etc. On my system, df -h now shows:

Congrats, your SD card now has a bootable system. The next step is to boot it.
Booting from the SD Card

You need to interact with u-boot now. You must do this from a program talking to the usb-serial port, not from an ssh shell (duh). I use minicom, from an ubuntu system.

When u-boot appears, stop it by typing ENTER a few times, to stop it from booting automatically.

This is the line that you’ll need to change. Copy everything after the first “=”, & paste it into a text editor. Edit the line to alter “root=/dev/mtdblock1” to “root=/dev/mmcblk0p1”. Optionally, you can moreover obtain rid of the mtdparts stuff. So, the new line (at least on my plug) is

Add, at the beginning of the line “setenv bootargs”. The line is now:

Copy it. Paste that line into u-boot as a command, then proceed as follows:

With any luck, the system will now boot. If you watch the boot text scrolling by, you should see something like this. If you formatted with ext2 instead of ext3, it will be different of course.

When the system comes up, log in & type “df”. You should see something like this, with a much bigger root fs than you had before.

Note that on this display, the rootfs is the new SD file system, & is much bigger. The last line is the internal nand flash. You won’t see that unless you mount it, as follows. The -r on the mount command mounts the nand read-only. Leave it off, if you like.

Write u-boot environment to flash if desired.

The changes you made to the boot environment (setenv) don’t persist across a reboot. You’ll need to do that every time, unless you explicitly write your changes to internal flash. You do so by inserting “saveenv” after the setenv.

I DON’T suggest you do this the first time. Try it first and, if it works, reboot with the saveenv. Once you’ve done this, it will automatically boot from the SD card after a power-up, reboot, or reset.
Changes for Alpha6 Beta

This tutorial doesn’t quite work out of the box for the Alpha6 system. Namely, the printenv bootargs will not work, & will say variable not found. Instead you can see:

it seems to work for me if you alter this bootargs_root variable to be the following:

This seems to work- for more information see the thread at: http://plugcomputer.org/plugforum/index.php?topic=591.0

Ensure that you power cycle (at the wall) to ensure that the configuration works. Should you end up with a message like this:

VFS: Cannot open root device “b301” or unknown-block(179,1)
Please append a correct “root=” boot option; here are the available partitions:

Then setting the following may work around the problem:

Mystery

If you just type “printenv” into u-boot, you’ll see lots of environment variables, including:

or

Have a look a the uboot manual .. & at the rest of the environment variables. You will find one with

wich will be replaced by the content of the x_bootargs_root variable, like in any shell ….
Where Credit is Due

As I tried to obtain this working, I returned frequently to plugforum (http://plugcomputer.org/plugforum/index.php?topic=149.0) where I received a lot of assist from karurosu, sethlans, wb6ymh & cbxbiker61. They’re smart.