Rev 126 | Go to most recent revision | 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# source ../../livecd.conf instead of ../config# changes need for SL5:# - initrd blocksize to 4096 (instead of 1024)# - add fscache (for NFS support)# - add ide-cd, cdrom (for CD-ROM support)# read $KERNEL from $1, can overwrite setting in livecd.conf# add aufs (replacement for unionfs)# add rev to static-binaries (for unionctl of aufs)# create links to all busybox commands (for busybox 1.6.1)# add sg.ko# add sata_nv# add cifs kernel module## . ../config || exit 1. ../../livecd.conf || exit 1# set an other kernel than the one set in livecd.conf[ "$1" ] && KERNEL=$1echo "take blocksize=$INITRD_BLOCKSIZE for initrd"# 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"UNIONFS_TYPE=""if [ -e /$LMK/kernel/fs/unionfs/unionfs.ko ] || \[ -e kernel-modules/${KERNEL}_$ARCH/unionfs.ko.gz ]; thenUNIONFS_TYPE="unionfs"fiif [ -e /$LMK/kernel/fs/aufs/aufs.ko ] || \[ -e kernel-modules/${KERNEL}_$ARCH/aufs.ko.gz ]; thenUNIONFS_TYPE="aufs"fiif [ ! $UNIONFS_TYPE ]; thenecho "ERROR: Neither aufs nor unionfs kernel module 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 1fidebug "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 0for i in 1 2 3 4 5 6; domknod $INITRD_TREE/dev/tty$i c 4 $i;doneloops=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/bin# cp static-binaries/unionctl_${ARCH} $INITRD_TREE/bin/unionctlif [ -x /usr/sbin/unionctl.static ]; thencp -a /usr/sbin/unionctl.static $INITRD_TREE/bin/unionctlelseecho "NOTE: /usr/sbin/unionctl.static was not found !"echo "assuming you're using unionfs 2.x"filn -s busybox $INITRD_TREE/bin/[ln -s busybox $INITRD_TREE/bin/[[BUSYBOXCMDS="ash awk basename cat chmod chown chroot \clear cp cut dd df dirname du echo egrep eject \expr false fdisk fgrep find free grep gunzip halt \hdparm head hostname ifconfig ifdown ifup insmod \kill killall last ln logger losetup ls lsmod md5sum \mkdir mkfifo mknod mkswap mktemp more \mount mv pivot_root poweroff ps pwd readlink realpath \reboot rm rmdir rmmod route sed sh sleep sort \swapoff swapon switch_root sync tail tar tee test touch tr \true udhcpc umount uname uniq vi which wc xargs \zcat"for c in $BUSYBOXCMDS; doln -s busybox $INITRD_TREE/bin/$cdone# 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/bin# rev needed for unionctl of aufsif [ "$UNIONFS_TYPE" = "aufs" ]; thencp static-binaries/rev $INITRD_TREE/binfiLMK="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/aufs.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/aufs $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/fs/fscache $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/net/sunrpc $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/net/sunrpc $INITRD_TREE 2>/dev/null# for cifs-supportrcopy_ex /$LMK/kernel/fs/cifs $INITRD_TREE 2>/dev/null# net driversrcopy_ex /$LMK/kernel/drivers/net $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/updates/drivers/net/sky2/sky2.ko $INITRD_TREE 2>/dev/null# add language support for filesystems# rcopy_ex /$LMK/kernel/fs/nls/ $INITRD_TREE 2>/dev/null# rcopy_ex /$LMK/kernel/fs/nls/nls_cp437.* $INITRD_TREE 2>/dev/null# rcopy_ex /$LMK/kernel/fs/nls/nls_iso8859-1.* $INITRD_TREE 2>/dev/null# rcopy_ex /$LMK/kernel/fs/nls/nls_iso8859-2.* $INITRD_TREE 2>/dev/null# cdrom support (for SL5)rcopy_ex /$LMK/kernel/drivers/ide/ide-cd.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/cdrom/cdrom.ko $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/ata/libata.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/ata_piix.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/ata/ata_piix.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/ahci.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/ata/ahci.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/sata_nv.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/ata/sata_nv.ko $INITRD_TREE 2>/dev/nullrcopy_ex /$LMK/kernel/drivers/scsi/sg.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=$INITRD_BLOCKSIZE count=$RAM0SIZE >/dev/null 2>/dev/nulldebug "making filesystem"mkfs -t ext2 -F -m 0 -b $INITRD_BLOCKSIZE -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"