]>
git.ipfire.org Git - ipfire-3.x.git/blob - src/mkinitramfs/mkliveramfs
6bdc82d4bff388c38b2f15327524221fd89104b9
2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2008, 2009 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
22 .
/usr
/lib
/mkinitramfs
/functions
24 # Modules needed by the live system
25 MODULES
="$MODULES aufs squashfs loop"
27 # Add all storage modules
28 for module
in /lib
/modules
/$KERNEL/kernel
/drivers
/{ata
,message
/fusion
,pcmcia
,scsi
{,/*}}/*; do
29 MODULES
="$MODULES $(basename ${module/.ko})"
31 ## XXX need to add support for usb cdroms
34 mkdir
-p mnt
/{source,tmpfs
,overlayfs
,squashfs
}
36 cat >> sbin
/real-init
<<'EOF'
37 # Users can override rootfs target on the kernel commandline
38 for o in $(cat /proc/cmdline); do
44 rootflags=${o#rootflags=}
47 rootfstype=${o#rootfstype=}
52 # generate udev rules to generate /dev/root symlink
53 if [ -z $root ] ; then
58 LABEL=${root#/dev/disk/by-label/}
59 echo "SUBSYSTEM==\"block\", PROGRAM=\"/lib/udev/vol_id -l %N\", RESULT==\"$LABEL\", SYMLINK+=\"root\"" > /etc/udev/rules.d/00-label.rules
61 echo "Added udev rule 00-label.rules:"
62 cat /etc/udev/rules.d/00-label.rules
64 thingtomount=/dev/root
67 CDLABEL=${root#CDLABEL=}
68 echo "KERNEL==\"hd[a-z]\", BUS==\"ide\", SYSFS{removable}==\"1\", ATTRS{media}==\"cdrom\", PROGRAM=\"/lib/udev/vol_id -l %N\", RESULT==\"$CDLABEL\", SYMLINK+=\"root\"" > /etc/udev/rules.d/00-cdlabel.rules
69 echo "KERNEL==\"sr[0-9]\", PROGRAM=\"/lib/udev/vol_id -l %N\", RESULT==\"$CDLABEL\", SYMLINK+=\"root\"" >> /etc/udev/rules.d/00-cdlabel.rules
70 echo "KERNEL==\"scd[0-9]\", PROGRAM=\"/lib/udev/vol_id -l %N\", RESULT==\"$CDLABEL\", SYMLINK+=\"root\"" >> /etc/udev/rules.d/00-cdlabel.rules
71 echo "KERNEL==\"pcd[0-9]\", PROGRAM=\"/lib/udev/vol_id -l %N\", RESULT==\"$CDLABEL\", SYMLINK+=\"root\"" >> /etc/udev/rules.d/00-cdlabel.rules
73 echo "Added udev rule 00-cdlabel.rules:"
74 cat /etc/udev/rules.d/00-cdlabel.rules
76 thingtomount=/dev/root
80 echo "SUBSYSTEM==\"block\", PROGRAM=\"/lib/udev/vol_id -l %N\", RESULT==\"$LABEL\", SYMLINK+=\"root\"" > /etc/udev/rules.d/00-label.rules
82 echo "Added udev rule 00-label.rules:"
83 cat /etc/udev/rules.d/00-label.rules
85 thingtomount=/dev/root
88 UUID=${root#/dev/disk/by-id/}
89 echo "SUBSYSTEM==\"block\", PROGRAM=\"/lib/udev/vol_id -u %N\", RESULT==\"$UUID\", SYMLINK+=\"root\"" > /etc/udev/rules.d/01-uuid.rules
91 echo "Added udev rule 01-uuid.rules:"
92 cat /etc/udev/rules.d/01-uuid.rules
94 thingtomount=/dev/root
98 echo "SUBSYSTEM==\"block\", PROGRAM=\"/lib/udev/vol_id -u %N\", RESULT==\"$UUID\", SYMLINK+=\"root\"" > /etc/udev/rules.d/01-uuid.rules
100 echo "Added udev rule 01-uuid.rules:"
101 cat /etc/udev/rules.d/01-uuid.rules
103 thingtomount=/dev/root
106 ln -s $root /dev/root
115 echo "udev_log=\"error\"" >> /etc/udev/udev.conf
117 # rules for loading modules
118 echo -n "ACTION==\"add\", SUBSYSTEM==\"?*\", ENV{MODALIAS}==\"?*\", RUN+=\"/sbin/modprobe $" >> /etc/udev/rules.d/10-modprobe.rules
119 echo "env{MODALIAS}\"" >> /etc/udev/rules.d/10-modprobe.rules
120 echo "ACTION==\"add\", SUBSYSTEM==\"scsi_device\" RUN+=\"/sbin/modprobe sg\"" >> /etc/udev/rules.d/10-modprobe.rules
121 echo "ACTION==\"add\", SUBSYSTEM==\"scsi_device\", SYSFS{type}==\"0|7|14\", RUN+=\"/sbin/modprobe sd_mod\"" >> /etc/udev/rules.d/10-modprobe.rules
122 echo "ACTION==\"add\", SUBSYSTEM==\"scsi_device\", SYSFS{type}==\"[45]\", RUN+=\"/sbin/modprobe sr_mod\"" >> /etc/udev/rules.d/10-modprobe.rules
123 echo "SUBSYSTEM==\"mmc\", RUN+=\"/sbin/modprobe mmc_block\"" >> /etc/udev/rules.d/10-modprobe.rules
125 # FIXME: hack since sr_mod seems to fail to get loaded sometimes (#239657)
128 modprobe loop max_loop=16
130 vecho "Starting udevd..."
133 vecho "Creating devices..."
136 vecho "Waiting for system to settle..."
137 udevadm settle --timeout=30 || :
139 if [ "$SHELL" == "1" ] ; then
140 echo "Shell requested on kernel commandline. Exit to continue booting."
145 # Wait 60 seconds for /dev/root to appear.
147 while [ "x$COUNTDOWN" != "x0" ] ; do
148 is_verbose && echo -n "."
150 if [ -e /dev/root ]; then
154 # this is kind of lame, but we could have had a situation
155 # where we were unable to read the volume id. so trigger
156 # another run through the block devs
157 if [ "x$COUNTDOWN" = "x30" ]; then
158 udevadm trigger --subsystem-match=block
161 COUNTDOWN=$(($COUNTDOWN - 1))
166 if [ ! -b /dev/root ] ; then
168 echo "--------------------------------------"
169 echo "WARNING: Cannot find root file system!"
170 echo "--------------------------------------"
172 echo "Create symlink /dev/root and then exit this shell to continue"
173 echo "the boot sequence."
179 vecho "Mounting /dev/root..."
183 if [ "x$READONLY" == "x1" ] ; then
184 rootflags="$rootflags,ro"
186 rootflags="$rootflags,rw"
189 if [ -n $rootflags ]; then
190 mountoptions=" -o$rootflags"
193 mount -n -t $rootfstype $mountoptions $thingtomount /mnt/source
196 if [ "$RES" != "0" ]; then
197 echo "---------------------------------"
198 echo "WARNING: Cannot mount rootfs!"
199 echo "---------------------------------"
201 echo "Dropping to a shell. "
202 echo "Mount /mnt/source and exit shell to continue. Good luck!"
207 mount -n -t tmpfs none /mnt/tmpfs
208 aufsmountoptions="br:/mnt/tmpfs=rw"
210 OVERLAY=$(ls /mnt/source/*.overlay 2>/dev/null || true)
211 if [ -n "$OVERLAY" ]; then
212 vecho "Setting up overlay for squashfs..."
213 mount -t squashfs -o loop,ro $OVERLAY /mnt/overlayfs
214 aufsmountoptions="$aufsmountoptions:/mnt/overlayfs=rr"
217 SQUASHED=$(ls /mnt/source/*.img 2>/dev/null || true)
218 if [ -n "$SQUASHED" ] ; then
219 vecho "Setting up embedded squashfs..."
220 mount -t squashfs -o loop,ro $SQUASHED /mnt/squashfs
221 aufsmountoptions="$aufsmountoptions:/mnt/squashfs=rr"
224 mount -t aufs -o $aufsmountoptions none /sysroot
226 for i in $(cd /mnt; ls); do
227 mountpoint /mnt/$i >/dev/null || continue
228 mkdir -p /sysroot/mnt/$i || :
229 mount --move /mnt/$i /sysroot/mnt/$i
232 if [ "$ESHELL" == "1" ]; then
233 echo "Shell requested on kernel commandline."
234 echo "Rootfs is mounted ro on /sysroot. Exit to continue booting."
239 if [ -x /sysroot$init ]; then
240 # Leave initramfs and transition to rootfs
242 vecho "Transfering control to $init"
244 exec switchroot $(get_verbose) /sysroot
245 echo "---------------------------------"
246 echo "WARNING: Error switching to real rootfs!"
247 echo "---------------------------------"
249 echo "Dropping to a shell. Good luck!"
253 echo "---------------------------------------------------------"
254 echo "WARNING: Requested $init binary does not exist on rootfs."
255 echo "---------------------------------------------------------"
257 echo "Dropping to a shell. Good luck!"