Home > Hacking, Linux, Mobiles > HOWTO — Running familiar Linux from CF/SD/MMC

HOWTO — Running familiar Linux from CF/SD/MMC

September 20th, 2007 Leave a comment Go to comments

This howto cov­ers one way of run­ning famil­iar Linux from your CF, SD, or MMC card.

OK, it doesn’t actu­ally boot from SD, but uses a snazzy Linux trick called pivot_root. Which switches over one root with another. This, IMHO, is prob­a­bly the best way of doing it apart from actu­ally directly boot­ing from SD. Although, I’ve only tried this on a 38xx based iPAQ it should work for all hand­helds based on famil­iar. Heck, it should work for any­thing really.

Pref­ace

The gen­eral idea is to boot up Linux from the inter­nal flash of the iPAQ to just before it runs the envi­ron­ment. Check the SD slot for a loopfs file, if one is there, then mount it up, switch roots, and con­tinue to boot.

Why?

There’s sev­eral ben­e­fits to doing it this way:

  1. Back­ups — Since you have a copy of the root filesys­tem on SD, you can back it up very eas­ily. Every PC these days has a SD slot. Just whack it in and copy the file across, you don’t even need Linux to do it either.
  2. Choices — You can startup either envi­ron­ment GPE or OPIE, just by chang­ing SD cards. (Fur­ther updates to set­MM­C­root will allow select­ing envi­ron­ment by buttons.
  3. Sav­ing files — regard­less of what envi­ron­ment you run, you can still save the files directly to the SD card. If you need them else­where, turn off the iPAQ, pop the SD card out and chuck it into a PC and read them. Easy!
  4. Dead SD — If your SD card dies, you can still run with a basic envi­ron­ment that is already loaded up on your iPAQ. With other meth­ods, if your SD dies that’s it. Things start going wierdo.

Pre-requisites

You’re going to need sev­eral things to do this:

  1. Linux based PC, any dist will do.
  2. An iPAQ — with famil­iar Linux already loaded up on to it, (doesn’t mat­ter what environment).
  3. A copy of famil­iar Linux , with either the GPE or OPIE will do. I used ver­sion 0.8.4 for this HOWTO. You will need the tar­balls from here and not the jffs files, (IE either of the *.rootfs.tar.bz2 files).
  4. Any SD, MMC, or CF card for­mat­ted with FAT16, (if you just bought it you don’t need to do any­thing as all flash cards are for­mat­ted these days).

Step 1 — Cre­ate root filesystem.

First we’ll need to cre­ate the filesys­tem that gets mounted up I’m cre­at­ing a 1G filesys­tem, because I tend to load up a lot of appli­ca­tions onto my iPAQs. Since I also have a 2G SD card, I will be able to store both the GPE and OPIE envi­ron­ments on it.

dd if=/dev/zero of=loopfs-gpe bs=1024 count=991680

Note the size is just under 1G? This is because a 1G filesys­tem on an SD card will con­sume slightly more than 1G. So, I’ve allowed for that. I can fit two filesys­tems on that card this way. Adjust the “count” to what­ever size you want or care for.

Now, you’ll need to setup the filesystem.

mkfs.ext2 loopfs-gpe

This will cre­ate a Linux ext2 filesys­tem. You can really use any filesys­tem, but you don’t want to use a jour­nelling filesys­tem like ext3, reis­erfs, xfs, as flash mem­ory can’t stand too many writes to it. Jour­nelling filesys­tem tend to write a lot of data even when not being used, (from a flash point of view).

Mount up the filesys­tem on your Linux box, (requires root).

mkdir loopfs-gpe.mount
mount -o rw,loop loopfs-gpe loopfs-gpe.mount

Extract the envi­ron­ment tar­ball into the loop­back mount point.

cd loopfs-gpe.mount
tar jxf ../gpe-image-v0.8.4-h3600.rootfs.tar.bz2

You will need to edit /etc/passwd and change the root pass­word to some­thing sen­si­ble if you want to login, the fol­low­ing entry will set the pass­word to ‘root’.

root:dquXGWQyEH.uI:0:0:root:/home/root:/bin/sh

Unmount the loopfs filesystem.

umount loopfs-gpe.mount

You now have a brand spank­ing new filesys­tem that will be used on your iPAQ.

Step 2 — Pre­pare your SD.

There are a num­ber of files that need to be cre­ated and copied over to your SD card. These are all required.

  • Your root filesys­tem that you just cre­ated, ensure it is called either loopfs-opie or loopfs-gpe.
  • The set­MM­C­root script , which does all the work.
  • Cre­ate a file called loopfs.boot on the SD card with the full path of the loopfs file you cre­ated. For exam­ple: /media/card/loopfs-gpe, or /media/card/loopfs-opie, or /media/card/i.like/it.here

Remove the SD card and plonk it into your iPAQ.

Step 3 — Pre­pare your iPAQ.

Fire up your favourite ser­ial port com­mu­ni­ca­tion pro­gram, (I use mini­com), to con­nect to your iPAQ, which should be con­nected to your PC by now. If you can’t do this, or don’t want to, then you can run these com­mands from within a con­sole on your iPAQ, (under the Appli­ca­tions tab). The pre­ferred option is to run the ppp dae­mon from your Linux box and ‘ssh 20.0.0.1′ into your iPAQ, using the fol­low­ing com­mand, (needs root on your PC):

/usr/sbin/pppd /dev/ttyS0 230400 20.0.0.5:20.0.0.1 nodetach local noauth nocrtscts lock user ppp connect "/usr/sbin/chat -v -t3 ogin--ogin: ppp"

Run the fol­low­ing com­mands in a shell on your iPAQ.

ln -s /etc/init.d/setMMCroot /etc/rc5.d/S01setMMCroot
ln -s /etc/init.d/setMMCroot etc/rc2.d/S01setMMCroot
cp /media/card/setMMCroot /etc/init.d/setMMCroot

I had sug­gested using the ppp dae­mon because then the next part becomes easy. You ned to install the extra pack­ages on your iPAQ. e2fsprogs, e2fsprogs-e2fsck, kernel-module-loop-2.4, and kernel-module-ext2-2.4. Run this on your iPAQ, or use the pack­age man­ager to do it.

ipkg install e2fsprogs e2fsprogs-e2fsck kernel-module-loop-2.4 kernel-module-ext2-2.4

Holy toledo bat­man! You’re almost there!

Step 4 — Reboot your iPAQ.

Reboot your iPAQ, via Start -> Set­tings -> Shutdown.

When you reboot you should see the fol­low­ing appear just under­neath the Linux pen­guin logo.

#### 1. Checking MMC: #
Found MMC!
Using loopfs: /media/card/loopfs-gpe
#### 2. FSCK filesystem:
/media/card/loopfs-gpe has gone 48850 days without being checked, check forced.
/media/card/loopfs-gpe: 2817/124160 files (0.1% non-contiguous), 12110/247900 blocks
#### 3. Setting up loopback FS:
Using /lib/modules/2.4.19-rmk6-pxa1-hh42/kernel/drivers/block/loop.o
#### 4. Mounting:
#### 5. Ballet:
#### 6. Tidying up:
killall: Xfbdev: no process killed
#### 7. Handover:

The script will wait for 16 sec­onds for an SD card to be inserted, (a hash will appear every sec­ond), else it will just boot up straight from the inter­nal flash. This allows you to just run with what­ever is there already, if need be.

Depend­ing on what envi­ron­ment you have run­ning will change some of the mes­sages between each stage. I’ll see if I can take a photo of the bootup stage and chuck it on here. (EDIT: I’ve put up some bloody hor­ri­ble images of the iPAQ boot­ing, taken with my mobile.)

Boot loader screen.

FSCK­ing the filesystem.

Bal­let school

From there onwards, it’s just the nor­mal boot procedure.

Step 5 — Final install.

Because this is a ‘fresh’ install you will be asked all the ques­tions you would have been asked when you did the ini­tial install of famil­iar on your iPAQ. If you get to this stage you’ve done it! Congratulations!

Once you have gone through the final install pro­ce­dure, if you open up a con­sole ses­sion and type ‘df’ , you’ll see what the set­MM­C­root script does. /mnt/realroot points to your iPAQ flash filesys­tem, and / is the SD filesys­tem. Cool eh?!

root@h3600:~# df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/root 976056 387164 539308 42% /
tmpfs 31676 40 31636 0% /mnt/realroot/var
tmpfs 31676 0 31676 0% /mnt/realroot/media/ram
/dev/mmc/part1 1983360 991712 991648 50% /mnt/realroot/media/card
/dev/loop/0 976056 387164 539308 42% /

No related posts.

Categories: Hacking, Linux, Mobiles Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.