Welcome! Log In Create A New Profile

Advanced

Howto: Install readonly emdebian on NAND

Posted by Jeff 
Howto: Install readonly emdebian on NAND
August 12, 2010 04:26PM
I've done some preliminary work getting debian installed to the NAND:

The installation is, by default, readonly. The installer includes a few workarounds to make everything work from the readonly filesystem. It creates a /sbin/init-ro script to mount and initialize a few tmpfs mount points. My goal is to keep the root system readonly, with all read-write parts located on tmpfs, NFS, or external drive.

You can add extra packages by modifying the variables at the top of the installer, or by remounting the system read-write and running apt. By default, this install will only install packages from embdebian. If you need to install packages from the full Debian, you'll need to add a repository to /etc/apt/sources.list. Be aware, however, that the package list itself is over 30M.

If you would prefer to make it read-write, just 'mount -o remount,rw'. You can edit /etc/fstab and remove the 'ro' from the root mount make the system permanently read-write.

The default install is 112M uncompressed on ext2 and 72M compressed on UBIFS.

I welcome any comments and suggestions on improving this.

-- Jeff

  • Remove USB drive, boot into pogoplug
  • Attach your USB drive, partition it with fdisk, and then run the following commands:

cd /tmp
wget http://jeff.doozan.com/debian/dockstar.emdebian-squeeze-readonly.sh
chmod +x dockstar.emdebian-squeeze-readonly.sh
export PATH=$PATH:/usr/sbin:/sbin
./dockstar.emdebian-squeeze-readonly.sh

  • Reboot into Debian
  • Create UBIFS on mtd3 using the following commands:

flash_eraseall /dev/mtd3
ubiformat /dev/mtd3 -y
ubiattach /dev/ubi_ctrl -m 3
ubimkvol /dev/ubi0 -m -N rootfs

  • Copy system to ubifs

mkdir /tmp/ubifs
mount -t ubifs ubi0:rootfs /tmp/ubifs

tar \
  --exclude=/lost+found  \
  --exclude=/tmp  \
  --exclude=/sys  \
  --exclude=/proc \
  -cf - / | ( cd /tmp/ubifs ; tar -xpvf - )
mkdir /tmp/ubifs/tmp
mkdir /tmp/ubifs/sys
mkdir /tmp/ubifs/proc

# change root fs type from ext2 to ubifs
sed -i 's/^\(\/dev\/root.*\)ext2/\1ubifs/' /tmp/ubifs/etc/fstab > /dev/null 2>&1
umount /tmp/ubifs

  • Configure UBIFS booting

fw_setenv set_bootargs_ubi 'setenv bootargs console=$console ubi.mtd=3 root=ubi0:rootfs rootfstype=ubifs $mtdparts init=/sbin/init-ro'
fw_setenv bootcmd_ubi 'run set_bootargs_ubi; ubi part data; ubifsmount rootfs; ubifsload 0x800000 /boot/uImage; ubifsload 0x1100000 /boot/uInitrd; bootm 0x800000 0x1100000'

# Configure new bootloader to run old uBoot
fw_setenv bootcmd 'run bootcmd_ubi; run bootcmd_usb; run bootcmd_pogo; reset'

Remove your USB drive and reboot into Debian on NAND


NOTE: If you change your UBIFS root to read-only (to edit files or install packages) and lose power or crash before you remount it a read-only, uBoot will think the partition has errors and will refuse to boot from it. In that case, it will try booting from USB. If there are no bootable USB devices, it will boot the original Pogoplug installation. From there, you can mount and unmount the UBIFS partition, just to reset the 'dirty' flags and uBoot will be okay again.

-- Jeff



Edited 12 time(s). Last edit at 09/15/2010 09:01PM by Jeff.
drakaz
Re: Install readonly embdebian on NAND
August 16, 2010 02:00PM
Just a big thanks for your job.
Mark
Does it work on POGOE02
August 17, 2010 09:14AM
Just wonder does this work on POGOE02(pink)
Buy.com has it on sle for about $48 free shipping (expires 08/19/10)
http://www.buy.com/prod/pogoplug-multimedia-sharing-device/q/loc/101/213816247.html
Re: Install readonly embdebian on NAND
August 17, 2010 09:20AM
^ You can get the dockstar for $36 from Seagate Store - promo code 'seagatestorage'

http://www.seagate.com/www/en-us/products/network_storage/freeagent_dockstar/
Mark
Re: Install readonly embdebian on NAND
August 17, 2010 09:56AM
varkey Wrote:
-------------------------------------------------------
> ^ You can get the dockstar for $36 from Seagate
> Store - promo code 'seagatestorage'
>
> http://www.seagate.com/www/en-us/products/network_
> storage/freeagent_dockstar/


Thanks for the information...
But the POGOE02 have twice much of Memory and NAND than dockstar

I have dockstar runs the Asterisk with GUI but it almost run out the 128M Memory That is why I mention about POGOE02

Thanks to Jeff for all your work.
Re: Install readonly embdebian on NAND
August 17, 2010 10:21AM
I don't have access to a Pogo, so I can't say for sure that it will work. I would guess that some of the mtd settings would need to be adjusted. If anyone has a spare pogo they'd like to donate to the cause, I'll be happy to take on the challenge.

-- Jeff
Re: Install readonly embdebian on NAND
August 18, 2010 04:59PM
Will this still boot to a bootable usb flash drive after the install? I want to be able to have a lightweight install to work with but I also have a much beefier install on a flash drive right now.
Re: Install readonly embdebian on NAND
August 18, 2010 09:04PM
Yes, you can continue to boot from the USB drive by interrupting uBoot and typing
run bootcmd_usb

Alternatively, you can force it to switch to USB booting by running the following from your linux command line:
fw_setenv bootcmd 'run bootcmd_usb; run bootcmd_ubi; run bootcmd_pogo; reset'

Switch back to NAND booting with the following:
fw_setenv bootcmd 'run bootcmd_ubi; run bootcmd_usb; run bootcmd_pogo; reset'

-- Jeff



Edited 2 time(s). Last edit at 08/24/2010 12:02PM by Jeff.
thorsten
Re: Install readonly embdebian on NAND
August 19, 2010 02:47AM
how does installation differ from the usb ?
because with only some extra packages installed, i'm way over th 256 meg the nand can offer :
root@debian:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 479M 376M 79M 83% /
none 60M 68K 60M 1% /dev
/dev/sda1 479M 376M 79M 83% /
tmpfs 62M 4.0K 62M 1% /lib/init/rw
tmpfs 62M 0 62M 0% /dev/shm
tmpfs 62M 0 62M 0% /tmp

I would like to avoid the "double boot"

thanks
thorsten
diarmuid
Re: Install readonly embdebian on NAND
August 19, 2010 01:29PM
Looks good.

I have a dockstar with openwrt running on it. I tried This script but got the follwoing error

root@OpenWrt:/# cd /tmp
root@OpenWrt:/tmp# wget http://jeff.doozan.com/debian/dockstar.emdebian-squeeze-
readonly.sh
Connecting to jeff.doozan.com (69.163.187.226:80)
dockstar.emdebian-sq 100% |*******************************| 10774 --:--:-- ETA
root@OpenWrt:/tmp# chmod +x dockstar.emdebian-squeeze-readonly.sh
root@OpenWrt:/tmp# export PATH=$PATH:/usr/sbin:/sbin
root@OpenWrt:/tmp# ./dockstar.emdebian-squeeze-readonly.sh



This script will configure your Dockstar to boot Debian Squeeze
from a USB device. Before running this script, you should have
used fdisk to create the following partitions:

/dev/sda1 (Linux ext2, at least 300MB)


This script will DESTROY ALL EXISTING DATA on /dev/sda1
Please double check that the device on /dev/sda1 is the correct device.

If everything looks good, type 'ok' to continue: ok



DISABLE POGOPLUG SERVICES

The pogoplug service includes an auto-update feature which could
be used to cripple or disable your device. It is recommended
that you disable this service.

NOTE: The pogoplug service is proprietary software
created by Cloud Engines. It is not available for use
in other distributions and will not be available in
your new debian installation even if you choose not to disable it.

Would you like to disable the pogoplug services? [Y/n] Y
Applying fixes to the pogoplug environment...
mount: mounting mini_fo:/overlay on / failed: Function not implemented
Disabling the pogoplug service...
mount: mounting mini_fo:/overlay on / failed: Function not implemented
Done fixing pogoplug environment.

mount: mounting mini_fo:/overlay on / failed: Function not implemented
Connecting to jeff.doozan.com (69.163.187.226:80)
mke2fs 100% |*******************************| 799k --:--:-- ETA
mount: mounting mini_fo:/overlay on / failed: Function not implemented
./dockstar.emdebian-squeeze-readonly.sh: line 186: /sbin/mke2fs: not found
mount: mounting /dev/sda1 on /tmp/debian failed: Invalid argument
Could not mount /dev/sda1 on /tmp/debian

Any ideas?
cheers
Diarmuid
mxspy
Re: Install readonly embdebian on NAND
August 23, 2010 03:44PM
Hello,

I am trying install debian to nand. What happens after i have run the script? The script tells me that I have to reboot now. I reboot the dockstar and now I am on the debian system from the usb stick.
The next step flash_eraseall /dev/mtd3 gives me an error that there is no flash_eraseall ?!

My status at this time -> Debian is running from the usb-stick if I am booting with it, without the stick I got the original firmware from nand.

Can someone help me, what I have to do now.

Thanks
Chris
Re: Install readonly embdebian on NAND
August 23, 2010 03:52PM
/usr/sbin/flash_eraseall should have been installed by the 'mtd-utils' package. If it's missing, which is explicitly included in the install script. If it's not there then something went wrong with the installer (but not that wrong, since it still boots Debian). You can try manually installing the package with
apt-get install mtd-utils

-- Jeff
mxspy
Re: Install readonly embdebian on NAND
August 23, 2010 03:58PM
...this was realy fast :-)

Okay, I found flash_eraseall in /usr/sbin -> thats good.

One question:
I boot from usb into debian and do the rest of the installation from there?

(Sorry for the bad english, it is a long time ago)

Chris
Re: Install readonly embdebian on NAND
August 23, 2010 04:00PM
Yes, boot into Debian and follow the rest of the steps from there.

-- Jeff
mxspy
Re: Install readonly embdebian on NAND
August 23, 2010 04:10PM
Okay - i am sorry:

root@debian:~# flash_eraseall /dev/mtd3
flash_eraseall: /dev/mtd3: No such file or directory

root@debian:/# ls /dev | grep mtd
mtd0
mtd0ro
mtd1
mtd1ro
mtd2
mtd2ro
mtdblock0
mtdblock1
mtdblock2
root@debian:/#

and part of dmesg says...

[ 1.014176] Creating 3 MTD partitions on "orion_nand":
[ 1.019354] 0x000000000000-0x000000100000 : "u-boot"
[ 1.024899] 0x000000100000-0x000000500000 : "uImage"
[ 1.030384] 0x000000500000-0x000010000000 : "root"


Do you have an idea?
Re: Install readonly embdebian on NAND
August 23, 2010 04:26PM
From the Debian command line, run

fw_setenv set_bootargs_usb 'setenv bootargs console=$console root=$usb_root rootdelay=$usb_rootdelay rootfstype=$usb_rootfstype init=/sbin/init-ro $mtdparts'

and then reboot. You should now have /dev/mtd3

-- Jeff

Edit: fixed a typo, thanks Jörn



Edited 1 time(s). Last edit at 08/31/2010 06:16PM by Jeff.
mxspy
Re: Install readonly embdebian on NAND
August 23, 2010 05:13PM
Thank you, Jeff.

I got some problem on boot (add some dirs /tmp/xxx) because the filesystem was read-only - so the network does not come up.
I have used the serial-console to make the rest of the installation, after a remount.

Now Debian starts from Nand .. i am happy.

Chris
Re: Install readonly embdebian on NAND
August 24, 2010 07:03AM
How to use the whole nand of the dockstar? I just want to have more than 256 MB and don't need the original partition.
Re: Install readonly embdebian on NAND
August 24, 2010 09:18AM
To clarify, the entire NAND is only 256MB. By default, uBoot use 1MB on mt0 and Pogoplug uses 36MB on mtd1 and mtd2, leaving you with 219MB for an embedded installation. If you really don't want to keep Pogoplug as a backup for recovery purposes, you can free up an additional 36MB, giving you a total of 255MB to for your embedded install. The first 1MB must be reserved for uBoot.

If you follow these instructions, you WILL lose the ability to boot into Pogoplug for recovery purposes. Be careful!

If you want to use the whole NAND, you need to adjust the 'mtdparts' string in uBoot. This is what tells the kernel and uBoot how to 'partition' the NAND.

By default, this string is "mtdparts=orion_nand:1M(u-boot),4M(uImage),32M(rootfs),-(data)". The u-boot partition is mandatory, but the rest is just the pogoplug stuff. Assuming that you've already got Linux booting on a USB drive, you can change the partitions to a 1M uBoot partition and everything else as the data partition with this command:

fw_setenv mtdparts 'mtdparts=orion_nand:1M(u-boot),-(data)'

After you reboot, linux (and uBoot) will only see mtd0 and mtd1. Now follow the instructions in the original post, but for the 'UBIFS' sections, use the commands above instead of the commands in the original post:

Create UBIFS on mtd1 using the following commands:
flash_eraseall /dev/mtd1
ubiformat /dev/mtd1 -y
ubiattach /dev/ubi_ctrl -m 1
ubimkvol /dev/ubi0 -m -N rootfs

Configure UBIFS Booting" from mtd1:
fw_setenv set_bootargs_ubi 'setenv bootargs console=$console ubi.mtd=1 root=ubi0:rootfs rootfstype=ubifs $mtdparts init=/sbin/init-ro'
fw_setenv bootcmd_ubi 'run set_bootargs_ubi; ubi part data; ubifsmount rootfs; ubifsload 0x800000 /boot/uImage; ubifsload 0x1100000 /boot/uInitrd; bootm 0x800000 0x1100000'

# Configure new bootloader to try ubi booting, then USB booting.  The Pogoplug recovery partition has been removed.
fw_setenv bootcmd 'run bootcmd_ubi; run bootcmd_usb; reset'

I would recommend that you be very careful with this.

-- Jeff



Edited 1 time(s). Last edit at 08/24/2010 12:08PM by Jeff.
ecc
Re: Install readonly embdebian on NAND
August 27, 2010 11:37AM
I currently have Debian installed in NAND on my DockStar (factory uboot in mtd0, kernel in mtd1, ubifs root in the remaining 251MB). I initially installed OpenWrt, removing the PogoPlug system completely, and later switched to Debian.

Do I understand correctly that your new uboot supports reading/booting from a ubifs NAND flash paritition? (I'd like to be able to use the flash-kernel package to install kernels in the rootfs, rather than in a separate flash partition.)
Re: Install readonly embdebian on NAND
August 27, 2010 12:18PM
Yes, the new uBoot support reading from UBIFS partitions.
Hendrik
Re: Install readonly embdebian on NAND
August 27, 2010 04:34PM
Hello,

Thanks for this guide!
I have two questions:
How much space is Left on the internal Memory, After the install?
What do you recommend to do in Order to extend the Space? Somerset kind of an overlay file System Gould Be gerat, that makes / rw and Stores all Files to an external Memory (hdd USB Flash). I think unionfs and aufs are capable of this.

Regards,
Hendrik
ecc
Re: Install readonly embdebian on NAND
August 28, 2010 02:23PM
Hendrik Wrote:
-------------------------------------------------------
> I have two questions:
> How much space is Left on the internal Memory, After the install?

I'm running Debian on the internal NAND of my DockStar. I didn't use Jeff's method -- I started from debootstrap and just tweaked it until it worked. My installation currently uses about 60M.

> What do you recommend to do in Order to extend the Space?

I just moved the /var/cache/apt, /var/lib/apt, and /usr/share/doc dirs to a USB drive -- that saves me about 100M and doesn't affect normal operation -- I just have to plug the drive in when I want to install/update packages. I also installed the localepurge package which automatically removes i18n stuff that I don't need.

It's a bit error-prone, so an overlay system might indeed be a good idea.
Re: Install readonly embdebian on NAND
August 29, 2010 06:39AM
I keep looking at the script to install on NAND, but I have one problem: I killed my pogo on the NAND. How would I go about modifying the script to install to a second flash drive ie. /dev/sdb (since I'm booting debian from sda)?
Jörn
Re: Install readonly embdebian on NAND
August 31, 2010 05:25PM
Hi Jeff,

first of all thanks a lot for your great work! I encountered the same problem as mxspy (missing /dev/mtd3 after first reboot) and I also had the issue with Debian not booting successfully after applying your proposed fix. After thinking hard for some time how to avoid the serial cable, I figured out that the init=/sbin/init-ro bootarg is missing. So the correct command is:

fw_setenv set_bootargs_usb 'setenv bootargs console=$console root=$usb_root rootdelay=$usb_rootdelay rootfstype=$usb_rootfstype init=/sbin/init-ro $mtdparts'

Joern
ecc
Re: Install readonly embdebian on NAND
August 31, 2010 08:30PM
Jörn Wrote:
-------------------------------------------------------
After thinking hard
> for some time how to avoid the serial cable, I
> figured out that the init=/sbin/init-ro bootarg is
> missing.

Isn't this just a typo? I think it should be:
init=/sbin/init ro

(I've never come across an "/sbin/init-ro" binary before, and "ro" is a common boot param telling the kernel to initially mount the rootfs read-only).
Re: Install readonly embdebian on NAND
August 31, 2010 08:46PM
It's not a typo, it's a script that the installer creates. The script has a few workarounds to fix some app compatibility in the read-only environment.

-- Jeff
ecc
Re: Install readonly embdebian on NAND
August 31, 2010 08:59PM
Jeff Wrote:
-------------------------------------------------------
> It's not a typo, it's a script that the installer
> creates. The script has a few workarounds to fix
> some app compatibility in the read-only
> environment.

Ah, thanks for the correction. What compatibility issues does it solve? I'm using a vanilla Debian squeeze system (rather than emdebian) on ubifs now, and booting with regular init and "ro" has worked fine so far.
Re: Install readonly embdebian on NAND
August 31, 2010 11:32PM
It creates and populates a few tmpfs mount points for a handful of applications that expect rw access for their config files.
Hendrik
Re: Install readonly embdebian on NAND
September 01, 2010 01:32PM
Hi,

thanks for this guide.
Unfortunately at this position i'm stuck:
flash_eraseall /dev/mtd3
ubiformat /dev/mtd3 -y
ubiattach /dev/ubi_ctrl -m 3
ubimkvol /dev/ubi0 -m -N rootfs
Pogoplug:~$ ubimkvol /dev/ubi0 -m -N rootfs
-bash: ubimkvol: command not found

Now, I don't know whether I'm running debian or still the original Software.., which might be the problem.
Can I safely reboot, hoping, that then debian will come up, or have I killed something by the previous commands?

Regards,
Hendrik
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: