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