1 |
beyerle@PS |
1 |
#!/bin/bash
|
|
|
2 |
# initrd_create: make initrd rootdisk by using busybox
|
|
|
3 |
#
|
|
|
4 |
# Author: Tomas M. <http://www.linux-live.org>
|
|
|
5 |
#
|
|
|
6 |
# added by Urs Beyerle, PSI:
|
|
|
7 |
#
|
|
|
8 |
# add modules: nfs, sunrpc, lockd, nfs_acl (found in nfs_common)
|
|
|
9 |
# add drivers/net
|
|
|
10 |
# add x86_64 support
|
|
|
11 |
# add sata modules: ata_piix, libata
|
|
|
12 |
# add module: jbd
|
|
|
13 |
# add module: sr_mod
|
|
|
14 |
# unionctl.static can be installed locally
|
|
|
15 |
# add module ahci
|
|
|
16 |
# add module forcedeth
|
|
|
17 |
# source ../../livecd.conf instead of ../config
|
|
|
18 |
# changes need for SL5:
|
|
|
19 |
# - initrd blocksize to 4096 (instead of 1024)
|
|
|
20 |
# - add fscache (for NFS support)
|
|
|
21 |
# - add ide-cd, cdrom (for CD-ROM support)
|
23 |
beyerle@PS |
22 |
# read $KERNEL from $1, can overwrite setting in livecd.conf
|
39 |
beyerle@PS |
23 |
# add aufs (replacement for unionfs)
|
|
|
24 |
# add rev to static-binaries (for unionctl of aufs)
|
1 |
beyerle@PS |
25 |
#
|
|
|
26 |
|
|
|
27 |
# . ../config || exit 1
|
23 |
beyerle@PS |
28 |
|
1 |
beyerle@PS |
29 |
. ../../livecd.conf || exit 1
|
|
|
30 |
|
23 |
beyerle@PS |
31 |
# set an other kernel than the one set in livecd.conf
|
|
|
32 |
[ "$1" ] && KERNEL=$1
|
1 |
beyerle@PS |
33 |
echo "take blocksize=$INITRD_BLOCKSIZE for initrd"
|
|
|
34 |
|
|
|
35 |
# arch
|
|
|
36 |
ARCH=$( /bin/arch )
|
|
|
37 |
[ "$ARCH" != "x86_64" ] && ARCH=i686
|
|
|
38 |
|
23 |
beyerle@PS |
39 |
|
|
|
40 |
|
1 |
beyerle@PS |
41 |
# rcopy is a recursive cp, which copies also symlink's real source
|
|
|
42 |
# $1 = source (may be a regular file or symlink)
|
|
|
43 |
# $2 = target PARENT
|
|
|
44 |
#
|
|
|
45 |
rcopy()
|
|
|
46 |
{
|
|
|
47 |
if [ -L "$1" ]; then
|
|
|
48 |
REALPATH="`readlink -f \"$1\"`"
|
|
|
49 |
cp --parent -R "$REALPATH" "$2"
|
|
|
50 |
ln -sf "$REALPATH" "$2/$1"
|
|
|
51 |
else
|
|
|
52 |
cp --parent -R "$1" "$2"
|
|
|
53 |
fi
|
|
|
54 |
if [ "$?" -ne 0 ]; then
|
|
|
55 |
echo "---------------------------"
|
|
|
56 |
echo "Error occured while trying to copy \"$1\" to \"$2\""
|
|
|
57 |
echo "nevertheless your LiveCD may still work."
|
|
|
58 |
echo "Possible reason: not enough free space in initrd or source doesn't exist"
|
|
|
59 |
echo "---------------------------"
|
|
|
60 |
fi
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
# copy file/dir only if it exists, else skip with no error
|
|
|
64 |
# $1 = source (may not exist)
|
|
|
65 |
# $2 = target PARENT
|
|
|
66 |
#
|
|
|
67 |
rcopy_ex()
|
|
|
68 |
{
|
|
|
69 |
if [ -a "$1" ]; then
|
|
|
70 |
rcopy "$1" "$2"
|
|
|
71 |
fi
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
debug()
|
|
|
75 |
{
|
|
|
76 |
# uncomment to show debug messages
|
|
|
77 |
# echo "$@"
|
|
|
78 |
return 0
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
##################################################
|
|
|
82 |
# Create INITRD image now:
|
|
|
83 |
|
|
|
84 |
MOUNTDIR=/tmp/initrd_mountdir_$$
|
|
|
85 |
INITRD_TREE=/tmp/initrd_tree_$$
|
|
|
86 |
|
|
|
87 |
LMK="lib/modules/$KERNEL"
|
|
|
88 |
|
39 |
beyerle@PS |
89 |
UNIONFS_TYPE=""
|
|
|
90 |
|
|
|
91 |
if [ -e /$LMK/kernel/fs/unionfs/unionfs.ko ] || \
|
|
|
92 |
[ -e kernel-modules/${KERNEL}_$ARCH/unionfs.ko.gz ]; then
|
|
|
93 |
UNIONFS_TYPE="unionfs"
|
1 |
beyerle@PS |
94 |
fi
|
39 |
beyerle@PS |
95 |
if [ -e /$LMK/kernel/fs/aufs/aufs.ko ] || \
|
|
|
96 |
[ -e kernel-modules/${KERNEL}_$ARCH/aufs.ko.gz ]; then
|
|
|
97 |
UNIONFS_TYPE="aufs"
|
|
|
98 |
fi
|
|
|
99 |
if [ ! $UNIONFS_TYPE ]; then
|
|
|
100 |
echo "ERROR: Neither aufs nor unionfs kernel module not found."
|
|
|
101 |
exit 1
|
|
|
102 |
fi
|
1 |
beyerle@PS |
103 |
|
|
|
104 |
if [ ! -e /$LMK/kernel/fs/squashfs/squashfs.ko ] && \
|
|
|
105 |
[ ! -e kernel-modules/${KERNEL}_$ARCH/squashfs.ko.gz ]; then
|
|
|
106 |
echo "ERROR: Squashfs kernel module not found."
|
|
|
107 |
exit 1
|
|
|
108 |
fi
|
|
|
109 |
|
|
|
110 |
debug "creating directories"
|
|
|
111 |
mkdir -p $INITRD_TREE/{etc,dev,bin,mnt,livecd,proc,lib,sbin,sys,tmp,var/log}
|
|
|
112 |
|
|
|
113 |
debug "creating some essential devices in rootdisk"
|
|
|
114 |
mknod $INITRD_TREE/dev/console c 5 1
|
|
|
115 |
mknod $INITRD_TREE/dev/null c 1 3
|
|
|
116 |
mknod $INITRD_TREE/dev/ram b 1 1
|
|
|
117 |
mknod $INITRD_TREE/dev/systty c 4 0
|
|
|
118 |
mknod $INITRD_TREE/dev/tty c 5 0
|
69 |
beyerle@PS |
119 |
for i in 1 2 3 4 5 6; do
|
|
|
120 |
mknod $INITRD_TREE/dev/tty$i c 4 $i;
|
|
|
121 |
done
|
1 |
beyerle@PS |
122 |
|
|
|
123 |
loops=255
|
|
|
124 |
while [ $loops -ge 0 ]; do
|
|
|
125 |
mknod $INITRD_TREE/dev/loop$loops b 7 $loops
|
|
|
126 |
loops=$(($loops-1))
|
|
|
127 |
done
|
|
|
128 |
|
|
|
129 |
debug "copying files to the rootdisk"
|
|
|
130 |
touch $INITRD_TREE/etc/{m,fs}tab
|
|
|
131 |
cp {linuxrc,liblinuxlive} $INITRD_TREE # symlink will be copied as original file
|
|
|
132 |
chmod a+x $INITRD_TREE/linuxrc
|
|
|
133 |
|
|
|
134 |
cp static-binaries/modprobe $INITRD_TREE/sbin
|
|
|
135 |
cp static-binaries/busybox $INITRD_TREE/bin
|
|
|
136 |
cp static-binaries/unionctl_${ARCH} $INITRD_TREE/bin/unionctl
|
|
|
137 |
[ -x /usr/sbin/unionctl.static ] && cp -a /usr/sbin/unionctl.static $INITRD_TREE/bin/unionctl
|
|
|
138 |
ln -s busybox $INITRD_TREE/bin/ash
|
|
|
139 |
ln -s busybox $INITRD_TREE/bin/sh
|
|
|
140 |
ln -s busybox $INITRD_TREE/bin/[
|
|
|
141 |
|
|
|
142 |
# dhcp startup script
|
|
|
143 |
cp static-binaries/udhcpc.script $INITRD_TREE/bin
|
|
|
144 |
ln -s ../bin/busybox $INITRD_TREE/sbin/ifconfig
|
|
|
145 |
|
|
|
146 |
# lspci and pcitable for network card detection
|
37 |
beyerle@PS |
147 |
cp static-binaries/lspci $INITRD_TREE/sbin
|
1 |
beyerle@PS |
148 |
cp static-binaries/pcitable $INITRD_TREE/bin
|
|
|
149 |
|
39 |
beyerle@PS |
150 |
# rev needed for unionctl of aufs
|
|
|
151 |
if [ "$UNIONFS_TYPE" = "aufs" ]; then
|
|
|
152 |
cp static-binaries/rev $INITRD_TREE/bin
|
|
|
153 |
fi
|
1 |
beyerle@PS |
154 |
|
|
|
155 |
LMK="lib/modules/$KERNEL"
|
|
|
156 |
|
39 |
beyerle@PS |
157 |
# necessary modules and dependency files
|
1 |
beyerle@PS |
158 |
mkdir -p $INITRD_TREE/$LMK/kernel/fs
|
|
|
159 |
cp kernel-modules/${KERNEL}_$ARCH/unionfs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/null
|
37 |
beyerle@PS |
160 |
cp kernel-modules/${KERNEL}_$ARCH/aufs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/null
|
1 |
beyerle@PS |
161 |
cp kernel-modules/${KERNEL}_$ARCH/squashfs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/null
|
|
|
162 |
rcopy_ex /$LMK/kernel/fs/unionfs $INITRD_TREE 2>/dev/null
|
37 |
beyerle@PS |
163 |
rcopy_ex /$LMK/kernel/fs/aufs $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
164 |
rcopy_ex /$LMK/kernel/fs/squashfs $INITRD_TREE 2>/dev/null
|
|
|
165 |
|
39 |
beyerle@PS |
166 |
# copy filesystem modules, if not directly copied into kernel
|
1 |
beyerle@PS |
167 |
rcopy_ex /$LMK/kernel/lib/zlib_inflate $INITRD_TREE 2>/dev/null
|
|
|
168 |
rcopy_ex /$LMK/kernel/drivers/block/loop* $INITRD_TREE 2>/dev/null
|
|
|
169 |
|
|
|
170 |
rcopy_ex /$LMK/kernel/fs/isofs $INITRD_TREE 2>/dev/null
|
|
|
171 |
rcopy_ex /$LMK/kernel/fs/fat $INITRD_TREE 2>/dev/null
|
|
|
172 |
rcopy_ex /$LMK/kernel/fs/vfat $INITRD_TREE 2>/dev/null
|
|
|
173 |
rcopy_ex /$LMK/kernel/fs/ntfs $INITRD_TREE 2>/dev/null
|
|
|
174 |
rcopy_ex /$LMK/kernel/fs/ext3 $INITRD_TREE 2>/dev/null
|
|
|
175 |
rcopy_ex /$LMK/kernel/fs/jbd $INITRD_TREE 2>/dev/null
|
|
|
176 |
|
|
|
177 |
# for NFS support
|
|
|
178 |
rcopy_ex /$LMK/kernel/fs/nfs $INITRD_TREE 2>/dev/null
|
|
|
179 |
rcopy_ex /$LMK/kernel/fs/nfs_common $INITRD_TREE 2>/dev/null
|
|
|
180 |
rcopy_ex /$LMK/kernel/fs/lockd $INITRD_TREE 2>/dev/null
|
|
|
181 |
rcopy_ex /$LMK/kernel/fs/fscache $INITRD_TREE 2>/dev/null
|
|
|
182 |
rcopy_ex /$LMK/kernel/net/sunrpc $INITRD_TREE 2>/dev/null
|
|
|
183 |
rcopy_ex /$LMK/kernel/net/sunrpc $INITRD_TREE 2>/dev/null
|
|
|
184 |
|
|
|
185 |
# net drivers
|
|
|
186 |
rcopy_ex /$LMK/kernel/drivers/net/mii.ko $INITRD_TREE 2>/dev/null
|
|
|
187 |
rcopy_ex /$LMK/kernel/drivers/net/3c59x.ko $INITRD_TREE 2>/dev/null
|
|
|
188 |
rcopy_ex /$LMK/kernel/drivers/net/8139cp.ko $INITRD_TREE 2>/dev/null
|
|
|
189 |
rcopy_ex /$LMK/kernel/drivers/net/8139too.ko $INITRD_TREE 2>/dev/null
|
|
|
190 |
rcopy_ex /$LMK/kernel/drivers/net/8390.ko $INITRD_TREE 2>/dev/null
|
|
|
191 |
rcopy_ex /$LMK/kernel/drivers/net/e1000/e1000.ko $INITRD_TREE 2>/dev/null
|
|
|
192 |
rcopy_ex /$LMK/kernel/drivers/net/e100.ko $INITRD_TREE 2>/dev/null
|
|
|
193 |
rcopy_ex /$LMK/kernel/drivers/net/ns83820.ko $INITRD_TREE 2>/dev/null
|
|
|
194 |
rcopy_ex /$LMK/kernel/drivers/net/tg3.ko $INITRD_TREE 2>/dev/null
|
|
|
195 |
rcopy_ex /$LMK/kernel/drivers/net/pcnet32.ko $INITRD_TREE 2>/dev/null
|
|
|
196 |
rcopy_ex /$LMK/kernel/drivers/net/tulip/tulip.ko $INITRD_TREE 2>/dev/null
|
|
|
197 |
rcopy_ex /$LMK/kernel/drivers/net/b44.ko $INITRD_TREE 2>/dev/null
|
|
|
198 |
rcopy_ex /$LMK/kernel/drivers/net/sk98lin/sk98lin.ko $INITRD_TREE 2>/dev/null
|
|
|
199 |
rcopy_ex /$LMK/kernel/drivers/net/sky2.ko $INITRD_TREE 2>/dev/null
|
|
|
200 |
rcopy_ex /$LMK/kernel/drivers/net/forcedeth.ko $INITRD_TREE 2>/dev/null
|
|
|
201 |
rcopy_ex /$LMK/updates/drivers/net/sky2/sky2.ko $INITRD_TREE 2>/dev/null
|
|
|
202 |
|
|
|
203 |
# add language support for filesystems
|
69 |
beyerle@PS |
204 |
# rcopy_ex /$LMK/kernel/fs/nls/ $INITRD_TREE 2>/dev/null
|
|
|
205 |
rcopy_ex /$LMK/kernel/fs/nls/nls_cp437.* $INITRD_TREE 2>/dev/null
|
|
|
206 |
rcopy_ex /$LMK/kernel/fs/nls/nls_iso8859-1.* $INITRD_TREE 2>/dev/null
|
|
|
207 |
rcopy_ex /$LMK/kernel/fs/nls/nls_iso8859-2.* $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
208 |
|
|
|
209 |
# cdrom support (for SL5)
|
|
|
210 |
rcopy_ex /$LMK/kernel/drivers/ide/ide-cd.ko $INITRD_TREE 2>/dev/null
|
|
|
211 |
rcopy_ex /$LMK/kernel/drivers/cdrom/cdrom.ko $INITRD_TREE 2>/dev/null
|
|
|
212 |
|
|
|
213 |
# usb modules
|
|
|
214 |
rcopy_ex /$LMK/kernel/drivers/usb/storage $INITRD_TREE 2>/dev/null
|
|
|
215 |
rcopy_ex /$LMK/kernel/drivers/usb/host/ehci-hcd* $INITRD_TREE 2>/dev/null
|
|
|
216 |
rcopy_ex /$LMK/kernel/drivers/usb/host/ohci-hcd* $INITRD_TREE 2>/dev/null
|
|
|
217 |
rcopy_ex /$LMK/kernel/drivers/usb/host/uhci-hcd* $INITRD_TREE 2>/dev/null
|
|
|
218 |
rcopy_ex /$LMK/kernel/drivers/scsi/scsi_mod.ko $INITRD_TREE 2>/dev/null
|
|
|
219 |
rcopy_ex /$LMK/kernel/drivers/scsi/sd_mod.ko $INITRD_TREE 2>/dev/null
|
|
|
220 |
rcopy_ex /$LMK/kernel/drivers/scsi/sr_mod.ko $INITRD_TREE 2>/dev/null
|
|
|
221 |
|
39 |
beyerle@PS |
222 |
# disk (scsi, ide, raid, pcmcia) modules
|
1 |
beyerle@PS |
223 |
#rcopy_ex /$LMK/kernel/drivers/scsi $INITRD_TREE
|
|
|
224 |
#rcopy_ex /$LMK/kernel/drivers/ide $INITRD_TREE
|
|
|
225 |
#rcopy_ex /$LMK/kernel/drivers/pcmcia $INITRD_TREE
|
|
|
226 |
|
39 |
beyerle@PS |
227 |
# disk sata (some sata modules)
|
1 |
beyerle@PS |
228 |
rcopy_ex /$LMK/kernel/drivers/scsi/libata.ko $INITRD_TREE 2>/dev/null
|
|
|
229 |
rcopy_ex /$LMK/kernel/drivers/scsi/ata_piix.ko $INITRD_TREE 2>/dev/null
|
|
|
230 |
rcopy_ex /$LMK/kernel/drivers/scsi/ahci.ko $INITRD_TREE 2>/dev/null
|
|
|
231 |
|
|
|
232 |
|
|
|
233 |
debug "gzipping kernel modules"
|
|
|
234 |
find $INITRD_TREE -name "*.ko" | xargs -r gzip --best
|
|
|
235 |
|
|
|
236 |
debug "generating module dependency files"
|
|
|
237 |
depmod -b $INITRD_TREE $KERNEL
|
|
|
238 |
|
|
|
239 |
debug "creating empty image file $INITRDIMG"
|
|
|
240 |
dd if=/dev/zero of=$INITRDIMG bs=$INITRD_BLOCKSIZE count=$RAM0SIZE >/dev/null 2>/dev/null
|
|
|
241 |
|
|
|
242 |
debug "making filesystem"
|
|
|
243 |
mkfs -t ext2 -F -m 0 -b $INITRD_BLOCKSIZE -i 1024 $INITRDIMG 2>/dev/null >/dev/null
|
|
|
244 |
|
|
|
245 |
debug "creating empty directory $MOUNTDIR"
|
|
|
246 |
rm -Rf $MOUNTDIR
|
|
|
247 |
mkdir $MOUNTDIR
|
|
|
248 |
|
|
|
249 |
debug "mounting $INITRDIMG to it"
|
|
|
250 |
mount -o loop $INITRDIMG $MOUNTDIR
|
|
|
251 |
if [ "$?" -ne 0 ]; then
|
|
|
252 |
echo "Error mounting initrd! Not enough free loop devices?"
|
|
|
253 |
exit 1
|
|
|
254 |
fi
|
|
|
255 |
|
|
|
256 |
debug "copying content of $INITRD_TREE to $MOUNTDIR"
|
|
|
257 |
rmdir $MOUNTDIR/lost+found
|
|
|
258 |
cp -R --preserve $INITRD_TREE/* $MOUNTDIR
|
|
|
259 |
|
|
|
260 |
debug "unmounting $MOUNTDIR"
|
|
|
261 |
umount $MOUNTDIR
|
|
|
262 |
|
|
|
263 |
debug "gzipping $INITRDIMG"
|
|
|
264 |
gzip --best $INITRDIMG
|
|
|
265 |
|
|
|
266 |
debug "deleting directory $MOUNTDIR"
|
|
|
267 |
rmdir $MOUNTDIR
|
|
|
268 |
|
|
|
269 |
debug "deleting directory $INITRD_TREE"
|
|
|
270 |
rm -Rf $INITRD_TREE
|
|
|
271 |
|
|
|
272 |
debug "$INITRDIMG.gz created"
|