Jump to content


HOWTO - Mount SD card as part of the unionfs


160 replies to this topic

#1 albkwan

    ExtrEmE User

  • Members
  • 1,440 posts
  • LocationHong Kong

Posted 01 January 2008 - 04:32 PM

EDIT: I have hosted the initramfs image on http://eeepc.fire.prohosting.com/. If you download it, then you can skip steps 4-7 below.

UPDATED 2008/9/10: The initramfs image I have hosted now also support 900 and later models.

EDIT 2009/3/14: There is another set of instructions for doing this without Puppy Linux in thread #37 of this post. You will be working solely on the command line within EeePC Linux with that method.

I have worked out this solution to mount a 4G SD card as part of the filesystem of my Eeepc Linux, in particular as the USER partition of the unionfs instead of the default /dev/sda2. So, now I have plenty of free space in my Eeepc Linux (and my next step would be to install win2k on /dev/sda2).

The steps here are actually quite similiar to the steps for booting Xandros from USB. But BEWARE: Any mistake may render the default Xandros not usable and end up having to restore from DVD image. Take your own risk in testing this steps!

What you will need:

(i) a SD card (minimum 2G)
(ii) A Linux on USB (I am using my default Xandros booting from a USB card reader, you can also try with Puppy Linux).
[NB. Another possibility would be a Linux on CD, but then you will need an external CDROM]

The commands below are for working with default Xandros booting from USB. If you are using Puppy Linux, there will be some notable difference:

(i) Puppy Linux see the SSD as IDE, so /dev/sda1 and /dev/sda2 will appear as /dev/hdc1 and /dev/hdc2, and /dev/sdb1 will appear as /dev/sda1. Verify this for yourself on your system. You will have to change the device names in the commands below accordingly.

(ii) In Puppy Linux, the user is already by default "root". But for default Xandros, you will need to change user to root to run all the commands below:
sudo bash
Also in default Xandros, better do it on konsole (File Manager > Tools > Open Console Window) as you can copy and paste commands there.

(iii) Same for the File Manager in Puppy Linux, already root. For default Xandros, run a superuser File Manager with:
sudo XandrosFileManager
Here are the steps:

1) Backup your existing USER partition (/dev/sda2) to an USB flash disk (Optional)
dd if=/dev/sda2 | gzip > /mnt/media/xxx/xxx/eeepc-sda1.img.gz
Replace /mnt/media/xxx/xxx with the path of your USB storage device as you can see it in your File Manager.

2) Prepare your SD card - fdisk and format to ext3
cfdisk /dev/sdb
New > Primary > Enter > Write > "yes" > Quit

mke2fs -c -L USER /dev/sdb1
tune2fs -j /dev/sdb1
3) Copy all data from your existing USER partition (sda2) to your new USER partition (sdb1)
cd /mnt
mkdir sda1 sda2 sdb1
mount -t ext3 /dev/sda2 /mnt/sda2
mount -t ext3 /dev/sdb1 /mnt/sdb1
cd /mnt/sda2
cp -ax * /mnt/sdb1
4) Create a temp dir in /boot of sdb1 and unpack the initramfs image there:
mount -t ext2 /dev/sda1 /mnt/sda1
cd /mnt/sdb1/boot
mkdir temp
cd temp
gunzip < /mnt/sda1/boot/initramfs-eeepc.img | cpio -i
5) Modify "init":
EDIT: Thanks to the insight of Russell, we can actually load the USB modules from within the filesystem instead of copying them into the initramfs image.
kwrite init
Look for these lines:
mount -t ext2 -o ro $ROOT /mnt-system
if [ $? -ne 0 ] ; then
    echo Could not mount OS on $ROOT. Starting debugging shell....
    /bin/busybox sh
fi
Add the following lines just after it to USB modules at bootup:
#load USB modules
VERSION=`cat /proc/version | cut -f3 -d" "`
insmod -f /mnt-system/lib/modules/$VERSION/kernel/drivers/usb/core/usbcore.ko > /dev/null
insmod -f /mnt-system/lib/modules/$VERSION/kernel/drivers/usb/host/ehci-hcd.ko > /dev/null
insmod -f /mnt-system/lib/modules/$VERSION/kernel/drivers/usb/host/uhci-hcd.ko > /dev/null
insmod -f /mnt-system/lib/modules/$VERSION/kernel/drivers/usb/storage/libusual.ko > /dev/null
insmod -f /mnt-system/lib/modules/$VERSION/kernel/drivers/usb/storage/usb-storage.ko > /dev/null

#loop scanning for usb devices
while ! grep -q "sdb1" /proc/partitions; do sleep 1; done
Also change all sda2 to sdb1. Save and quit.

6) Create device sdb1 in /dev of the temp dir:
cd /mnt/sdb1/boot/temp/dev
mknod -m 660 sdb1 b 8 17
[NB. don't substitute "sdb1" in the mknod command even if you are using Puppy Linux]

7) Now pack the initramfs image and move it to /mnt/sda1/boot:
cd /mnt/sda1/boot
mv initramfs-eeepc.img initramfs-eeepc.img.orig
cd /mnt/sdb1/boot/temp
find | cpio -H newc -o | gzip -9 > ../initramfs-eeepc.img
cd ../
mv initramfs-eeepc.img /mnt/sda1/boot
8) Edit the file scanuser.sh:
cd /mnt/sda1/sbin
cp scanuser.sh scanuser.sh.orig
kwrite scanuser.sh
Replace all "sda2" with "sdb1".

9) Do the same for formatuser.sh:
cd /mnt/sda1/sbin
cp formatuser.sh formatuser.sh.orig
kwrite formatuser.sh
Replace all "sda2" with "sdb1".

EDIT: This step is not necessary!
10) Give exec permission to your SD card as per this thread.


11) Reboot.

The beauty of this method is that all the changes are permanent and upgrading your SD card to a even bigger capacity in the future (when price is more attractive) is very easy. You only need to repeat steps 2 and 3 for your new SD card.

So time for a beer?

Edited by albkwan, 14 March 2009 - 01:14 PM.

EeePC 4G white,
Default Xandros (Easy Mode + icewm start menu) on 1st SSD/2nd 16GB SSD added/SD/USB/
http://eeepc.fire.prohosting.com/
http://eeepc-albkwan.blogspot.com/

#2 wamser_e

    Senior Member

  • Members
  • 101 posts

Posted 01 January 2008 - 05:59 PM

This is a nice alternative to removing unionfs. I have an 8G SDHC card showing up soon. If I have trouble removing unionfs I may go this route instead and if I need to read an SD card I can just use my cheap USB external card reader. Thanks for posting this!

#3 lcangler

    Member

  • Members
  • 14 posts

Posted 02 January 2008 - 01:26 AM

This sounds like what I have been looking for. But I am such a noob with Linux, I need to make sure I understand exactly what you've done and if it is what I need. I put xp on my ssd and would like to intall/run xandros from my 8g sd card. I will leave the sd card in all the time. Does this procedure preclude using the sd card for anything else? Can you partition a card and have xandros on part of the card and put some of your other windows type program files on the card in another partition? That would be the best of all worlds for me.

#4 jasonp

    Advanced Member

  • Members
  • PipPipPip
  • 57 posts

Posted 02 January 2008 - 01:33 AM

Quote

I put xp on my ssd and would like to intall/run xandros from my 8g sd card. I will leave the sd card in all the time. Does this procedure preclude using the sd card for anything else? Can you partition a card and have xandros on part of the card and put some of your other windows type program files on the card in another partition?
You should use the technique given in the wiki http://wiki.eeeuser....drosbootfromusb for what you have described instead. But since xandros is gone from your ssd you'll need something like puppy linux or eeexubuntu on usb stick to execute the commands. It's possible to partition the sd card in the way you have described to share between xandros and xp. I'm doing something similiar from a USB hard disk.

Edited by jasonp, 02 January 2008 - 01:35 AM.


#5 albkwan

    ExtrEmE User

  • Members
  • 1,440 posts
  • LocationHong Kong

Posted 02 January 2008 - 01:35 AM

Another application of this modification has come to my mind:

With the USER partition all on a SD card, you can share your eeepc with members of your family, or lend out to students at school. Every user only need to have his/her own SD card, insert it into the eeepc and boot it.

Then every user can have the freedom to install programs he/she like, store their personal data, without the need to config different user profiles ... etc on the limited space of the SSD.

And the best thing of this approach is that it is fully upgradeable and you don't need to worry about wearing of the SSD (which is now read only). Any sign of disk read/write error on the SD, you just buy a new SD and move all your data there.
EeePC 4G white,
Default Xandros (Easy Mode + icewm start menu) on 1st SSD/2nd 16GB SSD added/SD/USB/
http://eeepc.fire.prohosting.com/
http://eeepc-albkwan.blogspot.com/

#6 cyril

    Member

  • Members
  • 17 posts

Posted 02 January 2008 - 03:15 AM

I am new to all this but I think I understand. With this method, I could install Xandros and XP on an 8GB SD cardd and boot into either? The added benefit is that I could install any apps that I want for Xandros (on the SD card) without worrying about running out of space like he default Xandros?

Do I have that right?

Thanks for all your help

#7 albkwan

    ExtrEmE User

  • Members
  • 1,440 posts
  • LocationHong Kong

Posted 02 January 2008 - 03:31 AM

Quote

I am new to all this but I think I understand. With this method, I could install Xandros and XP on an 8GB SD cardd and boot into either? The added benefit is that I could install any apps that I want for Xandros (on the SD card) without worrying about running out of space like he default Xandros?

Do I have that right?

Thanks for all your help
Exactly.

Also, this will solve the limited disk space problem of 2G eeepc.
EeePC 4G white,
Default Xandros (Easy Mode + icewm start menu) on 1st SSD/2nd 16GB SSD added/SD/USB/
http://eeepc.fire.prohosting.com/
http://eeepc-albkwan.blogspot.com/

#8 alanbcohen

    Senior Member

  • Members
  • 505 posts
  • LocationBaltimore, MD, USA

Posted 02 January 2008 - 01:29 PM

albkwan,

Thank you! I had posted a request for this a couple of days ago, and you have come through! I've copied your HowTo (so I can find it again!) and will be trying it tonight.
All opinions, information etc in this forum post is copyrighted by me (alanbcohen) unless indicated otherwise.
You are free to reuse whatever you want to, provided that:
1) you give credit to me and eeeuser.com whenever you reuse anything for all things you reused.
2) you do not pretend or create the illusion that your modifications are mine. I'll be responsible for my junk, you for yours.

#9 lcangler

    Member

  • Members
  • 14 posts

Posted 02 January 2008 - 02:05 PM

How is the procedure described in this link http://wiki.eeeuser....drosbootfromusb different from the procedure that albkwan developed. I thought there was some issue trying to run xandros from an sb card and that albkwan's procedure fixed this. Can someone explain this for me before I do anything stupid??

#10 albkwan

    ExtrEmE User

  • Members
  • 1,440 posts
  • LocationHong Kong

Posted 02 January 2008 - 03:31 PM

Quote

How is the procedure described in this link http://wiki.eeeuser....drosbootfromusb different from the procedure that albkwan developed. I thought there was some issue trying to run xandros from an sb card and that albkwan's procedure fixed this. Can someone explain this for me before I do anything stupid??
Both steps are written by me. There is not much difference - Only where to mount the USER partition.

The issue that come when booting Xandros from an SD card (i.e. /dev/sdb) comes from udev that mounts removable USB devices. This happens after the system has completely boot up (after X windows is running).

Tonight, while redoing it all over again, I come to a situation when the system has completely boot up, I check and found that /dev/sdb2 has been mounted read/write. But after a few seconds, it becomes read only!

This does not occur at every boot up and it never happen to a USB flash disk (i.e. /dev/sdc), But sometimes it happens. I think the solution should be changing the udev rules to disable udev from re-mounting this SD card again.

In my old system, I have something like this. But since I have format everything (due to a silly mistake), I have to do it all over again!

EDIT: It's too late now. I need some good sleep tonight!

Edited by albkwan, 02 January 2008 - 03:32 PM.

EeePC 4G white,
Default Xandros (Easy Mode + icewm start menu) on 1st SSD/2nd 16GB SSD added/SD/USB/
http://eeepc.fire.prohosting.com/
http://eeepc-albkwan.blogspot.com/

#11 lcangler

    Member

  • Members
  • 14 posts

Posted 02 January 2008 - 05:53 PM

Thanks albkwan. When you do it again and I am sure will get it going, can you edit your original procedure and repost with one writeup. Linux is so new to me, I get confused trying to paste together different procedures and trying to land on the last one that worked. One other question that was unclear, if I follow your procedure... normally booting XP from SSD and using SD for program and data file access (office, etc.) nothing will change for that right? When I want to run xandros, I get to choose to boot linux from SD card and off it goes. That would be sweet.

#12 albkwan

    ExtrEmE User

  • Members
  • 1,440 posts
  • LocationHong Kong

Posted 03 January 2008 - 02:48 AM

Quote

Thanks albkwan. When you do it again and I am sure will get it going, can you edit your original procedure and repost with one writeup. Linux is so new to me, I get confused trying to paste together different procedures and trying to land on the last one that worked. One other question that was unclear, if I follow your procedure... normally booting XP from SSD and using SD for program and data file access (office, etc.) nothing will change for that right? When I want to run xandros, I get to choose to boot linux from SD card and off it goes. That would be sweet.
I will repost the steps later. Last night, I was redoing it with Puppy Linux. I found that Puppy Linux has more GUI tools, which I think will be much easier for Window users (not acquainted with Linux) to follow.

As for the dual boot thing, I am also planning to install win2k on my /dev/sda2 partition (the original USER partition). After I get that working, I will also post the steps.
EeePC 4G white,
Default Xandros (Easy Mode + icewm start menu) on 1st SSD/2nd 16GB SSD added/SD/USB/
http://eeepc.fire.prohosting.com/
http://eeepc-albkwan.blogspot.com/

#13 jasonp

    Advanced Member

  • Members
  • PipPipPip
  • 57 posts

Posted 03 January 2008 - 07:13 AM

Quote

Another application of this modification has come to my mind:

With the USER partition all on a SD card, you can share your eeepc with members of your family, or lend out to students at school. Every user only need to have his/her own SD card, insert it into the eeepc and boot it.

Then every user can have the freedom to install programs he/she like, store their personal data, without the need to config different user profiles ... etc on the limited space of the SSD.

And the best thing of this approach is that it is fully upgradeable and you don't need to worry about wearing of the SSD (which is now read only). Any sign of disk read/write error on the SD, you just buy a new SD and move all your data there.
Russel has done something similiar and included support for using USER as an encrypted container with LUKS and as a ram disk.

http://slofith.org/projects/eeepc/

Edited by jasonp, 03 January 2008 - 07:14 AM.


#14 albkwan

    ExtrEmE User

  • Members
  • 1,440 posts
  • LocationHong Kong

Posted 03 January 2008 - 07:41 AM

Quote

Quote

Another application of this modification has come to my mind:

With the USER partition all on a SD card, you can share your eeepc with members of your family, or lend out to students at school. Every user only need to have his/her own SD card, insert it into the eeepc and boot it.

Then every user can have the freedom to install programs he/she like, store their personal data, without the need to config different user profiles ... etc on the limited space of the SSD.

And the best thing of this approach is that it is fully upgradeable and you don't need to worry about wearing of the SSD (which is now read only). Any sign of disk read/write error on the SD, you just buy a new SD and move all your data there.
Russel has done something similiar and included support for using USER as an encrypted container with LUKS and as a ram disk.

http://slofith.org/projects/eeepc/
Just take a look at Russel's init file. Indeed, he has done it in an even smarter way:

There is actually no need to copy the USB modules into init, they can be loaded from within the root filesystem after mounting /mnt-system. This will require fewer changes to the initramfs image. I will test it and update the steps above.

The other thing I like very much is booting with a ramdisk when no SD card is available - just like a Linux on CD!
EeePC 4G white,
Default Xandros (Easy Mode + icewm start menu) on 1st SSD/2nd 16GB SSD added/SD/USB/
http://eeepc.fire.prohosting.com/
http://eeepc-albkwan.blogspot.com/

#15 majic

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 10 January 2008 - 03:06 PM

Hi,

Great thread.

I'm a linux newbie but if I understand this correctly it means that when I install my apps via apt-get they will be placed on my SD card, preserving that valuable SDD card space.. My question is more about the steps taken to achieve this. I think I understand most of it but the mknod command loses me. What exactly is that being used for? A google search threw up what the command is for. Creating some special file. But it doesnt explain why its required here. If anyone could shed some light on that I'd be greatful :)

I assume that this elborate process is mainly to auto mount the SD card early enough in the boot process so its available (for mounting) and then sdb1 is mounted at /mnt-user instead of sda2. Is that right?

Well sorry for probably asking dumb questions but in helping me to learn linux i'd like to understand this entire process a little more fully :)

thanks
my Karma just ran over your Dogma

#16 albkwan

    ExtrEmE User

  • Members
  • 1,440 posts
  • LocationHong Kong

Posted 10 January 2008 - 03:27 PM

Hard disks are block devices in Linux. They are special files in the Linux filesystem which need to be created by the mknod command. To help the kernel to identify them, each device is assigned a major and minor number. The scsi disk0 is conventionally assigned a major number of 8. Only the minor number changes for sda, sdb, sdc, and so on.

For the 1st partition on the 1st scsi disk, i.e. /dev/sda1, the major and minor numbers are 8 and 1;
...
For the 16th partition on the 1st scsi disk, i.e. /dev/sda16, the major and minor numbers are 8 and 16;
For the 1st partition on the 2nd scsi disk, i.e. /dev/sdb1, the major and minor numbers are 8 and 17;
...
For the 16th partition on the 2nd scsi disk, i.e. /dev/sdb16, the major and minor numbers are 8 and 32;
...
For the 1st partition on the 3rd scsi disk, i.e. /dev/sdc1, the major and minor numbers are 8 and 33;
...
and so on.

For more information, you can read the manual page and info page of the command mknod, or refer to Linux kernel documentation.
man mknod
info mknod
'q' to quit

EeePC 4G white,
Default Xandros (Easy Mode + icewm start menu) on 1st SSD/2nd 16GB SSD added/SD/USB/
http://eeepc.fire.prohosting.com/
http://eeepc-albkwan.blogspot.com/

#17 majic

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts

Posted 10 January 2008 - 04:23 PM

Thanks for that. I also looked http://lwn.net/Articles/210046/ and read about creating an initramfs and now its all becoming clear :-)

oh yes, this helped understand the process too :)
http://www.tldp.org/.../buildroot.html

damn, i'm starting to love linux.. god bless the eeePC :)

Edited by majic, 10 January 2008 - 04:38 PM.

my Karma just ran over your Dogma

#18 ERamseth

    Advanced Member

  • Members
  • PipPipPip
  • 35 posts

Posted 10 January 2008 - 06:08 PM

OK if I am not mistaken, this moves everything from the SSD storage to the SD card, correct? Or does this "add" the available storage space of the SD card to the root file system in general?

#19 Qatz

    Senior Member

  • Members
  • 212 posts
  • LocationIn your hair.

Posted 10 January 2008 - 06:20 PM

It moves it to sd, if you want something that just adds sd as storage through unionfs thats not hard either. In fact I'm already working an a set of scripts and programs that will automate that for you =)
Beer?
4G White 701a with Flash PCI-E Slot | 2 gig Ram | Gentoo | Kernel 2.6.25.4

#20 ERamseth

    Advanced Member

  • Members
  • PipPipPip
  • 35 posts

Posted 10 January 2008 - 06:48 PM

Very nice.

I did a little more reading about UnionFS after I last posted. Ideally, for me at least, I would a) keep the "recovery" partition (which I understand to be the "bottom layer" of the UnionFS tree in the EeePC); b) use the rest of the free space on the internal SSD as the "second layer" of the UnionFS tree; and c) when the SSD is full (or near full) start using the space on the SD card.

It seems this would create the scenario that the SD card would need to be kept in at all times. Also, I don't even know if this kind of set up is possible (it seems perfectly possible, but automatically switching to SD card space rather than SSD card space may not be possible).

In any case, please leave updates on these scripts you're working on.

Edited by ERamseth, 10 January 2008 - 06:49 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users