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