You are not logged in.

#1 2011-04-24 02:15:30

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

dinit - an alternative base/udev hook for mkinitcpio

Note: dinit has been removed from the AUR is now part of geninit. It still exists on github as a separate project if you want to play with it.

This is something fun that I've been fooling around with for the past week, and I'm pretty happy with it, so I figured I'd give it a little publicity. I've rewritten mkinitcpio's PID 1 in C, and it works as almost a drop-in replacement.

Why? Most of init can be taken care of with native C and some parts are more easily and thoroughly covered than with shell script. I'm currently booting off an image weighing in at under 1mb (it does not have busybox). You can do this too assuming, of course, that you aren't using any runtime hooks.

You can tell if you're using any runtime hooks by checking your current boot image:

$ bsdtar tf /boot/kernel26.img | grep '^/hooks'

If that returns anything more than /hooks/udev, you're using runtime hooks to prepare your root device for mounting. This mainly applies to people using encrypted root, lvm2, sometimes mdadm, and there's some other fancy business like plymouth or keymap. This doesn't disqualify you, it just means you need to read this to the end.

I've created two new base layouts to go with it:
ubase: Very similar to the current base layout, and includes udev. If you're using any runtime hooks, see below for how to modify them for use with dinit.
uubase: Masochistic. No udev. No busybox. No runtime hooks allowed. You must supply all modules in the MODULES= define in /etc/mkinitcpio.conf, and your root cannot be specified as a /dev/disk/by-{uuid,label} symlink. Use /dev/sdxy, or specify the device major/minor (e.g. 8:2 or 802). I currently boot off of this with great success -- my root setup isn't complicated.

I mentioned that this isn't quite a drop-in replacement. What needs to be modified? Since hooks are being run as a fork/exec, you'll need to remove the function wrapper on each runtime hook, and dress them up a bit. Simply done:

  1. Remove the 'run_hook() {' function header and the closing '}'.

  2. Make sure line 1 is a shebang: #!/bin/busybox ash

  3. Mark the hook executable: chmod +x /lib/initcpio/hook/$hookname.

  4. You're no longer inherting from init_functions, so calls such as 'msg' need to go away. This isn't mandatory, but you may see a few 'command not found' errors if you skip this step. They're harmless.

  5. Don't regenerate the image just yet.

Now, modify /etc/mkinitcpio.conf. Remove base and udev from HOOKS, and add in your drug of choice: ubase or uubase.

This next step is important, because I don't wish anybody any particular harm. As much as I've tested this, I really don't want anyone to be in a situation where they need to chroot from a liveCD to get back to a booting system. So, make an image with a different name than whatever it is you're currently booting with, e.g.

# mkinitcpio -g /boot/dinit.img

Add a new boot entry to your bootloader of choice or just edit at boot time.

Other notes:

  • This should still support 99% of what mkinitcpio supports in terms of command line parameters such as: skiphooks, earlymodules, disablemodules, rootdelay, break (ubase only, of course), and init.

  • Intentionally discluded: /lib/udev/load-modules.sh is a symlink to /sbin/modprobe. I'll only say that blacklisting for disablemodules is done the way upstream recommends it done. You won't notice the difference.

  • No support for a '/message' file. I didn't think it was a big deal.

The most important part: where to find it?

On Github: https://github.com/falconindy/dinit
In the AUR: https://aur.archlinux.org/packages.php?ID=48454

I'd love to know what setups people are able to use with this, and I'm almost more interested in what setups don't work, so I can fix them. If you'd like to tell me my code sucks, please provide as much information as possible. Posting the contents of a working initcpio (bsdtar -tf /boot/kernel-26.img) and /etc/mkinitcpio.conf would be most helpful (remember to use code tags!). If you're using a non-stock kernel I'd like to know that too.

Last edited by falconindy (2011-04-30 16:26:21)

Offline

#2 2011-04-24 14:12:12

el mariachi
Member
Registered: 2007-11-30
Posts: 595

Re: dinit - an alternative base/udev hook for mkinitcpio

Works here with

/hooks
/hooks/udev/
/hooks/resume

using kernel26-pf-core2

/lib
/lib/modules
/lib/modules/2.6.38-pf
/lib/modules/2.6.38-pf/kernel
/lib/modules/2.6.38-pf/kernel/drivers
/lib/modules/2.6.38-pf/kernel/drivers/char
/lib/modules/2.6.38-pf/kernel/drivers/char/agp
/lib/modules/2.6.38-pf/kernel/drivers/char/agp/intel-gtt.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/char/agp/intel-agp.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/i2c
/lib/modules/2.6.38-pf/kernel/drivers/i2c/i2c-core.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/gpu
/lib/modules/2.6.38-pf/kernel/drivers/gpu/drm
/lib/modules/2.6.38-pf/kernel/drivers/gpu/drm/drm.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/gpu/drm/drm_kms_helper.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/acpi
/lib/modules/2.6.38-pf/kernel/drivers/acpi/video.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/acpi/button.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/i2c/algos
/lib/modules/2.6.38-pf/kernel/drivers/i2c/algos/i2c-algo-bit.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/gpu/drm/i915
/lib/modules/2.6.38-pf/kernel/drivers/gpu/drm/i915/i915.ko.gz
/proc
/sys
/dev
/bin
/sbin
/usr
/usr/bin
/usr/lib
/usr/sbin
/run
/new_root
/etc
/etc/udev
/etc/udev/udev.conf
/etc/modprobe.d
/etc/modprobe.d/usb-load-ehci-first.conf
/lib/udev
/lib/udev/rules.d
/lib/udev/rules.d/50-firmware.rules
/lib/udev/rules.d/50-udev-default.rules
/lib/udev/rules.d/60-persistent-storage.rules
/lib/udev/rules.d/80-drivers.rules
/lib/udev/firmware
/lib/udev/ata_id
/lib/udev/path_id
/lib/udev/scsi_id
/lib/udev/usb_id
/init
/lib/libblkid.so.1
/lib/libblkid.so.1.1.0
/lib/libc.so.6
/lib/libc-2.13.so
/lib/libuuid.so.1
/lib/libuuid.so.1.3.0
/lib/ld-linux-x86-64.so.2
/lib/ld-2.13.so
/bin/busybox
/sbin/modprobe
/sbin/blkid
/sbin/udevd
/lib/librt.so.1
/lib/librt-2.13.so
/lib/libpthread.so.0
/lib/libpthread-2.13.so
/sbin/udevadm
/lib/udev/load-modules.sh
/config
/lib/modules/2.6.38-pf/kernel/drivers/scsi
/lib/modules/2.6.38-pf/kernel/drivers/scsi/scsi_mod.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/ata
/lib/modules/2.6.38-pf/kernel/drivers/ata/libata.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/ata/libahci.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/ata/ahci.ko.gz
/lib/modules/2.6.38-pf/kernel/drivers/scsi/sd_mod.ko.gz
/hooks
/hooks/resume
/lib/modules/2.6.38-pf/kernel/fs
/lib/modules/2.6.38-pf/kernel/fs/mbcache.ko.gz
/lib/modules/2.6.38-pf/kernel/fs/jbd2
/lib/modules/2.6.38-pf/kernel/fs/jbd2/jbd2.ko.gz
/lib/modules/2.6.38-pf/kernel/lib
/lib/modules/2.6.38-pf/kernel/lib/crc16.ko.gz
/lib/modules/2.6.38-pf/kernel/fs/ext4
/lib/modules/2.6.38-pf/kernel/fs/ext4/ext4.ko.gz
/lib/modules/2.6.38-pf/modules.dep
/lib/modules/2.6.38-pf/modules.alias
/lib/modules/2.6.38-pf/modules.symbols

Last edited by el mariachi (2011-04-24 14:14:23)

Offline

#3 2011-04-24 19:24:28

Stebalien
Member
Registered: 2010-04-27
Posts: 1,239
Website

Re: dinit - an alternative base/udev hook for mkinitcpio

uubase  works here but you should remind users that specifying the root device by label requires udev and therefore does not work with uubase.

Last edited by Stebalien (2011-04-24 19:25:11)


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C

Offline

#4 2011-04-24 19:27:50

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: dinit - an alternative base/udev hook for mkinitcpio

Stebalien wrote:

uubase  works here but you should remind users that specifying the root device by label requires udev and therefore does not work with uubase.

Good call. Updated the OP.

Offline

Board footer

Powered by FluxBB