Subversion Repositories livecd

Rev

Details | Last modification | View Log | RSS feed

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