Rev 8 | Blame | Last modification | View Log | Download | RSS feed
#!/bin/bash# initrd_create: make initrd rootdisk by using busybox## Author: Tomas M. <http://www.linux-live.org>## added by Urs Beyerle, PSI:## add modules: nfs, sunrpc, lockd, nfs_acl (found in nfs_common)# add drivers/net# add x86_64 support# add sata modules: ata_piix, libata# add module: jbd# add module: sr_mod# unionctl.static can be installed locally# add module ahci# add module forcedeth#. ../config || exit 1# archARCH=$( /bin/arch )[ "$ARCH" != "x86_64" ] && ARCH=i686# rcopy is a recursive cp, which copies also symlink's real source# $1 = source (may be a regular file or symlink)# $2 = target PARENT#rcopy(){if [ -L "$1" ]; thenREALPATH="`readlink -f \"$1\"`"cp --parent -R "$REALPATH" "$2"ln -sf "$REALPATH" "$2/$1"elsecp --parent -R "$1" "$2"fiif [ "$?" -ne 0 ]; thenecho "---------------------------"echo "Error occured while trying to copy \"$1\" to \"$2\""echo "nevertheless your LiveCD may still work."echo "Possible reason: not enough free space in initrd or source doesn't exist"echo "---------------------------"fi}# copy file/dir only if it exists, else skip with no error# $1 = source (may not exist)# $2 = target PARENT#rcopy_ex(){if [ -a "$1" ]; thenrcopy "$1" "$2"fi}debug(){# uncomment to show debug messages# echo "$@"return 0}################################################### Create INITRD image now:MOUNTDIR=/tmp/initrd_mountdir_$$INITRD_TREE=/tmp/initrd_tree_$$LMK="lib/modules/$KERNEL"if [ ! -e /$LMK/kernel/fs/unionfs/unionfs.ko ] && \[ ! -e kernel-modules/${KERNEL}_$ARCH/unionfs.ko.gz ]; thenecho "ERROR: Unionfs kernel module not found."exit 1fiif [ ! -e /$LMK/kernel/fs/squashfs/squashfs.ko ] && \[ ! -e kernel-modules/${KERNEL}_$ARCH/squashfs.ko.gz ]; thenecho "ERROR: Squashfs kernel module not found."exit 1fi# if [ ! -d "kernel-modules/${KERNEL}_$ARCH" ]; then# echo "The directory kernel-modules/${KERNEL}_$ARCH doesn't exist. Please create it and copy"# echo "squashFS and unionFS modules for your kernel version to it."# exit 1# fidebug "creating empty directory $INITRD_TREE"rm -Rf $INITRD_TREEmkdir $INITRD_TREEdebug "creating directories"mkdir -p $INITRD_TREE/{etc,dev,bin,mnt,livecd,proc,lib,sbin,sys,tmp,var/log}debug "creating some essential devices in rootdisk"mknod $INITRD_TREE/dev/console c 5 1mknod $INITRD_TREE/dev/null c 1 3mknod $INITRD_TREE/dev/ram b 1 1mknod $INITRD_TREE/dev/systty c 4 0mknod $INITRD_TREE/dev/tty c 5 0mknod $INITRD_TREE/dev/tty1 c 4 1loops=255while [ $loops -ge 0 ]; domknod $INITRD_TREE/dev/loop$loops b 7 $loopsloops=$(($loops-1))donedebug "copying files to the rootdisk"touch $INITRD_TREE/etc/{m,fs}tabcp {linuxrc,liblinuxlive} $INITRD_TREE # symlink will be copied as original filechmod a+x $INITRD_TREE/linuxrccp static-binaries/modprobe $INITRD_TREE/sbincp static-binaries/busybox $INITRD_TREE/bincp static-binaries/unionctl_${ARCH} $INITRD_TREE/bin/unionctl[ -x /usr/sbin/unionctl.static ] && cp -a /usr/sbin/unionctl.static $INITRD_TREE/bin/unionctlln -s busybox $INITRD_TREE/bin/ashln -s busybox $INITRD_TREE/bin/shln -s busybox $INITRD_TREE/bin/[# dhcp startup scriptcp static-binaries/udhcpc.script $INITRD_TREE/binln -s ../bin/busybox $INITRD_TREE/sbin/ifconfig# lspci and pcitable for network card detectioncp static-binaries/lspci $INITRD_TREE/sbincp static-binaries/pcitable $INITRD_TREE/binLMK="lib/modules/$KERNEL"#necessary modules and dependency filesmkdir -p $INITRD_TREE/$LMK/kernel/fscp kernel-modules/${KERNEL}_$ARCH/unionfs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/nullcp kernel-modules/${KERNEL}_$ARCH/squashfs.ko.gz $INITRD_TREE/$LMK/kernel/fs 2>/dev/nullrcopy_ex /$LMK/kernel/fs/unionfs $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/squashfs $INITRD_TREE 2>/dev/null#copy filesystem modules, if not directly copied into kernelrcopy_ex /$LMK/kernel/lib/zlib_inflate $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/block/loop* $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/isofs $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/fat $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/vfat $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/ntfs $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/ext3 $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/jbd $INITRD_TREE 2>/dev/null# for NFS supportrcopy_ex /$LMK/kernel/fs/nfs $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/nfs_common $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/fs/lockd $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/net/sunrpc $INITRD_TREE 2>/dev/null# net driversrcopy_ex /$LMK/kernel/drivers/net/mii.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/3c59x.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/8139cp.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/8139too.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/8390.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/e1000/e1000.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/e100.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/ns83820.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/tg3.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/pcnet32.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/tulip/tulip.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/b44.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/sk98lin/sk98lin.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/sky2.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/net/forcedeth.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/updates/drivers/net/sky2/sky2.ko $INITRD_TREE 2>/dev/null# add language support for filesystemsrcopy_ex /$LMK/kernel/fs/nls/ $INITRD_TREE 2>/dev/null#usb modulesrcopy_ex /$LMK/kernel/drivers/usb/storage $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/usb/host/ehci-hcd* $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/usb/host/ohci-hcd* $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/usb/host/uhci-hcd* $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/scsi_mod.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/sd_mod.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/sr_mod.ko $INITRD_TREE 2>/dev/null#disk (scsi, ide, raid, pcmcia) modules#rcopy_ex /$LMK/kernel/drivers/scsi $INITRD_TREE#rcopy_ex /$LMK/kernel/drivers/ide $INITRD_TREE#rcopy_ex /$LMK/kernel/drivers/pcmcia $INITRD_TREE#disk sata (some sata modules)rcopy_ex /$LMK/kernel/drivers/scsi/libata.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/ata_piix.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/ahci.ko $INITRD_TREE 2>/dev/nulldebug "gzipping kernel modules"find $INITRD_TREE -name "*.ko" | xargs -r gzip --bestdebug "generating module dependency files"depmod -b $INITRD_TREE $KERNELdebug "creating empty image file $INITRDIMG"dd if=/dev/zero of=$INITRDIMG bs=1024 count=$RAM0SIZE >/dev/null 2>/dev/nulldebug "making filesystem"mkfs -t ext2 -F -m 0 -b 1024 -i 1024 $INITRDIMG 2>/dev/null >/dev/nulldebug "creating empty directory $MOUNTDIR"rm -Rf $MOUNTDIRmkdir $MOUNTDIRdebug "mounting $INITRDIMG to it"mount -o loop $INITRDIMG $MOUNTDIRif [ "$?" -ne 0 ]; thenecho "Error mounting initrd! Not enough free loop devices?"exit 1fidebug "copying content of $INITRD_TREE to $MOUNTDIR"rmdir $MOUNTDIR/lost+foundcp -R --preserve $INITRD_TREE/* $MOUNTDIRdebug "unmounting $MOUNTDIR"umount $MOUNTDIRdebug "gzipping $INITRDIMG"gzip --best $INITRDIMGdebug "deleting directory $MOUNTDIR"rmdir $MOUNTDIRdebug "deleting directory $INITRD_TREE"rm -Rf $INITRD_TREEdebug "$INITRDIMG.gz created"