LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   Squashfs Root on USB Flash drive. Need help with init (https://www.linuxquestions.org/questions/debian-26/squashfs-root-on-usb-flash-drive-need-help-with-init-651372/)

Drack 06-24-2008 04:35 PM

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.

IsaacKuo 06-24-2008 04:54 PM

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.

Drack 06-25-2008 07:37 AM

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.

kushalkoolwal 03-20-2009 05:48 PM

Quote:

Originally Posted by Drack (Post 3193970)
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?


All times are GMT -5. The time now is 02:53 PM.