Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
initrd problem
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
traggart
n00b
n00b


Joined: 31 Mar 2005
Posts: 72

PostPosted: Wed Sep 10, 2008 10:02 am    Post subject: initrd problem Reply with quote

hi all,
i've built an initrd (i need to have some modules before starting init) with mkinitrd but i have a problem at boot time: the kernel panics. :?

It panics when trying to "pivot_root", then since my root partition is on /dev/hda1 i've changed the linuxrc (it's inside the initrd) in this way:

Code:

....
echo Mounting /proc filesystem
mount -t proc /proc /proc
echo Creating block devices
mkdevices /dev
echo Creating root device
echo 0x0100 > /proc/sys/kernel/real-root-dev
echo Mounting root filesystem
mount -o noatime --ro -t ext3 /dev/hda1 /
pivot_root / /old
umount /old/proc


i've changed
mount -o noatime --ro -t ext3 /dev/root /sysroot
with
mount -o noatime --ro -t ext3 /dev/hda1 /
and now it works! i can boot and i can work with my gentoo! 8)


But i still get at boot time:
Code:

EXT3-fs: mounted filesystem with ordered data mode.
pivotroot: pivot_root(/,/old) failed: 2
umount /old/proc failed: 2


is't not a big problem (or maybe it is?), and if i try to cat /proc/mounts i get:
Code:

# cat /proc/mounts
/dev/root.old /old ext2 rw 0 0
/proc /old/proc proc rw 0 0

and when i shut down the server it says it can't find /old and /old/proc
then it can't umount it and want me to insert root password for mainteinance(annoying! :x )


as you can see i changed these two line in linuxrc
Code:

pivot_root / /old
umount /old/proc

according to what /proc/mounts shows(just to try, i'dont know really what i am doing :twisted: ), since the original code does not work either!
Code:

pivot_root /sysroot /sysroot/initrd
umount /initrd



according to man pages of nash basic shell
Code:

pivot_root newrootpath oldrootpath
              Makes  the filesystem mounted at newrootpath the new root filesystem, and mounts the current root filesystem as oldroot-
              path.

which means i should mount /dev/hda1 somewhere(and i tried the /sysroot directory without success), then "pivotroot somewhere oldrootpath" but i actually don't know where "oldrootpath" is!!!
And i can't find it with the basic "find" command built-in in nash shell. :?

any idea on how to pivot_root in the right way?

thank you in advance,
Back to top
View user's profile Send private message
gringo
Advocate
Advocate


Joined: 27 Apr 2003
Posts: 3793

PostPosted: Wed Sep 10, 2008 11:32 am    Post subject: Reply with quote

i dont have much idea about pivot_root() but oldrootpath should be the one specified by root= in your loader, right ? You mention you are using initrd, i guess you are using ramdisk so maybe ram0 or whatever you are using to store your initrd.

hope this helps.

cheers
_________________
Error: Failing not supported by current locale
Back to top
View user's profile Send private message
traggart
n00b
n00b


Joined: 31 Mar 2005
Posts: 72

PostPosted: Wed Sep 10, 2008 12:30 pm    Post subject: Reply with quote

gringo wrote:
i dont have much idea about pivot_root() but oldrootpath should be the one specified by root= in your loader, right ? You mention you are using initrd, i guess you are using ramdisk so maybe ram0 or whatever you are using to store your initrd.


I believe that oldrootpath is the path where initrd is mounted.
with linuxrc you mount the real root partition somewhere and you pivot the oldrootpath into the real root partition (in this case /dev/hda1).

I don't know if i am using ram0, i cannot find info about how end where the initrd is mounted.

Maybe if i understand where it is mounted, i will be able to pivot the root partition from the fake root which mounts initrd to the real /dev/hda1.
Back to top
View user's profile Send private message
gringo
Advocate
Advocate


Joined: 27 Apr 2003
Posts: 3793

PostPosted: Wed Sep 10, 2008 3:22 pm    Post subject: Reply with quote

Quote:
I believe that oldrootpath is the path where initrd is mounted


probably, yes, that´s why i said you should have a look to how your bootloader configuration, specially the root= switch is probably what you are looking for to know where the first root device is.

cheers
_________________
Error: Failing not supported by current locale
Back to top
View user's profile Send private message
mirekm
Apprentice
Apprentice


Joined: 12 Feb 2004
Posts: 210
Location: Gliwice

PostPosted: Wed Sep 10, 2008 6:41 pm    Post subject: Reply with quote

Could you show your init file, and directory listing of your initrd file?
Back to top
View user's profile Send private message
traggart
n00b
n00b


Joined: 31 Mar 2005
Posts: 72

PostPosted: Mon Sep 15, 2008 8:13 am    Post subject: Reply with quote

original linuxrc file:
Code:

#!/bin/nash

[cut modules loading]

echo Mounting /proc filesystem
mount -t proc /proc /proc
echo Creating block devices
mkdevices /dev
echo Creating root device
mkrootdev /dev/root
echo 0x0100 > /proc/sys/kernel/real-root-dev
echo Mounting root filesystem
mount -o noatime --ro -t ext3 /dev/root /sysroot
pivot_root /sysroot /sysroot/initrd
umount /initrd/proc



linuxrc made by me:
Code:

#!/bin/nash

[cut modules loading]

echo Mounting /proc filesystem
mount -t proc /proc /proc
echo Creating block devices
mkdevices /dev
echo Creating root device
echo 0x0100 > /proc/sys/kernel/real-root-dev
echo Mounting root filesystem
mount -o noatime --ro -t ext3 /dev/hda1 /
pivot_root / /old
umount /old/proc




directory listing:
Code:

./linuxrc
./lib
./lib/xen-balloon.ko
./lib/xen-platform-pci.ko
./lib/xen-vnif.ko
./lib/xen-vbd.ko
./sbin
./etc
./sysroot
./bin
./bin/nash
./bin/modprobe
./bin/insmod
./proc
./dev
./dev/null
./dev/console
./dev/tty4
./dev/systty
./dev/tty3
./dev/tty2
./dev/ram
./dev/tty1
./loopfs
Back to top
View user's profile Send private message
traggart
n00b
n00b


Joined: 31 Mar 2005
Posts: 72

PostPosted: Wed Sep 17, 2008 8:54 am    Post subject: Reply with quote

it's two days i am trying to get some result, but i can't find sufficient documentation.
Furthermore it seems that avery distro is using a different way/program to make an initrd, and this fact is confusing me!

Any idea is wellcome!

cheers
Back to top
View user's profile Send private message
DtZ
Tux's lil' helper
Tux's lil' helper


Joined: 09 Sep 2005
Posts: 124

PostPosted: Wed Sep 17, 2008 1:02 pm    Post subject: Reply with quote

I also need to loads some modules before starting init on one of my systems. I use initramfs and switch_root instead of pivot_root. My init script looks like this:
Code:
# mount proc and sysfs
mount -t proc none /proc
mount -t sysfs none /sys

# mount root in read only mode
mount -t ext3 /dev/sda6 /newroot -o noatime,ro

...
#load all the modules I need
...

umount /proc
umount /sys
clear
exec /sbin/switch_root /newroot /sbin/init

I hope this helps.
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Wed Sep 17, 2008 1:14 pm    Post subject: Reply with quote

traggart wrote:
Code:
mount -o noatime --ro -t ext3 /dev/hda1 /
pivot_root / /old


You're mounting something in /, thus replacing / already - which is what pivot_root really should be doing in a cleaner fashion.
pivot_root then fails because there is nothing mounted in /old it could pivot with.

Usually in init/linuxrc, you mount the root partition to /somedir (like /newroot or /whatever), and then pivot_root / switch_root it so the old root (initial ramdisk /) can be moved / freed.

I made my initrd/initramfs manually, that's the only way to understand what is actually happening... here you can see my example:
http://www.gentoo-wiki.com/Booting_encrypted_system_from_USB_stick#Building_the_initramfs

It really pays off to read the busybox help pages on pivot_root and switch_root too, so you can understand what they do.
Back to top
View user's profile Send private message
traggart
n00b
n00b


Joined: 31 Mar 2005
Posts: 72

PostPosted: Wed Sep 17, 2008 5:07 pm    Post subject: Reply with quote

DtZ wrote:
I also need to loads some modules before starting init on one of my systems. I use initramfs and switch_root instead of pivot_root. My init script looks like this:
Code:
# mount proc and sysfs
mount -t proc none /proc
mount -t sysfs none /sys

# mount root in read only mode
mount -t ext3 /dev/sda6 /newroot -o noatime,ro

...
#load all the modules I need
...

umount /proc
umount /sys
clear
exec /sbin/switch_root /newroot /sbin/init

I hope this helps.


I saw swtih_root in redhat like distro, but if i do a "man nash" i can't find it on gentoo.

the syntax of pivot_root is "pivot_root newrootpath oldrootpath"
...but the syntax of swith_root? (if gentoo's nash supports it)
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Wed Sep 17, 2008 5:16 pm    Post subject: Reply with quote

What's nash? 8O

You're using busybox, right?

Code:

$ busybox switch_root --help
BusyBox v1.12.0 (2008-08-22 13:32:21 CEST) multi-call binary

Usage: switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]

Use from PID 1 under initramfs to free initramfs, chroot to NEW_ROOT,
and exec NEW_INIT

Options:
   -c   Redirect console to device on new root
Back to top
View user's profile Send private message
x22
Apprentice
Apprentice


Joined: 24 Apr 2006
Posts: 208

PostPosted: Thu Sep 18, 2008 9:20 am    Post subject: Reply with quote

Documentation is in (kernel source)/Documentation/initrd.txt and Documentation/filesystems/ramfs-rootfs-initramfs.txt.

Nash is a simple script interpreter with some built-in commands which can be used in initrd. It is something like busybox but simpler.
Nash has switchroot, too, see man nash.
Back to top
View user's profile Send private message
traggart
n00b
n00b


Joined: 31 Mar 2005
Posts: 72

PostPosted: Thu Sep 18, 2008 9:26 am    Post subject: Reply with quote

busybox?
theres no busybox in the initrd, just nash, a little shell.

the beginning og the file "linuxrc" is indeed
#!/bin/nash
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2977
Location: Germany

PostPosted: Thu Sep 18, 2008 10:24 am    Post subject: Reply with quote

Code:

user@gentoo ~ $ nash
bash: nash: command not found
user@gentoo ~ $ which nash
which: no nash in (/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.3.1:/usr/qt/3/bin:/usr/games/bin)
user@gentoo ~ $ eix nash
* net-www/gnash
     Available versions:  (~)0.8.1-r1 (~)0.8.3 **9999 {agg cairo dbus fbcon ffmpeg gstreamer gtk kde mad nsplugin opengl qt3 sdl test video_cards_i810}
     Homepage:            http://www.gnu.org/software/gnash
     Description:         Gnash is a GNU Flash movie player that supports many SWF v7 features


nash doesn't exist on my radar. where does it come from? 8O

x22 wrote:
It is something like busybox but simpler.


There isn't anything simpler than busybox in Gentoo... you don't have to build it yourself, you can just use the binary provided by the Gentoo sys-apps/busybox ebuild (set static useflag for it in package.use). And it comes with everything you need in an initrd/initramfs and even offers help for the various commands (see 'busybox' for a list of commands and 'busybox command --help' for help for these commands - perhaps nash works the same way as busybox does not come with a manpage either).

With busybox (and cryptsetup and lvm), it took me only 10 shell commands, and a 10 line script, to build an initramfs that boots USB, unlocks a LUKS encrypted hard disk, initializes LVM, mounts, switches root, and boots the encrypted Gentoo box (see the example I linked above). If that isn't simple I really don't know what is. :?
Back to top
View user's profile Send private message
DtZ
Tux's lil' helper
Tux's lil' helper


Joined: 09 Sep 2005
Posts: 124

PostPosted: Thu Sep 18, 2008 11:58 am    Post subject: Reply with quote

Quote:
theres no busybox in the initrd, just nash, a little shell.

Busybox is more than just a shell. It's a swiss army knife for embedded systems. It's ideal for initramfs/initrd because it contains all utilities you might need (shell, module utilities, awk, grep, sed etc.). It's also highly configurable.

You can easily compile your own busybox binary by using ebuild provided by portage. There's also a tool called buildroot which can build an entire system based on uClibc and busybox.
Back to top
View user's profile Send private message
x22
Apprentice
Apprentice


Joined: 24 Apr 2006
Posts: 208

PostPosted: Thu Sep 18, 2008 2:58 pm    Post subject: Reply with quote

Nash is part of sys-apps/mkinitrd. It has mush less features than Busybox.

(I don't use nash or Busybox in my initrd, I use (parts of) glibc, bash, coreutils, util-linux, LVM, run-init from klibc and all required libraries.)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software 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