View previous topic :: View next topic |
Author |
Message |
giessie n00b
Joined: 10 Mar 2005 Posts: 66
|
Posted: Tue May 15, 2007 8:28 am Post subject: [SOLVED] Problem with initramfs |
|
|
Hi,
I installed gentoo on my notebook hd with luks-encryptet root. For booting, I created an initrd to mount the rootfs.
Later this installation is to be copied to a usb harddisk. Because I don't know of a way to make sure that my usbhd gets a certain device node, I wanted to use blkid from e2fsprogs to find the right partition by UUID, but in the initrd blkid doesn't work (even though compiled with USE="static"). It just says "File not found". I would be really happy for a hint on what I am doing wrong.
Here is the /init I use in the initrd. I took It from a livecd and modified it heavily.
Code: |
#!/bin/sh
# user defined variables
uv_init=/sbin/init # init to execute after switching to real root
gv_keymap="de"
die()
{
local lv_msg="$1"
umount -n /mnt 2>/dev/null
echo "${lv_msg}"
echo
echo "Dropping you into a minimal shell..."
exec /bin/sh
}
main() {
export PATH=/sbin:/bin
umask 0077
[ ! -d /proc ] && mkdir /proc
/bin/mount -t proc proc /proc
# /bin/busybox --install -s
[ ! -d /tmp ] && mkdir /tmp
[ ! -d /mnt ] && mkdir /mnt
[ ! -d /new-root ] && mkdir /new-root
/bin/mount -t sysfs sysfs /sys
# populate /dev from /sys
/bin/mount -t tmpfs tmpfs /dev
/sbin/mdev -s
# handle hotplug events
echo /sbin/mdev > /proc/sys/kernel/hotplug
# fix: /dev/device-mapper should be /dev/mapper/control
# otherwise it fails on my amd64 system(busybox v1.2.1), weird that it works
# on my laptop(i686, /dev/mapper/control gets created on luksOpen).
if [ ! -e "/dev/mapper/control" ]; then
# see: /proc/misc, /sys/class/misc/device-mapper/dev
mkdir /dev/mapper && mv /dev/device-mapper /dev/mapper/control
echo "device-mapper mapper/control issue fixed.."
fi
# load kmap and font
if [ -n "${gv_kmap}" ]; then
if [ -e "/etc/${gv_kmap}" ]; then
loadkmap < "/etc/${gv_kmap}"
else
die "Error: keymap ${gv_kmap} does not exist on /etc"
fi
if [ -n "${gv_font}" ]; then
if [ -e "/etc/${gv_font}" ]; then
loadfont < "/etc/${gv_font}"
else
die "Error: font ${gv_font} does not exist on /etc"
fi
fi
fi
# pretty sure the only disk with this UUID is the one we want
BOOTDEVICE=`blkid -l -o device -t UUID="deadbeaf-2007-0514-1800-de0123456789"`
# but our root is on partition 5 and not 1
ROOTDEVICE=`echo ${BOOTDEVICE} | awk '{sub(/1$/,"5");print}'`
cryptsetup isLuks "${ROOTDEVICE}" 2>/dev/null || die "Error: ${ROOTDEVICE} is not a luks partition"
cryptsetup luksOpen "${ROOTDEVICE}" root
if [ "$?" -ne 0 ]; then
die "Error: failed to luksOpen ${ROOTDEVICE}."
fi
mount /dev/mapper/root /new-root
# Unmount everything and switch root filesystems for good:
# exec the real init and begin the real boot process.
echo > /proc/sys/kernel/hotplug
/bin/umount -l /proc
/bin/umount -l /sys
/bin/umount -l /dev
exec switch_root /new-root "${uv_init}"
}
main
|
Last edited by giessie on Wed May 16, 2007 7:55 am; edited 1 time in total |
|
Back to top |
|
|
giessie n00b
Joined: 10 Mar 2005 Posts: 66
|
Posted: Wed May 16, 2007 5:50 am Post subject: |
|
|
I partly solved the problem.
Basicly, compiling e2fsprogs with USE="static" does NOT link the binaries statically.
I worked around this by first compiling ss statically by hand (not with ebuild), copying the libs over to the e2fsprogs source and doing the same there.
Finding my root works now. |
|
Back to top |
|
|
blh n00b
Joined: 13 Nov 2006 Posts: 10
|
Posted: Wed Jul 04, 2007 10:10 pm Post subject: Re: [SOLVED] Problem with initramfs |
|
|
Hi,
I've spent more then 10 hours on building the initrd and still not been able to solve one issue. Everything works up to this part:
Code: |
exec switch_root /new-root "${uv_init}"
|
switch_root returns a usage line like:
Code: |
/dev/hda2: not rootfs
|
When trying:
Code: |
CMDLINE=`cat /proc/cmdline`
exec chroot /new-root /sbin/init $(CMDLINE)
|
init returns:
Code: |
Usage: init 0123456789..and so on
|
Any suggestions? I just can't make it work using any examples and solutions found on this forum.
Using gentoo 2007.0 with linux 2.6.21-r3 |
|
Back to top |
|
|
boris64 Veteran
Joined: 04 Oct 2003 Posts: 1770 Location: Vechelde/Peine
|
Posted: Sat Jul 07, 2007 3:07 pm Post subject: Re: [SOLVED] Problem with initramfs |
|
|
Quote: | switch_root returns a usage line like:
Code: | /dev/hda2: not rootfs |
|
Are you actually in /newroot?
If not, try to change dir first
before your switch_root command.
This works for me.
Btw., i'm using busybox in my initramfs, dunno about
klibc or whatever you might be using.
hth
[Edit]Whooops, didn't read your "Solved" in this treads title,
this post will be useless then :7[/Edit] _________________ boris64.net 200x / visit my desktop / try these tiny kernel patches |
|
Back to top |
|
|
blh n00b
Joined: 13 Nov 2006 Posts: 10
|
Posted: Sat Jul 07, 2007 6:19 pm Post subject: |
|
|
Same here. I'm using busybox. I tried your suggestion and change directory still i get:
Code: |
switch_root: not rootfs
|
Could you please post your linuxrc or PM?
blh |
|
Back to top |
|
|
boris64 Veteran
Joined: 04 Oct 2003 Posts: 1770 Location: Vechelde/Peine
|
Posted: Sat Jul 07, 2007 6:47 pm Post subject: |
|
|
If you're using busybox:
"/linuxrc" needs to be a file(!!!!), not a symlink,
which it normally is when using busybox's "make install".
You could for example a create a file named "/linuxrc" or "/init", which
contains something like this:
Code: |
#!/bin/sh
## Symlink does not work, /init:
## 1) must exist
## 2) must be a regular file
exec /bin/busybox
## or something like "exec /etc/rc.init" ;)
|
_________________ boris64.net 200x / visit my desktop / try these tiny kernel patches |
|
Back to top |
|
|
blh n00b
Joined: 13 Nov 2006 Posts: 10
|
Posted: Sat Jul 07, 2007 7:11 pm Post subject: |
|
|
Indeed file. I did remove the symlink created by busybox.
I partly solved the problem using this code:
Code: |
mount -t proc proc /proc
cryptsetup luksOpen /dev/hda2 root
mount /dev/mapper/root /new
cd /new
exec chroot . /bin/sh <<- EOF >/dev/console 2>&1
umount initrd # ERROR: Device or resource busy
rm -rf initrd # ERROR: Device or resource busy
blockdev --flushbufs /dev/ram0 # ERROR: Device or resource busy
exec /sbin/init -i
EOF
|
However, the unmount was unsuccessful due to "initrd" was busy. No idea why.
When init then started udev and tried to mount my /dev/mapper/root, it said it wasnt a ext3-fs and stopped. I went into shell and verified. The mapper seem to have stopped for some reason.
Can you bring any light to it? |
|
Back to top |
|
|
|