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)
|
99 |
beyerle@PS |
25 |
# create links to all busybox commands (for busybox 1.6.1)
|
116 |
beyerle@PS |
26 |
# add sg.ko
|
126 |
beyerle@PS |
27 |
# add sata_nv
|
1 |
beyerle@PS |
28 |
#
|
|
|
29 |
|
|
|
30 |
# . ../config || exit 1
|
23 |
beyerle@PS |
31 |
|
1 |
beyerle@PS |
32 |
. ../../livecd.conf || exit 1
|
|
|
33 |
|
23 |
beyerle@PS |
34 |
# set an other kernel than the one set in livecd.conf
|
|
|
35 |
[ "$1" ] && KERNEL=$1
|
1 |
beyerle@PS |
36 |
echo "take blocksize=$INITRD_BLOCKSIZE for initrd"
|
|
|
37 |
|
|
|
38 |
# arch
|
|
|
39 |
ARCH=$( /bin/arch )
|
|
|
40 |
[ "$ARCH" != "x86_64" ] && ARCH=i686
|
|
|
41 |
|
23 |
beyerle@PS |
42 |
|
|
|
43 |
|
1 |
beyerle@PS |
44 |
# rcopy is a recursive cp, which copies also symlink's real source
|
|
|
45 |
# $1 = source (may be a regular file or symlink)
|
|
|
46 |
# $2 = target PARENT
|
|
|
47 |
#
|
|
|
48 |
rcopy()
|
|
|
49 |
{
|
|
|
50 |
if [ -L "$1" ]; then
|
|
|
51 |
REALPATH="`readlink -f \"$1\"`"
|
|
|
52 |
cp --parent -R "$REALPATH" "$2"
|
|
|
53 |
ln -sf "$REALPATH" "$2/$1"
|
|
|
54 |
else
|
|
|
55 |
cp --parent -R "$1" "$2"
|
|
|
56 |
fi
|
|
|
57 |
if [ "$?" -ne 0 ]; then
|
|
|
58 |
echo "---------------------------"
|
|
|
59 |
echo "Error occured while trying to copy \"$1\" to \"$2\""
|
|
|
60 |
echo "nevertheless your LiveCD may still work."
|
|
|
61 |
echo "Possible reason: not enough free space in initrd or source doesn't exist"
|
|
|
62 |
echo "---------------------------"
|
|
|
63 |
fi
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
# copy file/dir only if it exists, else skip with no error
|
|
|
67 |
# $1 = source (may not exist)
|
|
|
68 |
# $2 = target PARENT
|
|
|
69 |
#
|
|
|
70 |
rcopy_ex()
|
|
|
71 |
{
|
|
|
72 |
if [ -a "$1" ]; then
|
|
|
73 |
rcopy "$1" "$2"
|
|
|
74 |
fi
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
debug()
|
|
|
78 |
{
|
|
|
79 |
# uncomment to show debug messages
|
|
|
80 |
# echo "$@"
|
|
|
81 |
return 0
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
##################################################
|
|
|
85 |
# Create INITRD image now:
|
|
|
86 |
|
|
|
87 |
MOUNTDIR=/tmp/initrd_mountdir_$$
|
|
|
88 |
INITRD_TREE=/tmp/initrd_tree_$$
|
|
|
89 |
|
|
|
90 |
LMK="lib/modules/$KERNEL"
|
|
|
91 |
|
39 |
beyerle@PS |
92 |
UNIONFS_TYPE=""
|
|
|
93 |
|
|
|
94 |
if [ -e /$LMK/kernel/fs/unionfs/unionfs.ko ] || \
|
|
|
95 |
[ -e kernel-modules/${KERNEL}_$ARCH/unionfs.ko.gz ]; then
|
|
|
96 |
UNIONFS_TYPE="unionfs"
|
1 |
beyerle@PS |
97 |
fi
|
39 |
beyerle@PS |
98 |
if [ -e /$LMK/kernel/fs/aufs/aufs.ko ] || \
|
|
|
99 |
[ -e kernel-modules/${KERNEL}_$ARCH/aufs.ko.gz ]; then
|
|
|
100 |
UNIONFS_TYPE="aufs"
|
|
|
101 |
fi
|
|
|
102 |
if [ ! $UNIONFS_TYPE ]; then
|
107 |
beyerle@PS |
103 |
echo "ERROR: Neither aufs nor unionfs kernel module found."
|
39 |
beyerle@PS |
104 |
exit 1
|
|
|
105 |
fi
|
1 |
beyerle@PS |
106 |
|
|
|
107 |
if [ ! -e /$LMK/kernel/fs/squashfs/squashfs.ko ] && \
|
|
|
108 |
[ ! -e kernel-modules/${KERNEL}_$ARCH/squashfs.ko.gz ]; then
|
|
|
109 |
echo "ERROR: Squashfs kernel module not found."
|
|
|
110 |
exit 1
|
|
|
111 |
fi
|
|
|
112 |
|
|
|
113 |
debug "creating directories"
|
|
|
114 |
mkdir -p $INITRD_TREE/{etc,dev,bin,mnt,livecd,proc,lib,sbin,sys,tmp,var/log}
|
|
|
115 |
|
|
|
116 |
debug "creating some essential devices in rootdisk"
|
|
|
117 |
mknod $INITRD_TREE/dev/console c 5 1
|
|
|
118 |
mknod $INITRD_TREE/dev/null c 1 3
|
|
|
119 |
mknod $INITRD_TREE/dev/ram b 1 1
|
|
|
120 |
mknod $INITRD_TREE/dev/systty c 4 0
|
|
|
121 |
mknod $INITRD_TREE/dev/tty c 5 0
|
69 |
beyerle@PS |
122 |
for i in 1 2 3 4 5 6; do
|
|
|
123 |
mknod $INITRD_TREE/dev/tty$i c 4 $i;
|
|
|
124 |
done
|
1 |
beyerle@PS |
125 |
|
|
|
126 |
loops=255
|
|
|
127 |
while [ $loops -ge 0 ]; do
|
|
|
128 |
mknod $INITRD_TREE/dev/loop$loops b 7 $loops
|
|
|
129 |
loops=$(($loops-1))
|
|
|
130 |
done
|
|
|
131 |
|
|
|
132 |
debug "copying files to the rootdisk"
|
|
|
133 |
touch $INITRD_TREE/etc/{m,fs}tab
|
|
|
134 |
cp {linuxrc,liblinuxlive} $INITRD_TREE # symlink will be copied as original file
|
|
|
135 |
chmod a+x $INITRD_TREE/linuxrc
|
|
|
136 |
|
|
|
137 |
cp static-binaries/modprobe $INITRD_TREE/sbin
|
|
|
138 |
cp static-binaries/busybox $INITRD_TREE/bin
|
100 |
beyerle@PS |
139 |
# cp static-binaries/unionctl_${ARCH} $INITRD_TREE/bin/unionctl
|
|
|
140 |
if [ -x /usr/sbin/unionctl.static ]; then
|
|
|
141 |
cp -a /usr/sbin/unionctl.static $INITRD_TREE/bin/unionctl
|
|
|
142 |
else
|
|
|
143 |
echo "NOTE: /usr/sbin/unionctl.static was not found !"
|
|
|
144 |
echo "assuming you're using unionfs 2.x"
|
|
|
145 |
fi
|
1 |
beyerle@PS |
146 |
ln -s busybox $INITRD_TREE/bin/[
|
98 |
beyerle@PS |
147 |
ln -s busybox $INITRD_TREE/bin/[[
|
97 |
beyerle@PS |
148 |
BUSYBOXCMDS="ash awk basename cat chmod chown chroot \
|
|
|
149 |
clear cp cut dd df dirname du echo egrep eject \
|
|
|
150 |
expr false fdisk fgrep find free grep gunzip halt \
|
|
|
151 |
hdparm head hostname ifconfig ifdown ifup insmod \
|
|
|
152 |
kill killall last ln logger losetup ls lsmod md5sum \
|
|
|
153 |
mkdir mkfifo mknod mkswap mktemp more \
|
|
|
154 |
mount mv pivot_root poweroff ps pwd readlink realpath \
|
|
|
155 |
reboot rm rmdir rmmod route sed sh sleep sort \
|
|
|
156 |
swapoff swapon sync tail tar tee test touch tr \
|
105 |
beyerle@PS |
157 |
true udhcpc umount uname uniq vi which wc xargs \
|
|
|
158 |
zcat"
|
97 |
beyerle@PS |
159 |
for c in $BUSYBOXCMDS; do
|
|
|
160 |
ln -s busybox $INITRD_TREE/bin/$c
|
|
|
161 |
done
|
|
|
162 |
|
1 |
beyerle@PS |
163 |
# dhcp startup script
|
|
|
164 |
cp static-binaries/udhcpc.script $INITRD_TREE/bin
|
|
|
165 |
ln -s ../bin/busybox $INITRD_TREE/sbin/ifconfig
|
|
|
166 |
|
|
|
167 |
# lspci and pcitable for network card detection
|
37 |
beyerle@PS |
168 |
cp static-binaries/lspci $INITRD_TREE/sbin
|
1 |
beyerle@PS |
169 |
cp static-binaries/pcitable $INITRD_TREE/bin
|
|
|
170 |
|
39 |
beyerle@PS |
171 |
# rev needed for unionctl of aufs
|
|
|
172 |
if [ "$UNIONFS_TYPE" = "aufs" ]; then
|
|
|
173 |
cp static-binaries/rev $INITRD_TREE/bin
|
|
|
174 |
fi
|
1 |
beyerle@PS |
175 |
|
|
|
176 |
LMK="lib/modules/$KERNEL"
|
|
|
177 |
|
39 |
beyerle@PS |
178 |
# necessary modules and dependency files
|
1 |
beyerle@PS |
179 |
mkdir -p $INITRD_TREE/$LMK/kernel/fs
|
|
|
180 |
cp kernel-modules/${KERNEL}_$ARCH/unionfs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/null
|
37 |
beyerle@PS |
181 |
cp kernel-modules/${KERNEL}_$ARCH/aufs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/null
|
1 |
beyerle@PS |
182 |
cp kernel-modules/${KERNEL}_$ARCH/squashfs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/null
|
|
|
183 |
rcopy_ex /$LMK/kernel/fs/unionfs $INITRD_TREE 2>/dev/null
|
37 |
beyerle@PS |
184 |
rcopy_ex /$LMK/kernel/fs/aufs $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
185 |
rcopy_ex /$LMK/kernel/fs/squashfs $INITRD_TREE 2>/dev/null
|
|
|
186 |
|
39 |
beyerle@PS |
187 |
# copy filesystem modules, if not directly copied into kernel
|
1 |
beyerle@PS |
188 |
rcopy_ex /$LMK/kernel/lib/zlib_inflate $INITRD_TREE 2>/dev/null
|
|
|
189 |
rcopy_ex /$LMK/kernel/drivers/block/loop* $INITRD_TREE 2>/dev/null
|
|
|
190 |
|
|
|
191 |
rcopy_ex /$LMK/kernel/fs/isofs $INITRD_TREE 2>/dev/null
|
|
|
192 |
rcopy_ex /$LMK/kernel/fs/fat $INITRD_TREE 2>/dev/null
|
|
|
193 |
rcopy_ex /$LMK/kernel/fs/vfat $INITRD_TREE 2>/dev/null
|
|
|
194 |
rcopy_ex /$LMK/kernel/fs/ntfs $INITRD_TREE 2>/dev/null
|
|
|
195 |
rcopy_ex /$LMK/kernel/fs/ext3 $INITRD_TREE 2>/dev/null
|
|
|
196 |
rcopy_ex /$LMK/kernel/fs/jbd $INITRD_TREE 2>/dev/null
|
|
|
197 |
|
|
|
198 |
# for NFS support
|
|
|
199 |
rcopy_ex /$LMK/kernel/fs/nfs $INITRD_TREE 2>/dev/null
|
|
|
200 |
rcopy_ex /$LMK/kernel/fs/nfs_common $INITRD_TREE 2>/dev/null
|
|
|
201 |
rcopy_ex /$LMK/kernel/fs/lockd $INITRD_TREE 2>/dev/null
|
|
|
202 |
rcopy_ex /$LMK/kernel/fs/fscache $INITRD_TREE 2>/dev/null
|
|
|
203 |
rcopy_ex /$LMK/kernel/net/sunrpc $INITRD_TREE 2>/dev/null
|
|
|
204 |
rcopy_ex /$LMK/kernel/net/sunrpc $INITRD_TREE 2>/dev/null
|
|
|
205 |
|
|
|
206 |
# net drivers
|
104 |
beyerle@PS |
207 |
rcopy_ex /$LMK/kernel/drivers/net $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
208 |
rcopy_ex /$LMK/updates/drivers/net/sky2/sky2.ko $INITRD_TREE 2>/dev/null
|
|
|
209 |
|
|
|
210 |
# add language support for filesystems
|
69 |
beyerle@PS |
211 |
# rcopy_ex /$LMK/kernel/fs/nls/ $INITRD_TREE 2>/dev/null
|
120 |
beyerle@PS |
212 |
# rcopy_ex /$LMK/kernel/fs/nls/nls_cp437.* $INITRD_TREE 2>/dev/null
|
|
|
213 |
# rcopy_ex /$LMK/kernel/fs/nls/nls_iso8859-1.* $INITRD_TREE 2>/dev/null
|
|
|
214 |
# rcopy_ex /$LMK/kernel/fs/nls/nls_iso8859-2.* $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
215 |
|
|
|
216 |
# cdrom support (for SL5)
|
|
|
217 |
rcopy_ex /$LMK/kernel/drivers/ide/ide-cd.ko $INITRD_TREE 2>/dev/null
|
|
|
218 |
rcopy_ex /$LMK/kernel/drivers/cdrom/cdrom.ko $INITRD_TREE 2>/dev/null
|
|
|
219 |
|
|
|
220 |
# usb modules
|
|
|
221 |
rcopy_ex /$LMK/kernel/drivers/usb/storage $INITRD_TREE 2>/dev/null
|
|
|
222 |
rcopy_ex /$LMK/kernel/drivers/usb/host/ehci-hcd* $INITRD_TREE 2>/dev/null
|
|
|
223 |
rcopy_ex /$LMK/kernel/drivers/usb/host/ohci-hcd* $INITRD_TREE 2>/dev/null
|
|
|
224 |
rcopy_ex /$LMK/kernel/drivers/usb/host/uhci-hcd* $INITRD_TREE 2>/dev/null
|
|
|
225 |
rcopy_ex /$LMK/kernel/drivers/scsi/scsi_mod.ko $INITRD_TREE 2>/dev/null
|
|
|
226 |
rcopy_ex /$LMK/kernel/drivers/scsi/sd_mod.ko $INITRD_TREE 2>/dev/null
|
|
|
227 |
rcopy_ex /$LMK/kernel/drivers/scsi/sr_mod.ko $INITRD_TREE 2>/dev/null
|
|
|
228 |
|
39 |
beyerle@PS |
229 |
# disk (scsi, ide, raid, pcmcia) modules
|
1 |
beyerle@PS |
230 |
#rcopy_ex /$LMK/kernel/drivers/scsi $INITRD_TREE
|
|
|
231 |
#rcopy_ex /$LMK/kernel/drivers/ide $INITRD_TREE
|
|
|
232 |
#rcopy_ex /$LMK/kernel/drivers/pcmcia $INITRD_TREE
|
|
|
233 |
|
39 |
beyerle@PS |
234 |
# disk sata (some sata modules)
|
1 |
beyerle@PS |
235 |
rcopy_ex /$LMK/kernel/drivers/scsi/libata.ko $INITRD_TREE 2>/dev/null
|
120 |
beyerle@PS |
236 |
rcopy_ex /$LMK/kernel/drivers/ata/libata.ko $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
237 |
rcopy_ex /$LMK/kernel/drivers/scsi/ata_piix.ko $INITRD_TREE 2>/dev/null
|
122 |
beyerle@PS |
238 |
rcopy_ex /$LMK/kernel/drivers/ata/ata_piix.ko $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
239 |
rcopy_ex /$LMK/kernel/drivers/scsi/ahci.ko $INITRD_TREE 2>/dev/null
|
122 |
beyerle@PS |
240 |
rcopy_ex /$LMK/kernel/drivers/ata/ahci.ko $INITRD_TREE 2>/dev/null
|
126 |
beyerle@PS |
241 |
rcopy_ex /$LMK/kernel/drivers/scsi/sata_nv.ko $INITRD_TREE 2>/dev/null
|
|
|
242 |
rcopy_ex /$LMK/kernel/drivers/ata/sata_nv.ko $INITRD_TREE 2>/dev/null
|
116 |
beyerle@PS |
243 |
rcopy_ex /$LMK/kernel/drivers/scsi/sg.ko $INITRD_TREE 2>/dev/null
|
1 |
beyerle@PS |
244 |
|
|
|
245 |
|
|
|
246 |
debug "gzipping kernel modules"
|
|
|
247 |
find $INITRD_TREE -name "*.ko" | xargs -r gzip --best
|
|
|
248 |
|
|
|
249 |
debug "generating module dependency files"
|
|
|
250 |
depmod -b $INITRD_TREE $KERNEL
|
|
|
251 |
|
|
|
252 |
debug "creating empty image file $INITRDIMG"
|
|
|
253 |
dd if=/dev/zero of=$INITRDIMG bs=$INITRD_BLOCKSIZE count=$RAM0SIZE >/dev/null 2>/dev/null
|
|
|
254 |
|
|
|
255 |
debug "making filesystem"
|
|
|
256 |
mkfs -t ext2 -F -m 0 -b $INITRD_BLOCKSIZE -i 1024 $INITRDIMG 2>/dev/null >/dev/null
|
|
|
257 |
|
|
|
258 |
debug "creating empty directory $MOUNTDIR"
|
|
|
259 |
rm -Rf $MOUNTDIR
|
|
|
260 |
mkdir $MOUNTDIR
|
|
|
261 |
|
|
|
262 |
debug "mounting $INITRDIMG to it"
|
|
|
263 |
mount -o loop $INITRDIMG $MOUNTDIR
|
|
|
264 |
if [ "$?" -ne 0 ]; then
|
|
|
265 |
echo "Error mounting initrd! Not enough free loop devices?"
|
|
|
266 |
exit 1
|
|
|
267 |
fi
|
|
|
268 |
|
|
|
269 |
debug "copying content of $INITRD_TREE to $MOUNTDIR"
|
|
|
270 |
rmdir $MOUNTDIR/lost+found
|
|
|
271 |
cp -R --preserve $INITRD_TREE/* $MOUNTDIR
|
|
|
272 |
|
|
|
273 |
debug "unmounting $MOUNTDIR"
|
|
|
274 |
umount $MOUNTDIR
|
|
|
275 |
|
|
|
276 |
debug "gzipping $INITRDIMG"
|
|
|
277 |
gzip --best $INITRDIMG
|
|
|
278 |
|
|
|
279 |
debug "deleting directory $MOUNTDIR"
|
|
|
280 |
rmdir $MOUNTDIR
|
|
|
281 |
|
|
|
282 |
debug "deleting directory $INITRD_TREE"
|
|
|
283 |
rm -Rf $INITRD_TREE
|
|
|
284 |
|
|
|
285 |
debug "$INITRDIMG.gz created"
|