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