From: Kay Sievers <kay.sievers-tD+1rO4QERM@public.gmane.org>
To: initramfs <initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: devtmpfs: kernel maintained /dev and initramfs
Date: Fri, 15 May 2009 15:20:36 +0200 [thread overview]
Message-ID: <1242393636.3108.37.camel@poy> (raw)
Just for your information, as it *might* make things a bit simpler in
the future.
I'm currently working on a kernel-maintained tmpfs-based /dev
filesystem:
http://git.kernel.org/?p=linux/kernel/git/kay/patches.git;a=blob;f=driver-core-devtmpfs-driver-core-maintained-dev-tmpfs.patch;hb=HEAD
It would de-couple the rather complex userspace logic from a minimal
working /dev, and lets current udev work on top of the kernel provided
nodes, instead of being a hard requirement to have anything useful
in /dev. It is intended to make things more robust and lets init=/bin/sh
work with a fully populated and working /dev.
The kernel will provide us a device node for every kernel device
currently registered, udev would apply the policy like mode, ownership,
and possibly create a different node, or delete the kernel-created one
if told to do.
It makes the initramfs logic much simpler and does not need a full
coldplug run to bootstrap /dev. If kernel device names are used, udev
does not even need to be started, and we can go straight ahead. A simple
and minimal example initramfs "init", to show what's needed is below.
Cheers,
Kay
#!/bin/sh
# minimal initramfs with persistent device name support
# requires devtmpfs support provided by the kernel
shell() {
echo "initramfs: dropping to shell"
exec >/dev/console 2>&1 </dev/console < /dev/console
sh -i
}
getarg() {
local o line
for o in $cmdline; do
test "$o" = "$1" && return 0
if test "${o%%=*}" = "${1%=}"; then
echo ${o#*=}
return 0
fi
done
return 1
}
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export TERM=linux
# console redirect to kernel log
exec >/dev/kmsg 2>&1 </dev/console
echo "initramfs: starting ..."
# mount needed filesystems
mount -t proc proc /proc
mount -t sysfs sysfs /sys
# prepare /dev
mount -t devtmpfs devtmpfs /dev
mkdir -m 0755 /dev/pts
mkdir /dev/pts
mount -t devpts -o gid=5,mode=620 devpts /dev/pts
# kernel commandline
read cmdline </proc/cmdline;
# root we are looking for
root=$(getarg root=)
echo "initramfs: looking for $root"
# shortcut, in case root is already there
if test -e "$root"; then
echo "initramfs: mounting $root"
mount "$root" /root
mounted=yes
fi
# we need to start udev to create the symlink we are looking for
if test -z "$mounted"; then
echo "initramfs: starting udev"
udevd --daemon --resolve-names=never
# create links for already existing block devices
echo "initramfs: trigger block and module events"
udevadm trigger --subsystem-match=block
udevadm trigger --attr-match=modalias
echo "initramfs: waiting for $root"
# loop until root shows up
while test -z "$mounted"; do
if test -e "$root"; then
echo "initramfs: mounting $root"
mount "$root" /root && mounted=yes
fi
sleep 0.05
done
# kill udev
kill $(pidof udevd) >/dev/null 2>&1
fi
# move filesystems over to the mounted root
mount --move /dev /root/dev
mount --move /proc /root/proc
mount --move /sys /root/sys
# move into root
cd /root
init=$(getarg init=)
test -z "$init" && init=/sbin/init
echo "initramfs: switching to root filesystem $root and start $init"
exec run-init -c /dev/console /root $init
--
To unsubscribe from this list: send the line "unsubscribe initramfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
reply other threads:[~2009-05-15 13:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1242393636.3108.37.camel@poy \
--to=kay.sievers-td+1ro4qerm@public.gmane.org \
--cc=initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox