DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2009-11-07 13:58:03

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

initrd won't switch_root

I am trying to use unionfs as root filesystem. The firmware ro, with an usbstick rw overlay. To do so I'm using reloaded.ko, and an initrd containing this /init script: (there's a symlink /linuxrc pointing to it)

Code:

#!/bin/sh

echo starting initrd/linuxrc...

mount -t proc /proc /proc

ROOT_RO=` cat /proc/cmdline | sed 's/.*root=// ; s/ .*//'`
ROOT_RW=` cat /proc/cmdline | sed 's/.*overlay=// ; s/ .*//'`
INIT=` cat /proc/cmdline | sed 's/.*init=// ; s/ .*//'`


echo mounting $ROOT_RO and $ROOT_RW

mount -o ro $ROOT_RO /mnt-ro
if [ $? -ne 0 ] ; then
    echo could not mount $ROOT_RO. Starting shell....
    /bin/sh
fi

mount -o rw -o noatime $ROOT_RW /mnt-rw
if [ $? -ne 0 ] ; then
    echo could not mount $ROOT_RW. Starting shell....
    /bin/sh
fi


insmod /lib/modules/unionfs.ko

mount -t unionfs -o dirs=/mnt-rw=rw:/mnt-ro=ro -o noatime unionfs /mnt
if [ $? -ne 0 ] ; then
    echo could not mount unionfs. Starting shell....
    /bin/sh
fi
echo unionfs mounted, moving mounts...

mkdir /mnt/mnt/ro
mount --move /mnt-ro /mnt/mnt/ro
mkdir /mnt/mnt/rw
mount --move /mnt-rw /mnt/mnt/rw

printf "0x%x%02x" ` mountpoint -d /mnt | sed 's/:/ /' ` > /proc/sys/kernel/real-root-dev
umount /proc

exec switch_root /mnt $INIT "$@" </dev/console >/dev/console 2>&1

echo Failed. Starting shell....
/bin/sh

The serial output during and shortly after running initrd:

Code:

RAMDISK: squashfs filesystem found at block 0
RAMDISK: Loading 595KiB [1 disk] into ram disk... done.
VFS: Mounted root (squashfs filesystem) readonly.
starting initrd/linuxrc...
mounting /dev/mtdblock1 and /dev/sdc1
kjournald starting.  Commit interval 5 seconds
EXT3-fs warning: maximal mount count reached, running e2fsck is recommended
EXT3 FS on sdc1, internal journal
EXT3-fs: recovery complete.
EXT3-fs: mounted filesystem with ordered data mode.
Registering unionfs 2.1.8 (for 2.6.18.8)
unionfs mounted, moving mounts...
#------------ Here switch_root is called ----------------
VFS: Mounted root (squashfs filesystem) readonly.
Trying to move old root to /initrd ... /initrd does not exist. Ignored.
Unmounting old root
VFS: Busy inodes after unmount of sdc1. Self-destruct in 5 seconds.  Have a nice day...
Trying to free ramdisk memory ... okay
Freeing init memory: 116K

When I exchange switch_root by chroot everything works. So the filesystem(s) is OK. Why is the root remounted again?
The commandline is

Code:

rootfstype=squashfs root=/dev/mtdblock1 ro mtdparts=physmap-flash.0:2432k(kernel),12928k(initrd),896k(etc),-(bootbase) console=ttyS0,115200n8 mem=128M init=/linuxrc rootdelay=10 overlay=/dev/sdc3 reloaded

$INIT expands to /linuxrc, which is a symlink to /bin/busybox in the firmware. I tried to change it to a symlink to /etc/init.d/rcS in the rw layer, but that didn't help either.
I have tried it with and without the 'real-root-dev' line. Doesn't change anything.

I have found that the pid of the script has to be 1, in order to execute switch_root. When I drop a shell, I can see that process 1 is [swapper]. Don't know what that is. When I force a different pid for the script, I get n error: 'switch_root: no rootfs', so I suppose [swapper] is the script, somehow.

Offline

 

#2 2009-11-08 13:58:58

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: initrd won't switch_root

I thought maybe the root= parameter must point to the real rootdevice. So i tried to provide it. The mount command says:

Code:

unionfs on /mnt type unionfs (rw,dirs=/mnt-rw=rw:/mnt-ro=ro)

So I added root=unionfs to the commandline:

Code:

Root-NFS: No NFS server available, giving up.
VFS: Unable to mount root fs via NFS, trying floppy.
VFS: Cannot open root device "unionfs" or unknown-block(2,0)
Please append a correct "root=" boot option
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

According to mountpoint the major:minor of this unionfs is 0:12. So I tried /dev/0:12. The same output (except the ´unionfs´ string). I tried without a root= parameter. The same output, only ´unionfs´ is exchanged by '<NULL>'.

Another fuzzy thing I found: reloading of this kernel  only succeeds if I issue a /sbin/reboot. When I switch the box off and on, reloading stops:

Code:

reloaded for DNS-323, 2007 tp@fonz.de
zImage: 1931380 bytes
loaded 131072 of 1931380 bytes at c7ee0000 / 07ee0000
loaded 131072 of 1931380 bytes at c7f40000 / 07f40000
loaded 131072 of 1931380 bytes at c7f80000 / 07f80000
loaded 131072 of 1931380 bytes at c7fc0000 / 07fc0000
loaded 131072 of 1931380 bytes at c7800000 / 07800000
loaded 131072 of 1931380 bytes at c7840000 / 07840000
loaded 131072 of 1931380 bytes at c7880000 / 07880000
loaded 131072 of 1931380 bytes at c78c0000 / 078c0000
loaded 131072 of 1931380 bytes at c7900000 / 07900000
loaded 131072 of 1931380 bytes at c7940000 / 07940000
loaded 131072 of 1931380 bytes at c7980000 / 07980000
loaded 131072 of 1931380 bytes at c79c0000 / 079c0000
loaded 131072 of 1931380 bytes at c7a00000 / 07a00000
loaded 131072 of 1931380 bytes at c7a40000 / 07a40000
loaded 96372 of 1931380 bytes at c7a80000 / 07a80000
zImage: OK (15 segments)
initrd: 610304 bytes
loaded 131072 of 610304 bytes at c7aa0000 / 07aa0000
loaded 131072 of 610304 bytes at c7ae0000 / 07ae0000
loaded 131072 of 610304 bytes at c7b40000 / 07b40000
loaded 131072 of 610304 bytes at c7b60000 / 07b60000
loaded 86016 of 610304 bytes at c7ba0000 / 07ba0000
initrd: OK (5 segments)
dns323_machtype = 859
CMDLINE: mtdparts=physmap-flash.0:2432k(kernel),12928k(initrd),896k(etc),-(bootbase) console=ttyS0,115200n8 mem=128M init=/linuxrc rootdelay=10 unionfs_ro=/dev/mtdblock1 unionfs_rw=/dev/sdc1 RLT
MEM: start 00000000 size 128MB
INITRD: start 00800000 size 610304
dns323_taglist  = 7c2f000 (c7c2f000)
copying 2160 bytes reboot code from bf0c11b8 to c7eba000
dns323_reboot_start  = 7eba000
Reloading...
Uncompressing Linux............................................................................................................................ done, booting the kernel.

Then it just stops. The box doesn't react on the powerbutton, which it does after a kernel panic.
Is there some flag which survives a reboot? When doing a soft reboot, the bootloader is involved, and I cannot see any difference between a hard boot and a soft one.
It seems that this is only a problem with kernels compiled with the codesourcery toolchain, not with the ZyXEL provided montevista toolchain.

Offline

 

#3 2009-11-08 17:36:35

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: initrd won't switch_root

Are you really using an initrd? Or is it an initramfs (cpio archive)? I think you don't need a root= parameter at all. About the switch_root, I think it's common to cd to the new root directory, and use "switch_root . /sbin/init". I also think that you need a populated /dev in the new root tree, so /dev/console can be opened (this may be the reasons you log stops after 'Freeing init...').

Offline

 

#4 2009-11-08 18:27:21

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: initrd won't switch_root

fonz wrote:

Are you really using an initrd? Or is it an initramfs (cpio archive)?

I create it with mksquashfs. Can I also provide a cpio archive to reloaded.ko? Will it automagically be treated as initramfs?

About the switch_root, I think it's common to cd to the new root directory, and use "switch_root . /sbin/init".

Ok, I'll try.

I also think that you need a populated /dev in the new root tree, so /dev/console can be opened (this may be the reasons you log stops after 'Freeing init...').

It doesn't stop there. It boots fine, it only (re)mounts the default root to /dev/mtdblock1.

Edit:

Code:

cd /mnt
exec switch_root . /sbin/init

has the same behaviour as ´exec switch_root /mnt /linuxrc´. After this command the kernel will mount the device given in root=, or panic out when not provided.

Last edited by Mijzelf (2009-11-08 19:04:12)

Offline

 

#5 2009-11-08 21:17:00

fonz
Member / Developer
From: Berlin
Registered: 2007-02-06
Posts: 1716
Website

Re: initrd won't switch_root

Mijzelf wrote:

I create it with mksquashfs. Can I also provide a cpio archive to reloaded.ko? Will it automagically be treated as initramfs?

Yes, of course. I've used an initramfs to boot armedslack ( http://www.inreto.de/dns323/armedslack/ramdisks/ ).
The busybox switch_root has a comment:

If you're _not_ running out of init_ramfs (if for example you're using initrd                                                                         
instead), you probably shouldn't use switch_root because it's the wrong tool.

For initrds, they recommend pivot_root. But I think it's better to use an initramfs.

Offline

 

#6 2009-11-09 14:37:15

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: initrd won't switch_root

Thanks, using an initramfs works. Pure magic. I think I'll have to do some reading about the difference of initrd and initramfs.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB