]> git.ipfire.org Git - thirdparty/dracut.git/blame - init
[PATCH 43/50] Use ldd to find shared library deps.
[thirdparty/dracut.git] / init
CommitLineData
7f64a3fe 1#!/bin/sh
a5e56335
JK
2#
3# Licensed under the GPLv2
4#
5# Copyright 2008, Red Hat, Inc.
6# Jeremy Katz <katzj@redhat.com>
ec9315e5
JK
7
8emergency_shell()
9{
ca9f6259 10 echo ; echo
ec9315e5
JK
11 echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!"
12 echo
2a3efd82 13 exec sh -i
ec9315e5 14}
ec9315e5 15
04789195 16getarg() {
cd20f1f6 17 local o;
7f64a3fe
VL
18 for o in $(cat /proc/cmdline); do
19 [ "${o%%=*}" = "$1" ] && { echo $o; break; }
04789195 20 done
cd20f1f6
VL
21 return 1
22}
23
24source_all() {
25 local f
7f64a3fe
VL
26 [ "$1" ] && [ -d "/$1" ] || return
27 for f in "/$1"/*; do [ -f "$f" ] && . "$f"; done
04789195
VL
28}
29
ec9315e5
JK
30echo "Starting initrd..."
31export PATH=/sbin:/bin:/usr/sbin:/usr/bin
32export TERM=linux
33
7f64a3fe 34trap "emergency_shell" 0
ec9315e5
JK
35# /dev/console comes from the built-in initramfs crud in the kernel
36# someday, we may need to mkdir /dev first here
2a3efd82 37# exec > /dev/console 2>&1 < /dev/console
ec9315e5
JK
38
39# mount some important things
ec9315e5 40mount -t proc /proc /proc
ec9315e5
JK
41mount -t sysfs /sys /sys
42mount -t tmpfs -omode=0755 udev /dev
43
0c70846e 44# FIXME: what device nodes does plymouth really _need_ ?
0c70846e 45mknod /dev/ptmx c 5 2
7924b212 46mknod /dev/console c 5 0
0c70846e
JK
47mknod /dev/fb c 29 0
48mkdir /dev/pts
49mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
0c70846e
JK
50mknod /dev/tty0 c 4 0
51mknod /dev/tty1 c 4 1
bc6b0dec 52mknod /dev/null c 1 3
0c70846e 53
ec1ad334
VL
54source_all pre-udev
55
ec9315e5 56# start up udev and trigger cold plugs
09f9fec0 57udevd --daemon
bc6b0dec 58udevadm trigger >/dev/null 2>&1
ec9315e5 59
ec9315e5 60# mount the rootfs
35c5d61b 61NEWROOT="/sysroot"
ec9315e5 62
35c5d61b
JK
63# FIXME: there's got to be a better way ...
64# it'd be nice if we had a udev rule that just did all of the bits for
65# figuring out what the specified root is and linking it /dev/root
7f64a3fe 66root=$(getarg root); root=${root#root=}
f9a0b9f8
VL
67case $root in
68 LABEL=*) root=${root#LABEL=}
2a3efd82 69 root="$(echo $root |sed 's,/,\\x2f,g')"
f9a0b9f8
VL
70 root="/dev/disk/by-label/${root}" ;;
71 UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;;
72 '') echo "Warning: no root specified"
73 root="/dev/sda1" ;;
74esac
75
35c5d61b
JK
76# should we have a timeout?
77tries=0
7924b212
VL
78echo "Waiting up to 30 seconds for $root to become available"
79udevadm settle --timeout=30
ec1ad334 80source_all pre-mount
cd20f1f6 81
7924b212 82echo "Trying to mount rootfs $root"
7f64a3fe 83[ -e "$root" ] || emergency_shell
35c5d61b 84ln -s "$root" /dev/root
09bab2aa 85mount -o ro /dev/root $NEWROOT || emergency_shell
65e66984 86
ec9315e5
JK
87# now we need to prepare to switchroot
88mount --bind /dev $NEWROOT/dev
89
90# FIXME: now for a bunch of boiler-plate mounts. really, we should have
91# some like /etc/fstab.sys that's provided by filesystem/initscripts
92# and then do mount -f /etc/fstab.sys -a
93mount -t proc /proc $NEWROOT/proc
94mount -t sysfs /sys $NEWROOT/sys
95
ec1ad334 96source_all pre-pivot
ec9315e5 97
35c5d61b 98# kill off udev
8b691309 99kill $(pidof udevd)
0c70846e 100
ec9315e5 101# FIXME: nash die die die
09f9fec0 102exec switch_root
ec9315e5
JK
103# davej doesn't like initrd bugs
104echo "Something went very badly wrong in the initrd. Please "
105echo "file a bug against mkinitrd."
ed16343e 106sleep 100d
ec9315e5 107exit 1