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