Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Kernel & Hardware
  • Search

[Solved] System not booting with custom initramfs

Kernel not recognizing your hardware? Problems with power management or PCMCIA? What hardware is compatible with Gentoo? See here. (Only for kernels supported by Gentoo.)
Post Reply
Advanced search
14 posts • Page 1 of 1
Author
Message
heliostic
n00b
n00b
Posts: 13
Joined: Mon Nov 28, 2022 8:05 am

[Solved] System not booting with custom initramfs

  • Quote

Post by heliostic » Sun Dec 18, 2022 4:28 pm

I have been trying to boot my system with a custom initramfs that is basically the busybox binary and the below init script based on some guides on the gentoo wiki.

Booting the compressed cpio archive will give a kernel panic along the lines of "not syncing: no working init found" seemingly refering to the init of the base system.
Booting with the initramfs embedded onto the kernel will give a more generic "not syncing".

I have also tried to insert a rescue_shell command after the mounting of the root partition which has no effect implying that the init script does not get read.

Booting with ramdisk generated by genkernel works although using the ones generated with dracut does not.

initramfs/init

Code: Select all

#!/bin/busybox sh

/bin/busybox --install -s

rescue_shell() {
    echo "$@"
    echo "Something went wrong. Dropping you to a shell."
    # The symlinks are not required any longer
    # but it helps tab completion
    # /bin/busybox --install -s
    exec /bin/busybox sh
}

# mount
mount -t proc none /proc
mount -t devtmpfs none /dev
mount -t sysfs none /sys

# mount root partition by UUID
mount -o ro UUID=1884e3b9-09f7-4c06-9fe3-3c0f84c3acd5 /mnt/root 

# unmount
umount /proc
umount /dev
umount /sys

exec /sbin/switch_root /mnt/root /sbin/init
Last edited by heliostic on Mon Dec 19, 2022 5:41 pm, edited 1 time in total.
Top
pingtoo
Advocate
Advocate
User avatar
Posts: 2180
Joined: Fri Sep 10, 2021 8:37 pm
Location: Richmond Hill, Canada

  • Quote

Post by pingtoo » Sun Dec 18, 2022 4:56 pm

May be the /init inside the initramfs have wrong permission, so it cannot execute.

You can try to change your kernel command line argument. Add 'rdinit=/bin/sh' may help you debug. However this depend on your initramfs cpio archive have /bin/sh, symbolic link to /bin/busybox or standalone binary. I am not sure if 'rdinit=/bin/busybox sh' will work or not, never try that before.
Top
Hu
Administrator
Administrator
Posts: 24385
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Sun Dec 18, 2022 5:14 pm

Please describe your build process in enough detail that we can replicate it. When you create the compressed cpio archive, from what directory do you run it and with what options? What is the output of cpio -tv when given your archive as input?

When you embedded the initramfs into the kernel, how did you do that?
Last edited by Hu on Sun Dec 18, 2022 5:14 pm, edited 1 time in total.
Top
heliostic
n00b
n00b
Posts: 13
Joined: Mon Nov 28, 2022 8:05 am

  • Quote

Post by heliostic » Sun Dec 18, 2022 5:35 pm

Hu,

I cd into /usr/src/initramfs, which the source directory of my initramfs.
There I run

Code: Select all

find . -depth -print0 | cpio -ocv0 > ../custom-initramfs.cpio
to generate the cpio archive and copy the resulting file to /boot.

Usually the file is so small that I don't compress it, but I have tried that as well.

I embedded the initramfs into the kernel by passing the location of the cpio archive into the 'initramfs source file(s)' (CONFIG_INITRAMFS_SOURCE) option in menuconfig.

Running

Code: Select all

cpio -tv custom-initramfs.cpio
seems to be taking a very long time and I couldn't get any output yet.

For clarity, ls * in /usr/src/initramfs gives

Code: Select all

init

bin:
busybox

dev:
console  null  sda2  tty  tty0

etc:

lib:

lib64:

mnt:
root

proc:

root:

sbin:

sys:
Top
heliostic
n00b
n00b
Posts: 13
Joined: Mon Nov 28, 2022 8:05 am

  • Quote

Post by heliostic » Sun Dec 18, 2022 5:36 pm

pingtoo,

The /init file has permissions for all users to execute so it should be fine.

I'll make the busybox symlinks and try to boot with 'rdinit/bin/sh'.
Top
heliostic
n00b
n00b
Posts: 13
Joined: Mon Nov 28, 2022 8:05 am

  • Quote

Post by heliostic » Sun Dec 18, 2022 5:40 pm

Continuing from my previous message,

I used the cpio command incorrectly.
Here's the output of

Code: Select all

cpio -tvI custom-initramfs.cpio
-rwxr-xr-x   1 root     root          534 Dec 18 18:17 init
-rwxr-xr-x   1 root     root       109128 Dec  3 16:14 bin/busybox
drwxr-xr-x   2 root     root            0 Dec  3 16:14 bin
drwxr-xr-x   2 root     root            0 Dec  3 16:04 sbin
drwxr-xr-x   2 root     root            0 Dec  3 14:35 lib
drwxr-xr-x   2 root     root            0 Dec  3 14:35 proc
drwxr-xr-x   2 root     root            0 Dec  3 16:01 lib64
drwxr-xr-x   2 root     root            0 Dec  3 14:35 sys
drwxr-xr-x   2 root     root            0 Dec  3 14:35 root
drwxr-xr-x   2 root     root            0 Dec  3 14:35 etc
drwxr-xr-x   2 root     root            0 Dec  3 14:29 mnt/root
drwxr-xr-x   3 root     root            0 Dec  3 14:29 mnt
crw-rw-rw-   1 root     root       1,   3 Dec  2 21:09 dev/null
brw-rw----   1 root     994        8,   2 Dec  2 21:09 dev/sda2
crw--w--w-   1 root     root       5,   1 Dec 12 18:26 dev/console
crw--w--w-   1 root     root       4,   0 Dec 12 18:26 dev/tty0
crw-rw-rw-   1 root     tty        5,   0 Dec  2 21:09 dev/tty
drwxr-xr-x   2 root     root            0 Dec 12 18:26 dev
drwxr-xr-x  12 root     root            0 Dec 18 19:16 .
218 blocks
Top
pietinger
Moderator
Moderator
Posts: 6620
Joined: Tue Oct 17, 2006 5:11 pm
Location: Bavaria

  • Quote

Post by pietinger » Sun Dec 18, 2022 7:43 pm

heliostic,

have you emerged busybox with ...

Code: Select all

# USE="-pam static static-libs" emerge -vD busybox
?

Also your last line could be wrong: If you dont have installed /sbin/switch_root into your initramfs you must use the internal switch_root (of busybox).

(=> exec switch_root /mnt/root /sbin/init)

See for example here: https://wiki.gentoo.org/wiki/Early_Userspace_Mounting
Top
Hu
Administrator
Administrator
Posts: 24385
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Sun Dec 18, 2022 10:05 pm

heliostic wrote:I cd into /usr/src/initramfs, which the source directory of my initramfs.
Why? The kernel's built-in initramfs generator can do a better job and can pull files straight from the live filesystem.
heliostic wrote:There I run

Code: Select all

find . -depth -print0 | cpio -ocv0 > ../custom-initramfs.cpio
to generate the cpio archive and copy the resulting file to /boot.
This looks wrong. Per the documentation:

Code: Select all

   The cpio man page contains some bad advice that will break your initramfs
   archive if you follow it.  It says "A typical way to generate the list
   of filenames is with the find command; you should give find the -depth
   option to minimize problems with permissions on directories that are
   unwritable or not searchable."  Don't do this when creating
   initramfs.cpio.gz images, it won't work.  The Linux kernel cpio extractor
   won't create files in a directory that doesn't exist, so the directory
   entries must go before the files that go in those directories.
According to that, I believe this output indicates an archive that is guaranteed to fail:
heliostic wrote:Here's the output of

Code: Select all

cpio -tvI custom-initramfs.cpio
-rwxr-xr-x   1 root     root       109128 Dec  3 16:14 bin/busybox
drwxr-xr-x   2 root     root            0 Dec  3 16:14 bin
drwxr-xr-x   2 root     root            0 Dec  3 14:29 mnt/root
drwxr-xr-x   3 root     root            0 Dec  3 14:29 mnt
crw-rw-rw-   1 root     root       1,   3 Dec  2 21:09 dev/null
brw-rw----   1 root     994        8,   2 Dec  2 21:09 dev/sda2
crw--w--w-   1 root     root       5,   1 Dec 12 18:26 dev/console
crw--w--w-   1 root     root       4,   0 Dec 12 18:26 dev/tty0
crw-rw-rw-   1 root     tty        5,   0 Dec  2 21:09 dev/tty
drwxr-xr-x   2 root     root            0 Dec 12 18:26 dev
I expect that all the shown inner objects will be ignored by the kernel's extractor, leaving you with no bin/busybox, no mnt/root on which to mount, and no nodes in dev. I don't know if having . at the end will mean you get nothing at all, but even losing the objects I cited will likely break this.

I suggest you generate the initramfs using a list file, so that the kernel can build the archive correctly for you. It produces diagnostics (albeit not great ones) when you make a mistake, and those diagnostics occur at build time, not boot time.

Failing that, I suggest you review the linked documentation for the cpio invocation that will generate an archive the kernel can consume.
Top
pietinger
Moderator
Moderator
Posts: 6620
Joined: Tue Oct 17, 2006 5:11 pm
Location: Bavaria

  • Quote

Post by pietinger » Sun Dec 18, 2022 10:45 pm

I dont know if old ascii format is the reason. It is recommended to use --format=newc

See more here: https://wiki.gentoo.org/wiki/User:Pieti ... _directory
Top
heliostic
n00b
n00b
Posts: 13
Joined: Mon Nov 28, 2022 8:05 am

  • Quote

Post by heliostic » Mon Dec 19, 2022 7:12 am

Hu,

I have previously tried to pass the source directory of the initramfs as the kernel config option but this resulted in the 'no working init found' kernel panic message if I recall correctly.

I'll make the list file and build the kernel with that.

pietinger,

I built busybox separately from the source files on the busybox website. The binary is statically linked and a symbolic link /sbin/switch_root -> /bin/busybox is created at the start of the init script. I have also tried run the init script without the symbolic links, as in exec switch_root /mnt/root /sbin/init would be exec /bin/busybox switch_root /mnt/root /sbin/init etc.

I'll make the archive with--format=newc if the list file doesn't work.
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56080
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Mon Dec 19, 2022 11:40 am

heliostic,

Code: Select all

# mount root partition by UUID
mount -o ro UUID=1884e3b9-09f7-4c06-9fe3-3c0f84c3acd5 /mnt/root 
requires the userspace mount command. Not busybox.

If it was in your initrd,

Code: Select all

/bin/busybox --install -s 
overwrites it with a symlink to busybox.

DIY initramfs may be useful.
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
pietinger
Moderator
Moderator
Posts: 6620
Joined: Tue Oct 17, 2006 5:11 pm
Location: Bavaria

  • Quote

Post by pietinger » Mon Dec 19, 2022 11:46 am

heliostic,

maybe try it with this = all you need:

Code: Select all

#!/bin/busybox sh

# mount
mount -t proc none /proc
mount -t devtmpfs none /dev
mount -t sysfs none /sys

# mount root partition by UUID
mount -o ro UUID=1884e3b9-09f7-4c06-9fe3-3c0f84c3acd5 /mnt/root

echo "Hello World"

# unmount
umount /proc /dev/ sys

exec switch_root /mnt/root /sbin/init
Top
GDH-gentoo
Advocate
Advocate
User avatar
Posts: 2111
Joined: Sat Jul 20, 2019 7:02 pm
Location: South America

  • Quote

Post by GDH-gentoo » Mon Dec 19, 2022 4:58 pm

NeddySeagoon wrote:

Code: Select all

# mount root partition by UUID
mount -o ro UUID=1884e3b9-09f7-4c06-9fe3-3c0f84c3acd5 /mnt/root 
requires the userspace mount command. Not busybox.
BusyBox supports it if it was built with FEATURE_MOUNT_LABEL enabled. I've used BusyBox mount with the LABEL= variant.
Last edited by GDH-gentoo on Tue Dec 20, 2022 1:35 am, edited 1 time in total.
Ionen wrote:As a packager I just don't want things to get messier with weird build systems and multiple toolchains requirements though :)
Top
heliostic
n00b
n00b
Posts: 13
Joined: Mon Nov 28, 2022 8:05 am

  • Quote

Post by heliostic » Mon Dec 19, 2022 5:41 pm

I built the cpio archive using the kernels usr/gen_initramfs.sh script and it booted fine embedded and as an external compressed file.

I'll test the initramfs a bit further but right now there doesn't seem to be any more problems.

Thanks for all the help.
Top
Post Reply

14 posts • Page 1 of 1

Return to “Kernel & Hardware”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic