LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 06-24-2008, 04:35 PM   #1
Drack
LQ Newbie
 
Registered: Feb 2006
Distribution: Gentoo and Debian
Posts: 8

Rep: Reputation: 0
Squashfs Root on USB Flash drive. Need help with init


My goal is to get a semi-persistent Debian install booted from a USB flash drive using squashfs for the root filesystem. It's semi-persistent because I should be able to rerun mksquashfs to update the image, otherwise it's read only but the os thinks it's read-write because of unionfs.

I've read a few guides to creating this kind of setup and none seem to fit very well. I'm using the amd64 architecture, debian etch. I presently have a full-blown install to the USB drive that boots and works fine - this is the fully-persistent install I want to make semi-persistent, for privacy (in case someone steals the drive, they won't get my identity from web browser history etc.) and other reasons.

I've installed squashfs-tools, squashfs-modules, unionfs-modules, and I've added squashfs and unionfs to /etc/modules. They modprobe just fine. I also installed initramfs-tools and casper if needed.

I need an init script to mount the squashfs image and set it as the root filesystem, with unionfs making it appear read-write. I'm not yet comfortable with my ability to write an init. One problem I've run into in the past on other distros is that the init script does not wait for the usb drive to be recognized and added to /dev, and it panics because it couldn't find the root filesystem. Debian's init works fine in this regard. Because it DOESN'T have this common issue, I'd like to modify this script instead of creating a new one.

I have other linux installs that I can mount the drive in if something needs to be performed not on the running system.
 
Old 06-24-2008, 04:54 PM   #2
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian 4.0 Etch
Posts: 1,349

Rep: Reputation: 49
I might be able to help, a little bit. I recently figured out how to do what I call "RAMboot", where the entire OS gets copied into a tmpfs ramdisk (not compressed). The result is just insanely fast.

In order to do it, I (temporarily) modified /usr/share/initramfs-tools/scripts/local. There's a line in this script where the root partition is mounted. I commented out that line, and replaced it with my custom script code to create the tmpfs root partition and untar an OS image into it.

After modifying /usr/share/initramfs-tools/scripts/local, I created the custom initrd.img with:

mkinitramfs -o /boot/initrd.img-2.6.18-6-686.ramboot

And then I copied back the original /usr/share/initramfs-tools/scripts/local. It's important to copy back the original, because if you don't then it will be used the next time the kernel is updated.

In GRUB, I created an entry based on the normal hard drive boot entry for "RAMboot". This custom entry used my custom initrd.img. Thus, I have the option to either boot up into my normal hard drive install, or I can boot up into the "RAMboot" OS. I boot into the normal hard drive install in order to add/remove software, configure things, and then create a new OS image based on it.

Here are my modifications to /usr/share/initramfs-tools/scripts/local:
Code:
[...]
########################################ramboot
        # FIXME This has no error checking
        # Mount root
###     mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}

################################ mount the filesystem
        mkdir /ijkijk
        mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /ijkijk

################################ create ramdisk (note hardcoded size)
        mount -t tmpfs -o size=400M none ${rootmnt}

################################ copy the files over to the ramdisk
        cd ${rootmnt}
        tar xf /ijkijk/snapstrip.tar

################################ umount the filesystem and set to spin down
        umount /ijkijk
	hdparm -S 6 /dev/hda

########################################ijk
[...]
For my purposes, the OS image is a non-compressed tar archive.

For your purposes, the OS image will be a squashfs file. You'll want to mount the "host" file system, perhaps /mnt/sda5, which contains the squashfs file. Then you'll mount the squashfs file system, and then merge it in (with what?) using unionfs.

Hopefully, I've given you some ideas of how to go about implementing your concept. The basic idea is to modify the initramdisk image with your own custom script for mounting the root partition.
 
Old 06-25-2008, 07:37 AM   #3
Drack
LQ Newbie
 
Registered: Feb 2006
Distribution: Gentoo and Debian
Posts: 8

Original Poster
Rep: Reputation: 0
Wink

That does help a bit.

I also found a guide with an init script at http://electronjunkie.wordpress.com/squashfs_script/ and a howto at http://www.ibiblio.org/pub/Linux/doc...shFS-HOWTO.pdf

As I said, I'm no shell/init scripting expert, but it looks like what I would have to do is something like this:

Code:
[...]
########################################ramboot
        # FIXME This has no error checking
        # Mount root
###     mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}

        mkdir /.tmpfs
        mount -w -t tmpfs -o size=90% tmpfs /.tmpfs
        # 90% of what? RAM?
        mkdir -p /.tmpfs/.mnt
        mkdir -p /.tmpfs/.sqfs
        mount -r -t reiserfs LABEL=LINUXUSB /.tmpfs/.mnt
        mount -t squashfs -o loop /.tmpfs/.mnt/root.squashfs /.tmpfs/.sqfs
        mount -t unionfs -o dirs=rw.fs=rw:/.tmpfs/.sqfs=ro unionfs ${rootmnt}

[...]
I'm sure there are a few mistakes in there, but I'll try it tonight.

Last edited by Drack; 06-25-2008 at 07:44 AM.
 
Old 03-20-2009, 05:48 PM   #4
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 48
Quote:
Originally Posted by Drack View Post
My goal is to get a semi-persistent Debian install booted from a USB flash drive using squashfs for the root filesystem. It's semi-persistent because I should be able to rerun mksquashfs to update the image, otherwise it's read only but the os thinks it's read-write because of unionfs.
Hi Drack, I was too planning to do something like that -squashfs with persistence. Was wondering if you were able to successfully implement what you were trying to. Can you please post your steps?
 
  


Reply

Tags
init, squashfs, unionfs


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fedora 7: autofs is not mounting USB flash drive or DVD ROM drive Hewson Linux - General 3 05-12-2008 08:58 AM
No filesystem could mount root, tried: cramfs squashfs romfs kkpal Linux - Distributions 0 01-09-2008 01:49 AM
cannot delete drive from root desktop - cannot mount usb flash drive - openSuSE 10.2 bluecog6 Linux - General 6 01-29-2007 03:18 PM
Why does my USB flash Drive appear when root? Cypher12 Linux - General 2 01-10-2007 04:22 PM
ZFS Root / Boot into ZFS from a usb flash drive Kataku Solaris / OpenSolaris 1 07-15-2006 04:13 AM


All times are GMT -5. The time now is 03:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration