Author: glen
Date: Tue Nov  6 14:06:37 2007
New Revision: 9003

Modified:
   geninitrd/trunk/geninitrd
Log:
- skip pointless another temporary dir
- beautify debug messages
- avoid race for initrd compression

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd   (original)
+++ geninitrd/trunk/geninitrd   Tue Nov  6 14:06:37 2007
@@ -389,7 +389,7 @@
        local dest=$1
        set -- $src
 
-       debug "cp $* $DESTDIR$dest"
+       debug "+ cp $* $DESTDIR$dest"
        cp -HR "$@" "$DESTDIR$dest"
 }
 
@@ -444,10 +444,10 @@
        fi
 
        if [ -n "$modulefile" ]; then
-               debug "modprobe: using $modulefile"
+               debug "Using $modulefile for modules config"
                modprobe_conf_cache=$(cat $modulefile)
        else
-               debug "modprobe: using modprobe -c"
+               debug "Using modprobe -c to get modules config"
                modprobe_conf_cache=$(modprobe -c)
        fi
 }
@@ -521,7 +521,7 @@
        eval "dev_list${rootdev_nr}=\"${dev_list}\""
 
        for device in $dev_list; do
-               find_modules_for_device $device
+               find_modules_for_devpath $device
        done
 }
 
@@ -656,7 +656,7 @@
        rc=$?
 
        if [ $rc = 0 ]; then
-               debug "$node is LVM1 node"
+               debug "LVM check: $node is LVM v1 node"
                # is lvm1
                return 0
        fi
@@ -669,9 +669,9 @@
        fi
 
        if [ $rc = 0 ]; then
-               debug "$node is lvm2 node"
+               debug "LVM check: $node is LVM v2 node"
        else
-               debug "$node is not any lvm node"
+               debug "LVM check: $node is not any LVM node"
        fi
        return $rc
 }
@@ -691,11 +691,11 @@
                return 1
        fi
 
-       debug "have multipath"
+       debug "Finding modules for dm-multipath"
        have_multipath=yes
        local dev phydevs=$(echo "$info" | awk '$2 ~ 
/^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
        for dev in $phydevs; do
-               find_modules_for_device $dev
+               find_modules_for_devpath $dev
                lvm_ignore_devices="$lvm_ignore_devices $dev"
        done
 
@@ -726,7 +726,7 @@
 
        local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, 
-vv="$raidname" '{if ($2 == v) print $1}')
        for dev in $phydevs; do
-               find_modules_for_device $dev
+               find_modules_for_devpath $dev
                lvm_ignore_devices="$lvm_ignore_devices $dev"
                found=1
        done
@@ -741,10 +741,10 @@
 }
 
 # find modules for $devpath
-find_modules_for_device() {
+find_modules_for_devpath() {
        local devpath="$1"
        if [ -z "$devpath" ]; then
-               die "No argument passed to find_modules_for_device() - is your 
/etc/fstab correct?"
+               die "No argument passed to find_modules_for_devpath() - is your 
/etc/fstab correct?"
        fi
 
        # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
@@ -753,7 +753,7 @@
                devpath=$(dm_longname "$devpath")
                ;;
        esac
-       debug "find_modules_for_device($devpath)"
+       debug "Finding modules for device path $devpath"
 
        if is_yes "`echo "$devpath" | awk 
'/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
                if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
@@ -871,7 +871,7 @@
                fi
                if [ -n "$PVDEVICES" ]; then
                        for device in $PVDEVICES; do
-                               find_modules_for_device $device
+                               find_modules_for_devpath $device
                        done
                else
                        die "I wasn't able to find PV (via lvdisplay and 
pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
@@ -884,7 +884,7 @@
                else
                        die "LVM version $LVMTOOLSVERSION is not supported yet."
                fi
-               debug "LVM $LVMTOOLSVERSION enabled"
+               debug "LVM v$LVMTOOLSVERSION enabled"
                have_lvm=yes
                return
        fi
@@ -1081,7 +1081,7 @@
 initrd_gen_bootsplash() {
        local target="$1"
 
-       debug "generating bootsplash"
+       debug "Generating bootsplash"
        if [ ! -x /bin/splash.bin ]; then
                echo >&2 "Failed to execute /bin/splash.bin. Is bootsplash 
package installed?"
        elif [ -z "$THEME" ]; then
@@ -1105,7 +1105,7 @@
 }
 
 initrd_gen_fbsplash() {
-       debug "generating fbsplash"
+       debug "Generating fbsplash"
 
        if [ ! -x /usr/bin/splash_geninitramfs ]; then
                echo >&2 "Failed to execute /usr/bin/splash_geninitramfs. Is 
splashutils package installed?"
@@ -1304,7 +1304,7 @@
                        echo '  filter = [' >> "$DESTDIR/etc/lvm.conf"
                        local dev
                        for dev in $lvm_ignore_devices; do
-                               debug "LVM2: ignore device $dev"
+                               debug "LVM v2: ignore device $dev"
                                printf '  "r|^%s.*|",\n' $dev
                        done >> "$DESTDIR/etc/lvm.conf"
                        echo ']' >> "$DESTDIR/etc/lvm.conf"
@@ -1649,7 +1649,7 @@
 else
        _lib=lib
 fi
-debug "_lib: $_lib"
+debug "Using libdir: $_lib"
 
 cache_modprobe_conf
 
@@ -1669,8 +1669,8 @@
 find_root "$fstab" || exit
 debug "Using $rootdev as device for rootfs"
 
-find_modules_for_device "$rootdev"
-[ -n "$rootdev_add" ] && find_modules_for_device "$rootdev_add"
+find_modules_for_devpath "$rootdev"
+[ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
 
 findmodule "-$rootFs"
 
@@ -1690,25 +1690,9 @@
        debug "No modules are needed -- not building initrd image."
        exit 0
 fi
-debug "Using modules: $MODULES"
 
-DESTDIR="`mktemp -d /tmp/initrd.XXXXXX`"
-IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
-MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
+DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
 RCFILE="$DESTDIR/linuxrc"
-
-if [ -f "$DESTDIR" ]; then
-       die "$DESTDIR already exists. Remove it and try again"
-fi
-
-if [ -f "$IMAGE" ]; then
-       die "$IMAGE already exists. Remove it and try again"
-fi
-
-mkdir -p "$MNTPOINT"
-# We don't need this directory, so let's save space
-rm -rf "$MNTPOINT"/lost+found
-
 > "$RCFILE"
 chmod a+rx "$RCFILE"
 ln -s linuxrc $DESTDIR/init
@@ -1895,6 +1879,7 @@
        # we need /init being real file, not symlink, otherwise the initramfs 
will
        # not be ran by pid 1 which is required for switch_root
        mv $DESTDIR/linuxrc $DESTDIR/init
+       ln -s init $DESTDIR/linuxrc
 else
        # other than initramfs
        umount_all
@@ -1904,48 +1889,56 @@
        initrd_gen_fbsplash
 fi
 
-
-(cd "$DESTDIR"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
-
+IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
 case "$INITRDFS" in
        ext2)
-               IMAGESIZE=$(du -ks $MNTPOINT | awk '{print 
int(($1+1023+512)/1024)*1024}')
-               debug   "ext2 image size: $IMAGESIZE ($MNTPOINT)"
+               IMAGESIZE=$(du -ks $DESTDIR | awk '{print 
int(($1+1023+512)/1024)*1024}')
+               debug   "ext2 image size: $IMAGESIZE ($DESTDIR)"
                if [ "$IMAGESIZE" -gt 4096 ]; then
                        echo >&2 "$PROGRAM: Your image size is larger than 
4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
                fi
 
+               debug "Creating ext2 image $IMAGE"
                dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> 
/dev/null
                mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
                tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
 
-               tmpmnt="`mktemp -d /tmp/initrd.mnte2-XXXXXX`"
+               local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
+               debug "Mounting ext2 image $IMAGE to $tmpmnt"
                mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
+               # We don't need this directory, so let's save space
+               rm -rf "$tmpmnt"/lost+found
 
-               (cd "$MNTPOINT"; tar cf - .) | (cd "$tmpmnt"; tar xf -)
-
+               debug "Copy recursively $DESTDIR -> $tmpmnt"
+               cp -a $DESTDIR/* $tmpmnt
                umount "$IMAGE"
+               rmdir "$tmpmnt"
+
                ;;
        rom|romfs)
-               genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel 
$kernel"
+               debug "Generating romfs image: $IMAGE"
+               genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel 
$kernel"
                IMAGESIZE=$(stat -c %s $IMAGE | awk '{print 
int((($1/1024)+1023)/1024)*1024}')
-               debug   "romfs image size: $IMAGESIZE ($IMAGE)"
+               debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
                if [ "$IMAGESIZE" -gt 4096 ]; then
                        echo >&2 "$PROGRAM: Your image size is larger than 
4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
                fi
                ;;
        cram|cramfs)
-               mkcramfs "$MNTPOINT" "$IMAGE"
+               mkcramfs "$DESTDIR" "$IMAGE"
                ;;
        initramfs)
-               (cd $MNTPOINT; find . | cpio --quiet -H newc -o > "$IMAGE")
+               (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
                ;;
        *)
                echo "Filesystem $INITRDFS not supported by $PROGRAM";
 esac
 
 if is_yes "$COMPRESS"; then
-       gzip -9 < "$IMAGE" > "$target"
+       local tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
+       debug "Compressing $target"
+       gzip -9 < "$IMAGE" > "$tmp"
+       mv -f "$tmp" "$target"
 else
        cp -a "$IMAGE" "$target"
 fi
@@ -1954,6 +1947,6 @@
        initrd_gen_bootsplash "$target"
 fi
 
-rm -rf "$DESTDIR" "$MNTPOINT" "$IMAGE"
+rm -rf "$DESTDIR" "$IMAGE"
 
 # vim:ts=4:sw=4:noet:fdm=marker
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to