]> git.ipfire.org Git - ipfire-3.x.git/blob - src/mkinitramfs/mkinitramfs
Added some nice things on mkinitramfs.
[ipfire-3.x.git] / src / mkinitramfs / mkinitramfs
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008, 2009 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 . /usr/lib/mkinitramfs/functions
23
24 # Add usb support
25 MODULES="$MODULES ehci-hcd ohci-hcd uhci-hcd"
26
27 # Get rootfs and options
28 rootdev=$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' /etc/fstab)
29 rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' /etc/fstab)
30 rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/fstab)
31 [ -z "$rootopts" ] && rootopts="defaults"
32
33 installmodule --load $rootfs
34
35 if [[ "$rootdev" =~ "^(UUID=|LABEL=)" ]]; then
36 rootdev=$(resolve_device_name "$rootdev")
37 fi
38
39 rootopts=$(echo $rootopts | sed -e 's/^r[ow],//' -e 's/,_netdev//' \
40 -e 's/_netdev//' -e 's/,r[ow],$//' -e 's/,r[ow],/,/' \
41 -e 's/^r[ow]$/defaults/' -e 's/$/,ro/')
42 physdev=$(findblockdevinsys "$rootdev")
43 physdev=${physdev##*/dev/}
44 if [ -n "$physdev" ]; then
45 vecho "[INFO] Found root device $physdev for $rootdev"
46 else
47 physdev="$rootdev"
48 fi
49
50 if [ -n "$physdev" -a "$physdev" != "$rootdev" ]; then
51 findstoragedriver ${physdev##/dev/}
52 fi
53
54 findstoragedriver ${rootdev##/dev/}
55
56 cat >> sbin/real-init <<EOF
57
58 #rootdev=$rootdev
59 #rootfstype=$rootfs
60 #rootopts=$rootopts
61 EOF
62
63 cat >> sbin/real-init <<'EOF'
64
65 # Users can override rootfs target on the kernel commandline
66 for o in $(cat /proc/cmdline); do
67 case $o in
68 root=*)
69 rootdev=${o#root=}
70 ;;
71 rootflags=*)
72 rootflags=${o#rootflags=}
73 ;;
74 rootfstype=*)
75 rootfstype=${o#rootfstype=}
76 ;;
77 esac
78 done
79
80 vecho "Starting udevd..."
81 udevd --daemon
82
83 vecho "Creating devices..."
84 udevadm trigger
85
86 vecho "Mounting root filesystem $rootdev..."
87 [ -n "$rootopts" ] && rootopts="-o $rootopts"
88 [ -n "$rootfstype" ] && rootopts="-t $rootfstype $rootopts"
89 mount $rootdev /sysroot $rootopts
90
91 kill $(pidof udevd)
92
93 vecho "Switching to new root and running init..."
94 exec switchroot $(get_verbose) /sysroot
95
96 echo exec switchroot failed...
97 bash
98 EOF
99
100 finalize