Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] help on initramfs with squashfs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Wed Oct 24, 2012 4:37 pm    Post subject: [SOLVED] help on initramfs with squashfs Reply with quote

Hi there

Because I wanted to ged rid of the genkernel-initramfs procedure that has only
a dirty solution yet when booted with "docache" (https://bugs.gentoo.org/show_bug.cgi?id=389755) I want to get my own from scatch
initramfs.

My plan was to squashfs my rootfs (without portage) and to boot it into RAM with initramfs



My rootfs is on /dev/sda1.
-I squashed "/" on /dev/sda1 to a livecd.squashfs and cp it to "/" on /dev/sda.

-I created the initrams with the following init:

Code:

#!/bin/busybox sh

rescue_shell() {
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    exec /bin/sh
}

echo "mounting proc devtmpfs"
mount -v -t devtmpfs none /dev || rescue_shell
mount -v -t proc none /proc || rescue_shell
sleep 5

mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
mkdir /mnt/sq1
mount -t squashfs /mnt/sda1/livecd.squashfs /mnt/sq1
mkdir /mnt/tmpfs
mount -t tmpfs -o size=2900m tmpfs /mnt/tmpfs
cp -a /mnt/sq1/. /mnt/tmpfs


umount /proc
umount /dev
echo mama
exec switch_root /mnt/tmpfs /sbin/init || rescue_shell





and here is the fstab thats inside the squashfs and I guess there is someting wrong too, what to add instead of dev/loop0?:
Code:
/proc           /proc           proc            defaults                0 0
/sys            /sys            sysfs           defaults                0 0

/dev/loop0      /               ext4        defaults                0 1



This seems to work without errors until, I guess, it switches root.

Here is a screenshot where it hangs, the "NUM" Key still works but ctrl+c,ctrl+alt+del does nothing

[img]http://www.abload.de/img/bootmpqllwy.jpg[/img]

Does someone has a idea what could be wrong?


Last edited by dasPaul on Tue Oct 30, 2012 10:06 am; edited 4 times in total
Back to top
View user's profile Send private message
nativemad
Developer
Developer


Joined: 30 Aug 2004
Posts: 816
Location: Switzerland

PostPosted: Wed Oct 24, 2012 5:10 pm    Post subject: Reply with quote

Hi,

...as i don't see the "mama" in the screenshot I suspect that it hangs before the switch-root!
Maybe you should add some more comments to see how far you get!?
I suggest you to use "cp -av", so you actually see if that takes longer than expected.

HTH a bit.

Cheers
_________________
Power to the people!
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Wed Oct 24, 2012 5:14 pm    Post subject: Reply with quote

I don't think umounting /dev is a good idea. Isn't that where you root file system lives?
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Wed Oct 24, 2012 5:50 pm    Post subject: Reply with quote

nativemad wrote:
...as i don't see the "mama" in the screenshot


Its in the screenshot @ very last line ;)

@BitJam

I removed it but error is still the same.

The next thing I tried was to remove the fstab in the squashfs completely and now I get an error.
Code:
fstabinfo ..segfault...

so I think it has all to do with the fstab in the squashfs
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Wed Oct 24, 2012 7:25 pm    Post subject: Reply with quote

It is possible that switch_root is unhappy with switching to a loop device. I've avoid this on a LiveCD/USB/HD by bind mounting all the top level directories and then just exec'ing /sbin/init directly:
Code:
for i in $(cd $AUFS_MP; echo *); do
    # bind mount new stuff in $AUFS_MP
    [ -d "$AUFS_MP/$i" ]      || continue
    mountpoint -q "/$i"       && continue
    [ -d "/$i" -o  -f "/$i" ] && continue
    mkdir -p /$i
    mount -o bind $AUFS_MP/$i /$i
done

[...]

exec /sbin/init "$@" </dev/console >/dev/console 2>&1
For you, AUFS_MP would be /mnt/tmpfs. This has been widely tested and is solid. Some people use it for their desktop system. I have not tried it with Gentoo.

I much prefer to debug this stuff in VirtualBox. You make a .iso file and then boot off of that inside of vbox. Perhaps you won't need to take things this far. Also (depending on your kernel?) using the vga=xxx boot parameter can give you a higher resolution display which can be helpful. I usually use vga=795 which gives me 1280x1024.
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Wed Oct 24, 2012 8:45 pm    Post subject: Reply with quote

ok my init looks now that:

Code:

#!/bin/busybox sh

rescue_shell() {
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    exec /bin/sh
}

echo "mounting proc devtmpfs"
mount -v -t devtmpfs none /dev
mount -v -t proc none /proc
sleep 5

mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
mkdir /mnt/sq1
mount -t squashfs /mnt/sda1/livecd.squashfs /mnt/sq1
mkdir /mnt/tmpfs
mount -t tmpfs -o size=2900m tmpfs /mnt/tmpfs
cp -av /mnt/sq1/. /mnt/tmpfs


umount /proc

echo "mama"

sleep 5
mount
sleep 10

for i in $(cd /mnt/tmpfs; echo *); do
    # bind mount new stuff in $AUFS_MP
    [ -d "/mnt/tmpfs/$i" ]      || continue
    mountpoint -q "/$i"       && continue
    [ -d "/$i" -o  -f "/$i" ] && continue
    mkdir -p /$i
    mount -o bind /mnt/tmpfs/$i /$i
   
done

mount
sleep 10
exec /sbin/init "$@" </dev/console >/dev/console 2>&1



After booting that it gives the error /sbin/init not found:

[img]http://www.abload.de/img/bootmp2craib.jpg[/img]

So I added /sbin/init to your lines ... plus some mount / ls stats to see whats in there

Code:


...
for i in $(cd /mnt/tmpfs; echo *); do
    # bind mount new stuff in $AUFS_MP
    [ -d "/mnt/tmpfs/$i" ]      || continue
    mountpoint -q "/$i"       && continue
    [ -d "/$i" -o  -f "/$i" ] && continue
    mkdir -p /$i
    mount -o bind /mnt/tmpfs/$i /$i
    mkdir -p /sbin
    mount -o bind /mnt/tmpfs/sbin /sbin
...


what gives now the INIT Process, but without an inittab as you can see here :roll:

[img]http://www.abload.de/img/bootmp3kolol.jpg[/img]

Something is deeply wrong here and please again what do you think about my fstab on the rootfs, i have absolutely no plan what to define in there for the root mount point...
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Wed Oct 24, 2012 9:33 pm    Post subject: Reply with quote

I gave you the wrong snippet of code! Sorry about that. Try this instead:
Code:
for dir in bin boot etc sbin var lib opt root tmp usr home; do

    # bind mount directories to aufs
    mkdir -p /$dir
    mkdir -p $AUFS_MP/$dir
    $STATIC/mount -o bind $AUFS_MP/$dir /$dir
done
I also had put busybox and its symlinks in /live/bin in my initramfs and make /bin and /sbin symlinks to it. I set:
Code:
PATH=/live/bin; export PATH
The STATIC variable above is just /live/bin.

You should not have to umount /proc /sys or /dev.

Again, I'm sorry for all the confusion I generated. I searched for "bind" from the bottom of my script and I had forgotten there were two bind mount loops.
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Thu Oct 25, 2012 8:10 am    Post subject: Reply with quote

new day new luck, finaly I changed your last code to a bit more "kindergarten"-like because ist still complained about "sbin/init not found... panic!" and I ended in a fully working, non erroneous, insane fast boot (after copy2ram) :P
thats my working init:

Code:

#!/bin/busybox sh

rescue_shell() {
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    exec /bin/sh
}

#mount needed

mount -v -t devtmpfs none /dev
mount -v -t proc none /proc

#mount sqfs partition,create tmps,copy root, umount uneeded
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
mkdir /mnt/sq1
mount -t squashfs /mnt/sda1/livecd.squashfs /mnt/sq1
mkdir /mnt/tmpfs
mount -t tmpfs -o size=2900m tmpfs /mnt/tmpfs
cp -av /mnt/sq1/. /mnt/tmpfs
umount /mnt/sq1 /mnt/sda1

#make dirs
mkdir bin boot etc import inst lib lib32 lib64 media opt root run sbin usr var
   mount -o bind /mnt/tmpfs/bin bin
   mount -o bind /mnt/tmpfs/boot boot
   mount -o bind /mnt/tmpfs/etc etc
   mount -o bind /mnt/tmpfs/lib32 lib32
   mount -o bind /mnt/tmpfs/lib64 lib64
   mount -o bind /mnt/tmpfs/media media
   mount -o bind /mnt/tmpfs/opt opt
   mount -o bind /mnt/tmpfs/root root
   mount -o bind /mnt/tmpfs/run run
   mount -o bind /mnt/tmpfs/sbin sbin
   mount -o bind /mnt/tmpfs/usr usr
   mount -o bind /mnt/tmpfs/var var
        mount -o bind /mnt/tmpfs/lib64 lib
exec /sbin/init "$@" </dev/console >/dev/console 2>&1

Just to mention the /lib dir was linked to lib64, that wont work on boot so I mount bind it to lib64

I dont know if it had any impact on the bootprocess but here is my fstab from the squashfs
Code:
/mnt/tmpfs   /   tmpfs   rw,defaults 0 0
none   /dev/shm   tmpfs   defaults 0 0
none   /proc   proc   defaults 0 0


Now I have a basis for further tweaking and improving and Iam free of genkernel :P
And of course thanx for your hints
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Thu Oct 25, 2012 8:45 am    Post subject: Reply with quote

I'm glad you got it to work despite my "help".
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Mon Oct 29, 2012 7:38 pm    Post subject: Reply with quote

there rose two questions in me:

what exactly does "$@" and the "</dev/console >/dev/console 2>&1" stand for in the line:

Code:
exec /sbin/init "$@" </dev/console >/dev/console 2>&1


My system seems to boot without error when I only use:

Quote:
exec /sbin/init


And 2nd:

What triggers the clean unmount of my mounted filesystems on the reboot command?
When I do reboot, it (open-rc?) only does a:

* Stopping local ..
* Saving random seed ...
* Deaktivating swap devices ....
REBOOT
no stoping services
no unmounting loop devices

I just noticed it because on boot it shows /dev/sda1 filesystem recovery message.
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Mon Oct 29, 2012 9:08 pm    Post subject: Reply with quote

dasPaul wrote:
what exactly does "$@" and the "</dev/console >/dev/console 2>&1" stand for in the line: [...]
My system seems to boot without error when I only use:
Quote:
exec /sbin/init

That was code I borrowed from elsewhere. The "$@" is supposed to send whatever command line parameters were sent to /init on to /sbin/init. This has probably been superseded by /proc/cmdline. Likewise the redirects were to assure that the input and output for /sbin/init are tied to the console. I'm glad to hear they are no longer needed. I will try running without them here. Thanks.
Quote:
What triggers the clean unmount of my mounted filesystems on the reboot command?
Make sure you are not using the busybox "reboot". Do a "which reboot" to find out.

If that doesn't work then I don't know. Perhaps the setup I gave you conflicts with openRC somehow. I've been using it on Debian based systems that use sysvinit. If it's not a busybox/path problem then I suggest you start a new thread with this openRC question.
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Tue Oct 30, 2012 7:39 am    Post subject: Reply with quote

BitJam wrote:
I'm glad to hear they are no longer needed. I will try...

Please do with care, my setup may be slightly different. I noticed the execution of "exec/sbin" takes some 4 seconds longer without the $@ console stuff...

Still no luck with clean reboot/shutdown. "which reboot" shows "/sbin/reboot".. I will do a bit more investigation before opening another thread.

thanx so far
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Tue Oct 30, 2012 7:46 am    Post subject: Reply with quote

You could trying putting the "$@" back in to see if that helps with your reboot problem.
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Tue Oct 30, 2012 9:03 am    Post subject: Reply with quote

no difference, still unclean reboot/shutdown
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Tue Nov 06, 2012 7:58 pm    Post subject: Reply with quote

BTW: it will boot much faster and use less RAM if you use aufs (another union filesystem) to combine a tmpfs with the squashfs because file system changes will be stored in RAM and you don't have to unsquash the squashfs at boot-time. This setup runs a little slower because parts of the squashfs get decompressed as needed.

An intermediate solution is to use an aufs but first copy the squashfs file into RAM. This runs fast (but not as fast as your original solution) and has a smaller RAM footprint (because the squashfs file in RAM is still compressed) but you need to do the copy of the squashfs at boot-time so it may not boot much faster.

One benefit of these two approaches is that you have the option of saving your filesystem changes across reboots. At shutdown, just copy the tmpfs part of the aufs into a disk-based filesystem and copy from the filesystem back to the tmpfs part of aufs at boot-time.
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Wed Jan 23, 2013 8:19 pm    Post subject: Reply with quote

BitJam wrote:
BTW: it will boot much faster and use less RAM if you use aufs

My current way is to:
dedicate ~1.5Gb ram to tmpfs
1. copy the whole squash.img into tmpfs (takes the most time, ~700Mb)
2. mount squash.img and bind-mount the ro-dirs to newroot(tmpfs)
3. copy the rw-dirs to newroot(tmfps, ~50Mb)
4. init the system (~700Mb left in rw-dirs and homedirs )

Important and big dirs/files are symliked to outside disks (games,musik,pornos...)


So it does read the ro-dirs from the squashed image but will it be much faster if it reads it from uncompressed/aufs tmps ?
I think the difference in time will not matter.

And the "option of saving your filesystem changes across reboots" is not very important for me. I preconfigured my ~/ settings in the master image and gather updates as a task list that I run periodically.
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2429
Location: Silver City, NM

PostPosted: Wed Jan 23, 2013 8:51 pm    Post subject: Reply with quote

dasPaul wrote:
...
1. copy the whole squash.img into tmpfs (takes the most time, ~700Mb)
...

So it does read the ro-dirs from the squashed image but will it be much faster if it reads it from uncompressed/aufs tmps ?
The time used to copy the whole squashfs.img is the time you will save.
Back to top
View user's profile Send private message
dasPaul
n00b
n00b


Joined: 14 Feb 2012
Posts: 46
Location: VirgoSC/LocalGroup/MilkyWay/Solarsystem/Earth/Europe/Germany/Saxony/Dresden

PostPosted: Fri Jan 25, 2013 10:39 am    Post subject: Reply with quote

thats right for shure but sorry, I did not mention that my goal was to have a system without any removeable devices, (cd,dvd,usb,hdd...)...plug usb--boot--just OS in ram--remove usb--go away --power off = nothing left :), exactly what the "docache" kernel command line option from the gentoo.iso normaly does (and is currently damaged with genkernel bug). Thats why I wrote my own initramfs to get rid of genkernel and have a docache option on boot.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum