# Need to become proficient with initramfs

## dufeu

I'm firmly from the old school KISS "Keep It Simple Silly!!" philosophy. To this point in time, I've been perfectly happy building kernels with no initramfs functionality.

I've reached the point where I want to start using relatively advanced functions. These include:dmraidbtrfsdmcrypt/LUKSuvesafb

I've been reading:InitramfsDM-Crypt with LUKSUsing Btrfs with Multiple DevicesBtrfs and Raid Setupprojects::uvesafb

This exercise is meant as an in depth learning experience and also to eventually become my default configuration.

My current thinking is to develop my initramfs based kernels on a virtual PC using either Virtual Box or VMWare Workstation. To that end, I'll probably configure the virtual PC with three drive partitions for a Raid5 setup. The intent is to have a single disk volume partitioned into / /boot and swap. 

Initially, instead of using a USB stick to hold the pass phrase for LUKS, I'll probably setup an ISO image. This should give me the experience I want with using stored pass phrases without having to struggle with activating USB functionality in a virtual environment.

My questions are:Are developing kernels this way reasonable?Are there any considerations I should be aware of before I start?What other resources should I be aware of besides the ones I've listed?Does anyone have /init scripts which perform any or all of the functionality I'm looking for which I can use as examples?

Several notes:

If it's convenient for sample /init scripts, I do make use of PasteBin.

I expect to digest my experiences doing this and to post a HOWTO in the future. Any other points anyone would like to see being made with regards to initramfs would be appreciated. For an example of the kind of writing I do, you may be interested in my Major Upgrade HOWTO (Post I).

Wish me luck! And thanks for reading.

----------

## Hu

 *dufeu wrote:*   

> My questions are:Are developing kernels this way reasonable?Are there any considerations I should be aware of before I start?What other resources should I be aware of besides the ones I've listed?Does anyone have /init scripts which perform any or all of the functionality I'm looking for which I can use as examples?

 

Technically, you are developing an initramfs rather than the kernel itself.  This seems like a reasonable way to approach the problem, though.If you only need to prove that the initramfs does what you want, consider having a barebones system inside the encrypted storage.  For example, a btrfs with an /sbin/init that just prints a message, prints /proc/swaps and /proc/mounts, and then stops would be sufficient to prove that you successfully opened the LUKS devices, activated swap, and mounted root.  This would save you time and space over having a functional Gentoo environment waiting in the virtual disk.Consider qemu-kvm instead of the products you described.  It is free, and it has a special hack that lets you choose a kernel on the command line instead of running a bootloader in the guest.  When doing early kernel work, this will save you a great deal of time because you can go from doing:

- host> build kernel

- Boot guest on good kernel

- host> scp vmlinuz guest:/boot

- Reboot guest

- Guest kernel boots

- Test kernel

to instead doing:

- host> build kernel

- qemu-kvm -kernel vmlinuz other-arguments-here

- Guest kernel boots

- Test kernel

As a bonus, you can start it with -snapshot so that all changes to guest hard disks are discarded when qemu-kvm exits.  This way, you can kill the hypervisor as soon as you decide that an iteration has failed, without worrying about the consequences to the guest disk.I am not aware of an init script which does all the things you describe.  I think I have one that does some of what you want.

----------

## Mad Merlin

I'm pretty sure none of those require an initrd. Normally an initrd is only used when you want to compile a lot of things as modules instead of directly into the kernel because you're not sure which will actually get used. In other words, there shouldn't be any reason to use an initrd for a single purpose kernel.

----------

## dufeu

 *Hu wrote:*   

> I am not aware of an init script which does all the things you describe.  I think I have one that does some of what you want.

 

Good points all. I very much appreciate your input.

As for the init script, the more examples I have to look at and think about, the better. i.e. Gentoo dev "spock" has init script fragments dealing with uvesafb. But I also would like to see fragments dealing with dmcrypt/LUKS and btrfs. Apparently, dmraid and btrfs are mutually exclusive. i.e. raid0, raid1 and raid10 are native to btrfs and dmraid doesn't apply. I'm still interested in dmraid oriented init script fragments/suggestions as this is something I still want to learn about. But it looks like I need to make a second virtual PC for this.

I like the suggestions regarding qemu. I will think about them for now. At the moment, I have both vbox and vmware working and available on my primary workstation. The problem is tacking on the learning curve associated with qemu. I've never set qemu up before. If you have a suggested HOWTO link or links for this, it would be appreciated.

You are correct that I'm only interested in developing an initramfs configuration. As such, this will be a minimalist virtual PC. I haven't yet decided how minimalist I will make it. The idea is to ultimately have a "stage4" I can use to initialize new systems with. This implies a working @system profile.

Thanks again for your thoughts. It's given me quite a bit more to think about.

----------

## dufeu

 *Mad Merlin wrote:*   

> I'm pretty sure none of those require an initrd. Normally an initrd is only used when you want to compile a lot of things as modules instead of directly into the kernel because you're not sure which will actually get used. In other words, there shouldn't be any reason to use an initrd for a single purpose kernel.

 

Several of the items listed actually do require an initrd.

uvesafb requires use of a userland helper program. "spock" gives init script fragments and specific kernel settings in his instructions for setting it up.

grub doesn't yet support booting from a btrfs partition. So you have to boot to an initramfs with btrfs support before you can continue booting. Also, mdadm doesn't recognize btrfs.

Also, I'd like to eventually get to the point of being able to boot with an encrypted root and encrypted swap. My understanding was that initramfs is required for this as well.

Finally, after using gentoo since 2001 and installing various distros prior to that, I feel it's about time to round out my linux admin skillset to include being reasonably conversant with building and using initramfs.  :Very Happy: 

----------

## Hu

No specific HOWTO documents for qemu come to mind.  You can work out a basic invocation of it from the documentation shipped with the package.  For what you want, it is probably sufficient to run kvm -drive file=guest.raw,format=raw -net none when booting it normally.  Add in -kernel and perhaps -append / -initrd when you want to bypass the bootloader in the guest.  KVM can treat a flat file as a raw disk image, so you could prepare the minimal system from the host.  Making filesystems in the virtual partitions is a bit challenging, since you would need to set up a loop device at some offset within the file.  You might find it easier to boot the guest with a Gentoo LiveCD: kvm -drive file=guest.raw,format=raw -drive file=amd64_minimal.iso,media=cdrom,format=raw.  By default, Qemu/KVM turns on a usermode network stack for the guest, which works, but is quite slow.  It may be adequate to prepare a minimal system.  If not, download the files to the host and use either an iso in a virtual CD drive or the virtual FAT support to expose the files to the guest.  You can also prepare a higher performance network stack via TUN/TAP devices, but that is more involved.

----------

