
Code: Select all
#!/bin/busybox sh
rescue_shell() {
echo $1
busybox --install -s
exec /bin/sh
}
# Mount the /proc and /sys filesystems.
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys
# Assemble RAID:
( sleep 2
mdadm --assemble --scan
sleep 2
) &
wait
# Mount the root filesystem.
mount -o ro `findfs LABEL=gentoo` || rescue_shell "Problem mounting root. Dropping to shell"
# Clean up.
umount /proc
umount /sys
umount /dev
# Boot the real thing.
exec switch_root /mnt/root /sbin/init

Code: Select all
# Mount the /proc and /sys filesystems.
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys Code: Select all
|| rescue_shell "Problem mounting root. Dropping to shell" Code: Select all
#!/bin/busybox sh
rescue_shell() {
echo "$@"
echo "Something went wrong. Dropping you to a shell."
# have time to read the message
/bin/sleep 20
/bin/busybox --install -s
exec /bin/sh
}Code: Select all
#echo "/bin"
#/bin/ls -l /bin
#echo "/sbin"
#/bin/ls -l /sbin
#/bin/sleep 20
#echo "Mount proc"
/bin/mount -t proc proc /proc
#/bin/busybox sleep 20Code: Select all
#!/bin/busybox sh
# Create applets
/bin/busybox --install -s
pause() {
read -p "$*"
}
rescue_shell() {
/bin/echo $1
/bin/busybox --install -s
exec /bin/sh
}
# Mount the /proc and /sys filesystems.
/bin/mount -t devtmpfs none /dev
/bin/mount -t proc none /proc
/bin/mount -t sysfs none /sys
#echo /sbin/mdev > /proc/sys/kernel/hotplug
#mdev -s
# Assemble RAID:
( sleep 2
/sbin/mdadm --assemble --scan
sleep 2
) &
wait
pause "raid array just assembled. Press Enter to continue"
# Mount the root filesystem.
/bin/mount -o ro `findfs LABEL=gentoo` || rescue_shell "Problem mounting root. Dropping to shell"
# Clean up.
/bin/umount /proc
/bin/umount /sys
/bin/umount /dev
# Boot the real thing.
exec /sbin/switch_root /mnt/root /sbin/init


Code: Select all
/bin/mount -o ro `findfs LABEL=gentoo` || rescue_shell "Problem mounting root. Dropping to shell"
Code: Select all
mount -o ro $(findfs "$dev") /mnt/root >>/tmp/initrdlog 2>&1
juggling_ben wrote:Few things:
Can you post a ls -la from inside your init directory structure? Your image shows an error code of -40 when running init, which according to my reading of the kernel code, means it can't determine the binary format of /init
Also, in your listing of your initramfs, you seem to be missing any .so files. Are you compiling the tools with the 'static' use flag? Particularly busybox.
I'd be happy to share by init script and my little build script if you'd like. It's only slightly more complicated than yours (after assembling the raid, I have to decrypt, do lvm stuff, etc) but hasn't failed me in quite some time.
Code: Select all
total 56K
drwxr-xr-x 13 root root 4.0K Feb 10 16:01 .
drwxr-xr-x 11 root root 4.0K Feb 20 10:14 ..
drwxr-xr-x 2 root root 4.0K Feb 8 16:32 bin
drwxr-xr-x 2 root root 4.0K Feb 9 14:16 dev
drwxr-xr-x 2 root root 4.0K Feb 9 13:56 etc
drwxr-xr-x 2 root root 4.0K Feb 8 16:27 lib
drwxr-xr-x 2 root root 4.0K Feb 8 16:27 lib64
drwxr-xr-x 3 root root 4.0K Feb 8 16:27 mnt
drwxr-xr-x 2 root root 4.0K Feb 8 16:27 proc
drwxr-xr-x 2 root root 4.0K Feb 8 16:27 root
drwxr-xr-x 2 root root 4.0K Feb 9 14:15 sbin
drwxr-xr-x 2 root root 4.0K Feb 8 16:27 sys
drwxr-xr-x 4 root root 4.0K Feb 10 16:01 usr
-rwxr-xr-x 1 root root 786 Feb 22 18:03 initCode: Select all
* Found these USE flags for sys-apps/busybox-1.23.1-r1:
U I
- - debug : Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see http://www.gentoo.org/proj/en/qa/backtraces.xml
+ + ipv6 : Add support for IP version 6
- - livecd : !!internal use only!! DO NOT SET THIS FLAG YOURSELF!, used during livecd building
- - make-symlinks : Create all the appropriate symlinks in /bin and /sbin.
- - math : Enable math support in gawk (requires libm)
- - mdev : Create the appropriate symlink in /sbin and install mdev.conf and support files
+ + pam : Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip
- - savedconfig : Use this to restore your config from /etc/portage/savedconfig ${CATEGORY}/${PN}. Make sure your USE flags allow for appropriate dependencies
- - sep-usr : Support a separate /usr without needing an initramfs by booting with init=/ginit
+ + static : Make the system rescue shell (/bin/bb) static so you can recover even when glibc is broken
- - syslog : Enable support for syslog
+ + systemd : Support systemd
Code: Select all
* Found these USE flags for sys-fs/mdadm-3.3.2:
U I
+ + static : !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically
Code: Select all
for f in $(find -type l); do ls -l $f; done;
Code: Select all
s0be@anvil /usr/src/initramfs $ for f in $(find -type l); do ls -l $f; done;
lrwxrwxrwx 1 s0be s0be 3 Oct 11 2012 ./sbin -> bin
lrwxrwxrwx 1 s0be s0be 8 Oct 11 2012 ./usr/sbin -> ../sbin/
lrwxrwxrwx 1 s0be s0be 6 Oct 11 2012 ./usr/bin -> ../bin

7 blocks? That does not sound right to me. If I only include statically-linked busybox in my own, it is > 5000 blocks. What is bin/busybox in your initramfs? (ie what does "file bin/busybox" say?) If you copied a symlink or something instead, it would fit with my earlier confusion about the 'error -40'triquetra wrote:Following is what my init script currently looks like, though this is one of a couple dozen different permutations I have tried.
[code="su -p -c "find . -print0 | cpio --null -ov --format=newc | gzip -9 > /boot/initramfs-custom-3.18.2-gentoo""]
.
./bin
./bin/busybox
./lib64
./dev
./dev/null
./dev/tty
./dev/console
./dev/md126p5
./root
./proc
./mnt
./mnt/root
./sbin
./sbin/mdadm
./lib
./init
./etc
./etc/mdadm.conf
./sys
7 blocks
[/code]
That makes a lot of sense, I bet $INITRDPATH/bin/busybox is a symlink to /bin/busybox. That'd lead the the error -40 (ELOOP) as it'd end up being a symlink to itself, and it would give him the tiny initrd rather than one of appreciable size.juggling_ben wrote:So thinking about this a bit, the problem isn't related to your init script. Your boot process isn't getting that far.
7 blocks? That does not sound right to me. If I only include statically-linked busybox in my own, it is > 5000 blocks. What is bin/busybox in your initramfs? (ie what does "file bin/busybox" say?) If you copied a symlink or something instead, it would fit with my earlier confusion about the 'error -40'triquetra wrote:Following is what my init script currently looks like, though this is one of a couple dozen different permutations I have tried.
[code="su -p -c "find . -print0 | cpio --null -ov --format=newc | gzip -9 > /boot/initramfs-custom-3.18.2-gentoo""]
.
./bin
./bin/busybox
./lib64
./dev
./dev/null
./dev/tty
./dev/console
./dev/md126p5
./root
./proc
./mnt
./mnt/root
./sbin
./sbin/mdadm
./lib
./init
./etc
./etc/mdadm.conf
./sys
7 blocks
[/code]

When it comes to initramfs, etc, making changes as rarely as possible is better, IMHO. You don't always want the 'latest and greatest' versions in it, because they change behaviors and whatnot, and pre-init is a very delicate time. I haven't upgraded the busybox in my initramfs since May 14, 2012. If it works, don't replace ittriquetra wrote:Yes, that was it. Thanks for the help debugging this issue. I thought I would be clever and symlink the files needed for the initramfs so that I was sure to always have the current version. Obviously, that did not work. Would hard links accomplish that goal, or is it better to just use a mkinitramfs script to build the initramfs files and directory structure each time I rebuild the initramfs?
Code: Select all
diff --git a/usr/Makefile b/usr/Makefile
index e767f01..041333b 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -60,15 +60,7 @@ targets := initramfs_data.cpio.gz initramfs_data.cpio.bz2 \
initramfs_data.cpio.lzma initramfs_data.cpio.xz \
initramfs_data.cpio.lzo initramfs_data.cpio.lz4 \
initramfs_data.cpio
-# do not try to update files included in initramfs
-$(deps_initramfs): ;
-
-$(deps_initramfs): klibcdirs
-# We rebuild initramfs_data.cpio if:
-# 1) Any included file is newer then initramfs_data.cpio
-# 2) There are changes in which files are included (added or deleted)
-# 3) If gen_init_cpio are newer than initramfs_data.cpio
-# 4) arguments to gen_initramfs.sh changes
-$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio $(deps_initramfs) klibcdirs
+
+$(obj)/initramfs_data.cpio$(suffix_y): $(obj)/gen_init_cpio
$(Q)$(initramfs) -l $(ramfs-input) > $(obj)/.initramfs_data.cpio.d
$(call if_changed,initfs)
Code: Select all
usr/Makefile:64: *** target pattern contains no '%'. Stop.
Makefile:964: recipe for target 'usr' failed
make: *** [usr] Error 2