* [gentoo-user] Building an initramfs into the kernel @ 2012-12-26 15:58 Mark Knecht 2012-12-26 17:09 ` Neil Bothwick 0 siblings, 1 reply; 12+ messages in thread From: Mark Knecht @ 2012-12-26 15:58 UTC (permalink / raw To: Gentoo User Hi, OK, it's the day after Christmas and this little kid wants to play with the new toys Uncle Neil gave us yesterday - a copy of his well worn setup file for building an initramfs into the kernel - a copy of which I place here: [QUOTE] This is the file I use on a system that has / on a LUKS filesystem on top of LVM. The format is documented in the kernel docs at Documentation/filesystems/ramfs-rootfs-initramfs.txt dir /bin 755 0 0 file /bin/busybox /bin/busybox 755 0 0 slink /bin/sh busybox 777 0 0 dir /realroot 755 0 0 dir /etc 755 0 0 dir /proc 755 0 0 dir /sys 755 0 0 dir /sbin 755 0 0 file /sbin/lvm.static /sbin/lvm.static 755 0 0 #file /sbin/mdadm /sbin/mdadm 755 0 0 file /sbin/cryptsetup /sbin/cryptsetup 755 0 0 file /sbin/e2fsck /sbin/e2fsck 755 0 0 dir /lib 755 0 0 file /lib/libext2fs.so /usr/lib64/libext2fs.so 755 0 0 dir /dev 755 0 0 nod /dev/console 600 0 0 c 5 1 nod /dev/null 666 0 0 c 1 3 nod /dev/tty 666 0 0 c 5 0 nod /dev/urandom 666 0 0 c 1 9 file /init /usr/src/init.sh 755 0 0 [/QUOTE] OK, so reading through this it seems moderately straight forward. My reading: a) Create some directories b) Populate them with some executables c) Make some nodes d) Execute a script I do have a few questions: 1) dir /realroot 755 0 0 Is this something required to make the machine boot? Or is it possibly a mount point in case of problems and just used inside the initramfs if trouble arises? Something else? Google didn't point me toward anything meaningful. 2) Contained executables, as I understand them, either need to be built with the static flag or you have to include all the libraries. Static seems simpler so (in my case) should I rebuild mdadm & e2fsprogs with +static? (I don't currently use lvm or any crypt stuff) I assume from the line file /lib/libext2fs.so /usr/lib64/libext2fs.so 755 0 0 that running ldd on the new mdadm is still going to require this one library be in the initramfs? 3) My system uses RAID today. Is there any significant risk in rebuilding mdadm with static support, rebooting the existing kernel without an initramfs and then mdadm having trouble? 4) What's in /usr/src/init.sh ? From the Gentoo initramfs wiki I find this as an example: rescue_shell() { echo "Something went wrong. Dropping you to a shell." busybox --install -s exec /bin/sh } I wonder what Uncle Neil uses? (Or anyone else...) Yipee!!! Better than the Red Ryder BB gun complete with a compass and a sundial I was hoping for! ;-) (And if it's not clear, I'm hoping this thread might possibly help others in the future move from one place about initramfs to another place about initramfs. We'll see.) Cheers, Mark ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 15:58 [gentoo-user] Building an initramfs into the kernel Mark Knecht @ 2012-12-26 17:09 ` Neil Bothwick 2012-12-26 20:48 ` Mark Knecht 0 siblings, 1 reply; 12+ messages in thread From: Neil Bothwick @ 2012-12-26 17:09 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 4726 bytes --] On Wed, 26 Dec 2012 07:58:34 -0800, Mark Knecht wrote: > OK, it's the day after Christmas and this little kid wants to play > with the new toys Uncle Neil gave us yesterday - a copy of his well > worn setup file for building an initramfs into the kernel - a copy of > which I place here: > > [QUOTE] > > This is the file I use on a system that has / on a LUKS filesystem on > top of LVM. The format is documented in the kernel docs at > Documentation/filesystems/ramfs-rootfs-initramfs.txt > > > dir /bin 755 0 0 > file /bin/busybox /bin/busybox 755 0 0 > slink /bin/sh busybox 777 0 0 > > dir /realroot 755 0 0 > dir /etc 755 0 0 > dir /proc 755 0 0 > dir /sys 755 0 0 > > dir /sbin 755 0 0 > file /sbin/lvm.static /sbin/lvm.static 755 0 0 > #file /sbin/mdadm /sbin/mdadm 755 0 0 > file /sbin/cryptsetup /sbin/cryptsetup 755 0 0 > > file /sbin/e2fsck /sbin/e2fsck 755 0 0 > dir /lib 755 0 0 > file /lib/libext2fs.so /usr/lib64/libext2fs.so 755 0 0 > > dir /dev 755 0 0 > nod /dev/console 600 0 0 c 5 1 > nod /dev/null 666 0 0 c 1 3 > nod /dev/tty 666 0 0 c 5 0 > nod /dev/urandom 666 0 0 c 1 9 > > file /init /usr/src/init.sh 755 0 0 > > [/QUOTE] > > > OK, so reading through this it seems moderately straight forward. My > reading: > > a) Create some directories > b) Populate them with some executables > c) Make some nodes > d) Execute a script > > > I do have a few questions: > > 1) dir /realroot 755 0 0 > > Is this something required to make the machine boot? Or is it possibly > a mount point in case of problems and just used inside the initramfs > if trouble arises? Something else? Google didn't point me toward > anything meaningful. It's where init.sh mounts the real root filesystem before running switchroot. > 2) Contained executables, as I understand them, either need to be > built with the static flag or you have to include all the libraries. > Static seems simpler so (in my case) should I rebuild mdadm & > e2fsprogs with +static? (I don't currently use lvm or any crypt stuff) Yes. > 3) My system uses RAID today. Is there any significant risk in > rebuilding mdadm with static support, rebooting the existing kernel > without an initramfs and then mdadm having trouble? Static mdadm has given me no problems whatsoever, I guarantee that you will have no fewer problems than me :) > 4) What's in /usr/src/init.sh ? From the Gentoo initramfs wiki I find > this as an example: I use one based on the wiki example #!/bin/busybox sh rescue_shell() { busybox --install -s echo $1 exec /bin/sh } ### Mount the /proc and /sys filesystems. mount -t proc none /proc grep -q initdebug </proc/cmdline && set -x && DEBUG=1 mount -t sysfs none /sys mount -t devtmpfs none /dev ### Get root and init parameters from cmdline REAL_ROOT="$(sed 's/.*root=\(\S*\).*/\1/' <proc/cmdline)" if grep -q init= </proc/cmdline; then REAL_INIT="$(sed 's/.*init=\(\S*\).*/\1/' <proc/cmdline)" else REAL_INIT="/sbin/init" fi ### Assemble RAID [[ -f /sbin/mdadm ]] && mdadm --assemble --scan ### Initialise LVM if [[ -f /sbin/lvm.static ]]; then lvm.static vgchange -a y lvm.static vgscan --mknodes [[ -n "$DEBUG" ]] && sleep 10 fi ### Mount the root filesystem. if [[ -f /sbin/cryptsetup ]] && cryptsetup isLuks $REAL_ROOT; then busybox echo -e "\e[0;32m\n=====================\nEncrypted root device\n=====================\n\e[m" cryptsetup luksOpen $REAL_ROOT cryptroot REAL_ROOT="/dev/mapper/cryptroot" [[ -n "$DEBUG" ]] && echo $REAL_ROOT && sleep 10 fi mount -o ro $REAL_ROOT /realroot || rescue_shell "Could not mount REAL_ROOT" [[ -n "$DEBUG" ]] && df -h /realroot && sleep 10 ### Mount /usr if separate if grep -qE '^[^#].*\s\/usr\s' /realroot/etc/fstab; then #mount $(awk '/\s\/usr\s/ {print $1, "/realroot"$2, "-t", $3, "-o", $4 ",ro"}' /realroot/etc/fstab) mount $(awk '/^[^#].*\s\/usr\s/ {print $1, "/realroot"$2, "-t", $3, "-o", $4 ",ro"}' /realroot/etc/fstab) [[ -n "$DEBUG" ]] && df -h /realroot//usr && sleep 10 fi grep -q waitforkey </proc/cmdline && WAITFORKEY=1 grep -q rescue </proc/cmdline && rescue_shell "...because you asked for it." ### Clean up. umount /dev umount /sys umount /proc ### Boot the real thing [[ -n "$DEBUG" ]] && echo "Ready to switch" && sleep 10 [[ -n "$WAITFORKEY" ]] && busybox showkey -a exec busybox switch_root /realroot $REAL_INIT || rescue_shell "Failed to switch_root" Most of it is debug stuff that I haven't used since I first started using it. -- Neil Bothwick For security reasons, all text in this mail is double-rot13 encrypted. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 17:09 ` Neil Bothwick @ 2012-12-26 20:48 ` Mark Knecht 2012-12-26 21:49 ` Mark Knecht 2012-12-26 23:02 ` Neil Bothwick 0 siblings, 2 replies; 12+ messages in thread From: Mark Knecht @ 2012-12-26 20:48 UTC (permalink / raw To: Gentoo User On Wed, Dec 26, 2012 at 9:09 AM, Neil Bothwick <neil@digimed.co.uk> wrote: > On Wed, 26 Dec 2012 07:58:34 -0800, Mark Knecht wrote: > >> 2) Contained executables, as I understand them, either need to be >> built with the static flag or you have to include all the libraries. >> Static seems simpler so (in my case) should I rebuild mdadm & >> e2fsprogs with +static? (I don't currently use lvm or any crypt stuff) > > Yes. > <SNIP> I've done that, played a bit with ldd to see the changes, etc., and it seems to make sense. On the mdadm list one comment came up which was to make sure my mdadm.conf file was up to date and then include it in the initramfs image so that if for some reason the machine doesn't boot I have all the info required to start the RAIDs by hand. I thought that was a good comment. > > Most of it is debug stuff that I haven't used since I first started using > it. OK, it's a good example of a more complete init script so that's helpful. Thanks! One other question came up. So I build the kernel, and the kernel build creates the initramfs image and embeds it in the kernel. Is there a tool that would allow me to query the embedded image prior to booting so that I can check that everything is in there that I think should be in there? Scanning around online I found discussion about lsinitramfs but I haven't found it in portage yet. dracut has lsinitrd. genkernel doesn't have anything like it. And even if I found it I think it only works for stand alone initramfs files. Thanks, Mark ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 20:48 ` Mark Knecht @ 2012-12-26 21:49 ` Mark Knecht 2012-12-26 22:09 ` Mark Knecht 2012-12-26 23:02 ` Neil Bothwick 1 sibling, 1 reply; 12+ messages in thread From: Mark Knecht @ 2012-12-26 21:49 UTC (permalink / raw To: Gentoo User On Wed, Dec 26, 2012 at 12:48 PM, Mark Knecht <markknecht@gmail.com> wrote: <SNIP> > One other question came up. So I build the kernel, and the kernel build > creates the initramfs image and embeds it in the kernel. Is there a tool > that would allow me to query the embedded image prior to booting > so that I can check that everything is in there that I think should be in > there? Actually, I think the initramfs wiki covers this, albeit it's 'not easy'. Their words. I think I'm covered for now. Cheers, Mark ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 21:49 ` Mark Knecht @ 2012-12-26 22:09 ` Mark Knecht 2012-12-26 23:03 ` Neil Bothwick 0 siblings, 1 reply; 12+ messages in thread From: Mark Knecht @ 2012-12-26 22:09 UTC (permalink / raw To: Gentoo User On Wed, Dec 26, 2012 at 1:49 PM, Mark Knecht <markknecht@gmail.com> wrote: <SNIP> > Actually, I think the initramfs wiki covers this, albeit it's 'not > easy'. Their words. > > I think I'm covered for now. > > Cheers, > Mark While extracting it from the kernel image may be involved, and for now using Neil's example init script which probably isn't exactly right for my needs, there is an intermediate step I quickly discovered. After building the new kernel there is an initramfs_data_cpio file created in /usr/src/linux/usr. I copied this file to a new directory under /root and then ran cpio -i -d -H newc --no-absolute-filenames < initramfs_data.cpio which creates all of the initramfs file structure in this directory. I can then list it and it appears everything is there: c2stable initramfs-work # ls -lR .: total 2620 drwxr-xr-x 2 root root 4096 Dec 26 14:00 bin drwxr-xr-x 2 root root 4096 Dec 26 14:00 dev drwxr-xr-x 2 root root 4096 Dec 26 14:00 etc -rwxr-xr-x 1 root root 2017 Dec 26 14:00 init -rw-r--r-- 1 root root 2640384 Dec 26 13:59 initramfs_data.cpio drwxr-xr-x 2 root root 4096 Dec 26 14:00 lib drwxr-xr-x 2 root root 4096 Dec 26 14:00 proc drwxr-xr-x 2 root root 4096 Dec 26 14:00 realroot drwxr-xr-x 2 root root 4096 Dec 26 14:00 sbin drwxr-xr-x 2 root root 4096 Dec 26 14:00 sys ./bin: total 2020 -rwxr-xr-x 1 root root 2061600 Dec 26 14:00 busybox lrwxrwxrwx 1 root root 7 Dec 26 14:00 sh -> busybox ./dev: total 0 crw------- 1 root root 5, 1 Dec 26 14:00 console crw-rw-rw- 1 root root 1, 3 Dec 26 14:00 null crw-rw-rw- 1 root root 5, 0 Dec 26 14:00 tty crw-rw-rw- 1 root root 1, 9 Dec 26 14:00 urandom ./etc: total 4 -rwxr-xr-x 1 root root 3017 Dec 26 14:00 mdadm.conf ./lib: total 4 -rwxr-xr-x 1 root root 528 Dec 26 14:00 libext2fs.so ./proc: total 0 ./realroot: total 0 ./sbin: total 568 -rwxr-xr-x 1 root root 216744 Dec 26 14:00 e2fsck -rwxr-xr-x 1 root root 353928 Dec 26 14:00 mdadm ./sys: total 0 c2stable initramfs-work # c2stable initramfs-work # cat init #!/bin/busybox sh rescue_shell() { busybox --install -s echo $1 exec /bin/sh } ### Mount the /proc and /sys filesystems. mount -t proc none /proc grep -q initdebug </proc/cmdline && set -x && DEBUG=1 mount -t sysfs none /sys mount -t devtmpfs none /dev ### Get root and init parameters from cmdline REAL_ROOT="$(sed 's/.*root=\(\S*\).*/\1/' <proc/cmdline)" if grep -q init= </proc/cmdline; then REAL_INIT="$(sed 's/.*init=\(\S*\).*/\1/' <proc/cmdline)" else REAL_INIT="/sbin/init" fi ### Assemble RAID [[ -f /sbin/mdadm ]] && mdadm --assemble --scan ### Initialise LVM if [[ -f /sbin/lvm.static ]]; then lvm.static vgchange -a y lvm.static vgscan --mknodes [[ -n "$DEBUG" ]] && sleep 10 fi ### Mount the root filesystem. if [[ -f /sbin/cryptsetup ]] && cryptsetup isLuks $REAL_ROOT; then busybox echo -e "\e[0;32m\n=====================\nEncrypted root device\n=====================\n\e[m" cryptsetup luksOpen $REAL_ROOT cryptroot REAL_ROOT="/dev/mapper/cryptroot" [[ -n "$DEBUG" ]] && echo $REAL_ROOT && sleep 10 fi mount -o ro $REAL_ROOT /realroot || rescue_shell "Could not mount REAL_ROOT" [[ -n "$DEBUG" ]] && df -h /realroot && sleep 10 ### Mount /usr if separate if grep -qE '^[^#].*\s\/usr\s' /realroot/etc/fstab; then #mount $(awk '/\s\/usr\s/ {print $1, "/realroot"$2, "-t", $3, "-o", $4 ",ro"}' /realroot/etc/fstab) mount $(awk '/^[^#].*\s\/usr\s/ {print $1, "/realroot"$2, "-t", $3, "-o", $4 ",ro"}' /realroot/etc/fstab) [[ -n "$DEBUG" ]] && df -h /realroot//usr && sleep 10 fi grep -q waitforkey </proc/cmdline && WAITFORKEY=1 grep -q rescue </proc/cmdline && rescue_shell "...because you asked for it." ### Clean up. umount /dev umount /sys umount /proc ### Boot the real thing [[ -n "$DEBUG" ]] && echo "Ready to switch" && sleep 10 [[ -n "$WAITFORKEY" ]] && busybox showkey -a exec busybox switch_root /realroot $REAL_INIT || rescue_shell "Failed to switch_root" c2stable initramfs-work # At this point I don't know that 1) the image is actually in the kernel, or 2) that my "init thingy" ;-) image would work, but at least the process of putting it together is verifiable. Cheers, Mark ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 22:09 ` Mark Knecht @ 2012-12-26 23:03 ` Neil Bothwick 2012-12-26 23:50 ` Mark Knecht 0 siblings, 1 reply; 12+ messages in thread From: Neil Bothwick @ 2012-12-26 23:03 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 499 bytes --] On Wed, 26 Dec 2012 14:09:34 -0800, Mark Knecht wrote: > At this point I don't know that 1) the image is actually in the > kernel, or 2) that my "init thingy" ;-) image would work, but at least > the process of putting it together is verifiable. That's why I put in all the debug stuff, so I could watch the progress of the script as it ran. -- Neil Bothwick In the 60's people took acid to make the world weird. Now the world is weird and people take Prozac to make it normal. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 23:03 ` Neil Bothwick @ 2012-12-26 23:50 ` Mark Knecht 2012-12-27 17:33 ` Mark Knecht 0 siblings, 1 reply; 12+ messages in thread From: Mark Knecht @ 2012-12-26 23:50 UTC (permalink / raw To: Gentoo User On Wed, Dec 26, 2012 at 3:03 PM, Neil Bothwick <neil@digimed.co.uk> wrote: > On Wed, 26 Dec 2012 14:09:34 -0800, Mark Knecht wrote: > >> At this point I don't know that 1) the image is actually in the >> kernel, or 2) that my "init thingy" ;-) image would work, but at least >> the process of putting it together is verifiable. > > That's why I put in all the debug stuff, so I could watch the progress of > the script as it ran. > OK, I'll look at combining that part my my scripts, or just using yours, etc. Thanks for the help, Mark ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 23:50 ` Mark Knecht @ 2012-12-27 17:33 ` Mark Knecht 2012-12-27 23:24 ` Mark Knecht 2012-12-29 0:41 ` Neil Bothwick 0 siblings, 2 replies; 12+ messages in thread From: Mark Knecht @ 2012-12-27 17:33 UTC (permalink / raw To: Gentoo User On Wed, Dec 26, 2012 at 3:50 PM, Mark Knecht <markknecht@gmail.com> wrote: > On Wed, Dec 26, 2012 at 3:03 PM, Neil Bothwick <neil@digimed.co.uk> wrote: >> On Wed, 26 Dec 2012 14:09:34 -0800, Mark Knecht wrote: >> >>> At this point I don't know that 1) the image is actually in the >>> kernel, or 2) that my "init thingy" ;-) image would work, but at least >>> the process of putting it together is verifiable. >> >> That's why I put in all the debug stuff, so I could watch the progress of >> the script as it ran. >> > > > OK, I'll look at combining that part my my scripts, or just using yours, etc. > > Thanks for the help, > Mark Neil, One more question if I might. What's the simplest way to regenerate the kernel when there are no kernel changes but you have changes to the programs that are going into the initramfs? make clean seems like overkill to me, and it's very slow to boot. I suspect that one of the simplest failures on an initramfs is that you update something that's contained in the initramfs, mdadm or busybox or whatever, and then don't get that new stuff into the initramfs. Seems like I need to be right on top of what I'm keeping in it and make sure a new kernel gets generated any time those packages are updated. Correct? Anyway, I'm wondering how you manage that? Should be booting my first kernel with the initramfs in it shortly. We'll see how that goes. Thanks, Mark ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-27 17:33 ` Mark Knecht @ 2012-12-27 23:24 ` Mark Knecht 2012-12-28 23:07 ` Mark Knecht 2012-12-29 0:41 ` Neil Bothwick 1 sibling, 1 reply; 12+ messages in thread From: Mark Knecht @ 2012-12-27 23:24 UTC (permalink / raw To: Gentoo User On Thu, Dec 27, 2012 at 9:33 AM, Mark Knecht <markknecht@gmail.com> wrote: > On Wed, Dec 26, 2012 at 3:50 PM, Mark Knecht <markknecht@gmail.com> wrote: >> On Wed, Dec 26, 2012 at 3:03 PM, Neil Bothwick <neil@digimed.co.uk> wrote: >>> On Wed, 26 Dec 2012 14:09:34 -0800, Mark Knecht wrote: >>> >>>> At this point I don't know that 1) the image is actually in the >>>> kernel, or 2) that my "init thingy" ;-) image would work, but at least >>>> the process of putting it together is verifiable. >>> >>> That's why I put in all the debug stuff, so I could watch the progress of >>> the script as it ran. >>> >> >> >> OK, I'll look at combining that part my my scripts, or just using yours, etc. >> >> Thanks for the help, >> Mark > > Neil, > One more question if I might. What's the simplest way to regenerate > the kernel when there are no kernel changes but you have changes to > the programs that are going into the initramfs? make clean seems like > overkill to me, and it's very slow to boot. > <SNIP> Answering self: The Gentoo wiki covered this at the end: http://en.gentoo-wiki.com/wiki/Initramfs I tried it and it seemed to work, although I've not yet successfully booted this kernel so there may well be some issues left to deal with. Cheers ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-27 23:24 ` Mark Knecht @ 2012-12-28 23:07 ` Mark Knecht 0 siblings, 0 replies; 12+ messages in thread From: Mark Knecht @ 2012-12-28 23:07 UTC (permalink / raw To: Gentoo User On Thu, Dec 27, 2012 at 3:24 PM, Mark Knecht <markknecht@gmail.com> wrote: > On Thu, Dec 27, 2012 at 9:33 AM, Mark Knecht <markknecht@gmail.com> wrote: >> On Wed, Dec 26, 2012 at 3:50 PM, Mark Knecht <markknecht@gmail.com> wrote: >>> On Wed, Dec 26, 2012 at 3:03 PM, Neil Bothwick <neil@digimed.co.uk> wrote: >>>> On Wed, 26 Dec 2012 14:09:34 -0800, Mark Knecht wrote: >>>> >>>>> At this point I don't know that 1) the image is actually in the >>>>> kernel, or 2) that my "init thingy" ;-) image would work, but at least >>>>> the process of putting it together is verifiable. >>>> >>>> That's why I put in all the debug stuff, so I could watch the progress of >>>> the script as it ran. >>>> >>> >>> >>> OK, I'll look at combining that part my my scripts, or just using yours, etc. >>> >>> Thanks for the help, >>> Mark >> >> Neil, >> One more question if I might. What's the simplest way to regenerate >> the kernel when there are no kernel changes but you have changes to >> the programs that are going into the initramfs? make clean seems like >> overkill to me, and it's very slow to boot. >> > <SNIP> > > Answering self: The Gentoo wiki covered this at the end: > > http://en.gentoo-wiki.com/wiki/Initramfs > > I tried it and it seemed to work, although I've not yet successfully > booted this kernel so there may well be some issues left to deal with. > > Cheers OK, this is all finished up and working now. I'll have to give it some time to make sure nothing weird pops up but it was a good learning experience for me. The two biggest problems I had along way: 1) I used an older init script that I had put together a year back with I played with this for an afternoon. I had trouble back then with /dev so I copied over pretty much everything into my initramfs. (As per the Gentoo initramfs wiki) This time around, using that script, I still had troubles until I discovered the mount -t devtmpfs none /dev command in Neil's script. That allowed me to move forward. 2) Turns out the config format for copying files is target/source, not source/target like most copies. This resulted in my mdadm.conf file going into the wrong directory. Once I figured those two out the machine booted cleanly. I'm going to continue working on this. I'd like to do a better init script, maybe add some more stuff to play with. That said I'll attach in-line the stuff I ended up with for anyone else who comes across this thread in the future. Cheers, Mark c2stable src # ls -la total 28 drwxr-xr-x 4 root root 4096 Dec 28 15:04 . drwxr-xr-x 14 root root 4096 Dec 25 2011 .. -rw-r--r-- 1 root root 0 Dec 29 2010 .keep -rw-r--r-- 1 root root 574 Dec 28 11:45 initramfs.config -rw-r--r-- 1 root root 562 Dec 28 10:44 initramfs_init_new.sh lrwxrwxrwx 1 root root 19 Dec 27 07:49 linux -> linux-3.6.11-gentoo drwxr-xr-x 24 root root 4096 Dec 28 09:49 linux-3.2.1-gentoo-r2 drwxr-xr-x 24 root root 4096 Dec 28 11:46 linux-3.6.11-gentoo -rw-r--r-- 1 root root 70 Dec 28 06:58 mdadm_initramfs.conf c2stable src # cat initramfs.config dir /bin 755 0 0 file /bin/busybox /bin/busybox 755 0 0 slink /bin/sh busybox 777 0 0 dir /realroot 755 0 0 dir /etc 755 0 0 dir /proc 755 0 0 dir /sys 755 0 0 dir /sbin 755 0 0 file /sbin/mdadm /sbin/mdadm 755 0 0 file /sbin/e2fsck /sbin/e2fsck 755 0 0 dir /lib 755 0 0 file /lib/libext2fs.so /usr/lib64/libext2fs.so 755 0 0 file /etc/mdadm.conf /usr/src/mdadm_initramfs.conf 755 0 0 dir /dev 755 0 0 nod /dev/console 600 0 0 c 5 1 nod /dev/null 666 0 0 c 1 3 nod /dev/tty 666 0 0 c 5 0 nod /dev/urandom 666 0 0 c 1 9 file /init /usr/src/initramfs_init_new.sh 755 0 0 c2stable src # cat initramfs_init_new.sh #!/bin/busybox sh rescue_shell() { echo "Something went wrong. Dropping you to a shell." busybox --install -s exec /bin/sh } # Mount the /proc and /sys filesystems. mount -t proc none /proc mount -t sysfs none /sys mount -t devtmpfs none /dev # Do your stuff here. echo "This script mounts rootfs and boots it up, nothing more!" mdadm --assemble /dev/md3 # Mount the root filesystem. mount -o ro /dev/md3 /realroot || rescue_shell # Clean up. umount /dev umount /proc umount /sys # Boot the real thing. exec switch_root /realroot /sbin/init c2stable src # cat mdadm_initramfs.conf ARRAY /dev/md/3 metadata=1.2 UUID=de47f991:86d98467:0637635b:9c6d0591 c2stable src # ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-27 17:33 ` Mark Knecht 2012-12-27 23:24 ` Mark Knecht @ 2012-12-29 0:41 ` Neil Bothwick 1 sibling, 0 replies; 12+ messages in thread From: Neil Bothwick @ 2012-12-29 0:41 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 626 bytes --] On Thu, 27 Dec 2012 09:33:48 -0800, Mark Knecht wrote: > One more question if I might. What's the simplest way to regenerate > the kernel when there are no kernel changes but you have changes to > the programs that are going into the initramfs? make clean seems like > overkill to me, and it's very slow to boot. Plain make works for me, it appears the initramfs is rebuilt every time, evewn if there are no changes. To be extra sure, you could delete usr/initramfs_data.cpio from the source tree before running make. -- Neil Bothwick You are a completely unique individual, just like everybody else. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [gentoo-user] Building an initramfs into the kernel 2012-12-26 20:48 ` Mark Knecht 2012-12-26 21:49 ` Mark Knecht @ 2012-12-26 23:02 ` Neil Bothwick 1 sibling, 0 replies; 12+ messages in thread From: Neil Bothwick @ 2012-12-26 23:02 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 1069 bytes --] On Wed, 26 Dec 2012 12:48:38 -0800, Mark Knecht wrote: > On the mdadm list one comment came up which was to make sure > my mdadm.conf file was up to date and then include it in the initramfs > image so that if for some reason the machine doesn't boot I have all > the info required to start the RAIDs by hand. I thought that was a good > comment. That is a good idea. > One other question came up. So I build the kernel, and the kernel build > creates the initramfs image and embeds it in the kernel. Is there a tool > that would allow me to query the embedded image prior to booting > so that I can check that everything is in there that I think should be > in there? Yes. I had to do this once when I corrupted or deleted my init.sh and needed to retrieve it from the kernel. I don't remember the details, but I do recall it involved one of the scripts in the kernel source directory and the use of Google - although not in that order :) -- Neil Bothwick "I am a Cub Ranger. We dib dib dib for the One. We dob dob dob for the One." [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2012-12-29 0:43 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-12-26 15:58 [gentoo-user] Building an initramfs into the kernel Mark Knecht 2012-12-26 17:09 ` Neil Bothwick 2012-12-26 20:48 ` Mark Knecht 2012-12-26 21:49 ` Mark Knecht 2012-12-26 22:09 ` Mark Knecht 2012-12-26 23:03 ` Neil Bothwick 2012-12-26 23:50 ` Mark Knecht 2012-12-27 17:33 ` Mark Knecht 2012-12-27 23:24 ` Mark Knecht 2012-12-28 23:07 ` Mark Knecht 2012-12-29 0:41 ` Neil Bothwick 2012-12-26 23:02 ` Neil Bothwick
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox