1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
#!/bin/sh
#
# $Source: /cvsroot/bootcd/bootcd/bootcdmkinitrd,v $
# $Id: bootcdmkinitrd,v 1.26 2006-11-27 15:53:57 bs Exp $
# author: Bernd Schumacher
# start: long time ago
# topic: build new initrd
#
# comment: more informations in man page bootcdmkinitrd(1)
#
KERNEL=/vmlinuz
INITRD=/initrd.img
ETCMKI=/etc/mkinitrd
ERRLOG=/var/log/errlog
# install the bootloader
INSTBOOTLOAD="yes"
# the next neutral PATH-Prefix is used to mark entries in /etc/mkinitrd/*
# done by bootcdmkinitrd
MARK="/usr/share/bootcd/../../.."
# ---------------------- nothing to configure behind this line ---------------
# include lib
. /usr/share/bootcd/bootcd-run.lib
SCRIPT=""
if [ $# -gt 0 ]; then
[ "$1" = "-s" ] && SCRIPT="$1"
fi
# Warning
set -u
if [ ! "$SCRIPT" ]; then
echo "Warning: this script assumes the following:"
echo "- the running kernel is the one that will be used on bootcd"
echo "- initrd is used"
echo "Warning: this script will do the following:"
echo "- /etc/mkinitrd/ will be changed."
echo "- mkinitrd will be called. This will change $INITRD."
echo "- your bootloader will be called."
echo "The debian package bootcd-mkinitrd containing the command"
echo "bootcdmkinitrd is superseeded by bootcd-mkinitramfs."
while :; do
echo "OK to continue ? (y|n) "
read A
[ "$A" = "n" ] && exit
[ "$A" = "y" ] && break
done
fi
# Checks
if [ \( -f /sbin/grub -o -f /usr/sbin/grub \) -a -f /sbin/lilo ]; then
while :; do
echo "Grub and lilo is installed. Which do you use ? (g|l) "
read BOOTLOAD
[ "$BOOTLOAD" = "l" ] && break
[ "$BOOTLOAD" = "g" ] && break
done
elif [ -f /sbin/grub -o -f /usr/sbin/grub ]; then
BOOTLOAD="g"
echo "Using grub"
elif [ -f /sbin/lilo ]; then
BOOTLOAD="l"
echo "Using lilo"
else
err "Error: No Bootloader found"
fi
if [ "$BOOTLOAD" = "l" ]; then
[ ! "$(grep "^[[:blank:]]*initrd=" /etc/lilo.conf)" ] && err "/etc/lilo.conf has no line initrd=. This means that you are not using lilo, or that you are not using initrd. This skript only works with lilo and initrd."
[ ! "$(grep "^[[:blank:]]*initrd[[:blank:]]*=[[:blank:]]*/initrd.img[[:blank:]]*$" /etc/lilo.conf)" ] && err "Your /etc/lilo.conf has no line with initrd=/initrd.img. Because this script can only support standard configurations, please edit lilo.conf run lilo and reboot to test your configuration. Then run this script again."
fi
# check for kernel version and initrd-version
k_vers=$(realpath $KERNEL|cut -d"-" -f2-)
[ ! "$k_vers" ] && err "Can't determine the kernel version ... does \"$KERNEL\" exists?"
i_vers=$(realpath $INITRD|cut -d"-" -f2-)
[ ! "$i_vers" ] && err "Can't determine the initrd version ... does \"$INITRD\" exists?"
if [ $(uname -r) != "$k_vers" ]; then
warn "The running kernel ("$(uname -r)") is not the target kernel ($k_vers), works but don't call lilo!"
INSTBOOTLOAD="no"
fi
[ "$k_vers" != "$i_vers" ] && err "The kernel version ($k_vers) differs from the initrd version ($i_vers)!"
if [ ! -d $ETCMKI ]; then
echo "ERROR: No mkinitrd config dir $ETCMKI." >&2
echo " Is initrd-tools.deb installed ?" >&2
exit 1
fi
[ ! -f $INITRD ] && err "$INITRD does not exist."
if [ "$(discover --version 2>/dev/null | grep "discover 2\..*")" ]; then
DISCOVERV=2
else
DISCOVERV=1
fi
# Start
[ -f /etc/mkinitrd.tgz ] && mv /etc/mkinitrd.tgz /etc/mkinitrd.tgz.old
(cd /etc; tar czf mkinitrd.tgz mkinitrd)
# modify mkinitrd.conf
F=/etc/mkinitrd/mkinitrd.conf
touch $F
cp $F $F.tmp
cat $F.tmp | sed "s/^BUSYBOX=.*/BUSYBOX=yes/" >$F
rm $F.tmp
# modify exe
F=/etc/mkinitrd/exe
touch $F
cp $F $F.tmp
(
cat $F.tmp | grep -v "^$MARK"
[ -f /sbin/discover ] && echo "/sbin/discover"
[ -f /bin/discover ] && echo "/bin/discover"
[ -f /usr/bin/discover ] && echo "/usr/bin/discover"
ls /bin/grep
) | sort -u | sed "s|^|$MARK|" >$F
rm $F.tmp
# modules
F=/etc/mkinitrd/modules
touch $F
cp $F $F.tmp
awk '
!/^cdrom$/ &&
!/^isofs$/ {
print
}
' < $F.tmp >$F
echo "cdrom" >>$F
echo "isofs" >>$F
rm $F.tmp
# files
F=/etc/mkinitrd/files
touch $F
cp $F $F.tmp
(
cat $F.tmp | grep -v "^$MARK"
ls /usr/share/discover/*.lst
ls /usr/share/bootcd/bootcdmodprobe # see prerm
ls /usr/share/bootcd/bootcdproberoot # see prerm
ls /lib/modules/$k_vers/kernel/drivers/usb/host/*.*o # match *.o and *.ko
ls /lib/modules/$k_vers/kernel/drivers/usb/core/usbcore.*o # used for 2.6
ls /lib/modules/$k_vers/kernel/drivers/usb/usbcore.*o # used for 2.4
ls /lib/modules/$k_vers/kernel/drivers/usb/storage/usb-storage.*o
ls /lib/modules/$k_vers/kernel/drivers/cdrom/cdrom.*o
ls /lib/modules/$k_vers/kernel/drivers/scsi/scsi_mod.*o
ls /lib/modules/$k_vers/kernel/fs/nls/*.*o
# extra data for discover 2
for i in libdiscover2 discover-data discover;
do
[ -f /var/lib/dpkg/info/$i.list ] || continue
(
cat /var/lib/dpkg/info/$i.list |
grep -v "^/usr/share/doc" | # no docu
grep -v "^/usr/share/man" | # no manpages
grep -v "^/lib/" | # libs will be taken by mkinitrd
grep -v "^/usr/lib/" | # libs will be taken by mkinitrd
grep -v "^/bin/" | # goes to exe if needed
grep -v "^/usr/bin/" | # goes to exe if needed
grep -v "^/sbin/" | # goes to exe if needed
grep -v "^/usr/sbin/" # goes to exe if needed
cat /var/lib/dpkg/info/$i.list |
grep "/lib/discover/" # we need discover xml data
) |
while read f; do
[ -d $f ] && continue # no dirs
echo "$f"
done
done
) | sort -u | sed "s|^|$MARK|" >$F
rm $F.tmp
# 50bootcddiscover
F1=/etc/mkinitrd/scripts/50bootcddiscover # see prerm
cat <<end1 >$F1
#!/bin/sh
F2=\$INITRDDIR/scripts/bootcd
cat <<end2 >\$F2
/bin/echo "running /scripts/bootcd" >&2
mount -nt proc proc proc
/usr/share/bootcd/bootcdmodprobe
umount proc
end2
chmod 755 \$F2
end1
chmod 755 $F1
# 60bootcdproberoot
F1=/etc/mkinitrd/scripts/60bootcdproberoot # see prerm
cat <<END1 >$F1
#!/bin/sh
F2=\$INITRDDIR/scripts/getrootdev
cat <<END2 >\$F2
mount -nt proc proc proc
mount -nt tmpfs tmpfs dev2 > /dev/null 2>&1 || mount -nt ramfs ramfs dev2
/usr/share/bootcd/bootcdproberoot
umount dev2
umount proc
END2
chmod 755 \$F2
END1
chmod 755 $F1
# build initrd
mkinitrd -k -o /initrd.img $k_vers
if [ "INSTBOOTLOAD" = "yes" ]; then
[ "$BOOTLOAD" = "l" ] && lilo || update-grub
fi
echo "new initrd for kernel version \"$k_vers\" created."
# Warning
[ "INSTBOOTLOAD" = "yes" ] && echo "Please reboot now, before using bootcdwrite"
|