Changeset 1099


Ignore:
Timestamp:
Feb 4, 2007, 7:35:31 AM (13 years ago)
Author:
andree
Message:

Add capability to mindi to detect what type of filesystem the kernel
will be able to access in initrd image during restore via new function
GetInitrdFilesystemToUse?(). Currently detected are: ext2, cpio and
cramfs. Note that the latter is not currently implemented in terms of
creating the initrd image.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi/mindi

    r1097 r1099  
    826826
    827827
     828# Check kernel filesystem capabilites for accessing initrd image
     829#
     830# Interface definition:
     831# param #1: absolute path to kernel image
     832GetInitrdFilesystemToUse() {
     833
     834    # interface test: make sure we have one parameter
     835    if [ $# -ne 1 ]; then
     836        Die "GetInitrdFilesystemToUse(): Expected 1 parameter, got $#."
     837    fi
     838
     839    # interface parameters
     840    local lvKernelImage=$1
     841
     842    # local constants (filesystem magic strings)
     843    local lcMagicCramfs="<3>cramfs: wrong magic"
     844    local lcMagicExt2fs="<3>EXT2-fs: blocksize too small for device."
     845    local lcMagicInitfs="<6>checking if image is initramfs..."
     846
     847    # local variables
     848    local lvOffset
     849    local lvScanRes
     850    local lvUseFilesystem
     851
     852    # say where we are.
     853    LogIt "  GetInitrdFilesystemToUse(): called with parameter: $lvKernelImage.\n"
     854
     855    # verify that file exists
     856    [ ! -f $lvKernelImage ] && Die "File $lvKernelImage not found. Terminating."
     857
     858    # get offet of gzip magic "1f8b0800" in file
     859    lvOffset=`od -vA n -t x1 $lvKernelImage | tr -d '[:space:]' | awk '{ print match($0, "1f8b0800")}'`
     860    [ $lvOffset -eq 0 ] && Die "gzip magic not found in file $lvKernelImage. Terminating."
     861    lvOffset=`expr $lvOffset / 2`
     862    LogIt "  GetInitrdFilesystemToUse(): gzip magic found at lvOffset $lvOffset.\n"
     863
     864    # scan kernel image for initrd filessystem support
     865    lvScanRes=`dd ibs=1 skip=$lvOffset if=$lvKernelImage obs=1M 2>/dev/null | gunzip -c | strings | grep -e "$lcMagicCramfs" -e "$lcMagicExt2fs" -e "$lcMagicInitfs"`
     866
     867    # determine which filesystem to use for initrd image: ext2fs, gzip'ed cpio (initramfs ) or cramfs
     868    if [ `echo $lvScanRes | grep -c "$lcMagicExt2fs"` -eq 1 ]; then
     869        lvUseFilesystem="ext2fs"
     870    elif [ `echo $lvScanRes | grep -c "$lcMagicInitfs"` -eq 1 ]; then
     871        lvUseFilesystem="initramfs"
     872    elif [ `echo $lvScanRes | grep -c "$lcMagicCramfs"` -eq 1 ]; then
     873        lvUseFilesystem="cramfs"
     874    else
     875        lvUseFilesystem="UNSUPPORTED"
     876    fi
     877
     878    # say what we are using
     879    LogIt "  GetInitrdFilesystemToUse(): Filesytem to use for initrd is $lvUseFilesystem.\n"
     880
     881    # return file system to use
     882    echo "$lvUseFilesystem"
     883
     884}
     885
    828886# Searches parent raid device of given disk device
    829887# $1: disk device (i.e. /dev/hda1)
     
    27042762    echo "$disksize" > $mountpoint/tmp/$disksize.siz
    27052763    find $mountpoint -name CVS -exec rm -rf '{}' \;
    2706     umount $mountpoint || Die "Cannot unmount $tempfile"
    2707     dd if=$tempfile bs=1k 2> /dev/null | gzip -v9 > $rdz_fname 2> /dev/null
     2764    # Determine what filesystem to use for initrd image
     2765    LogIt "Call GetInitrdFilesystemToUse() with parameter ${kernelpath} to get filesystem to use for initrd.\n"
     2766    gvFileSystem=`GetInitrdFilesystemToUse ${kernelpath}`
     2767    [ -z  gvFileSystem ] && Die "GetFilesystemToUse() failed. Terminating."
     2768    case "$gvFileSystem" in
     2769    "ext2fs")
     2770        # say what will be used
     2771            LogIt "Creating an ext2 initrd image..."
     2772        # kernel expects linuxrc in ext2 filesystem
     2773        ( cd $mountpoint && ln -s sbin/init linuxrc )
     2774        # unmount loop filesystem and create image file using the standard approach
     2775        umount $mountpoint || Die "Cannot unmount $tempfile"
     2776        dd if=$tempfile bs=1k 2> /dev/null | gzip -v9 > $rdz_fname 2> /dev/null
     2777        # log that we are done
     2778            LogIt "done.\n"
     2779    ;;
     2780    "initramfs")
     2781        # say what will be used
     2782            LogIt "Creating a gzip'ed cpio (AKA initramfs) initrd image..."
     2783        # make sure that cpio is there
     2784        which cpio &> /dev/null; [ $? -eq 0 ] || Die "cpio not found. Please install package cpio and try again."
     2785        # go into filesystem
     2786        cd $mountpoint
     2787        # kernel expects init in cpio filesystem
     2788        ln -s sbin/init init
     2789        # create cpio image file and unmount loop filesystem
     2790        find . -print | cpio -o -H newc | gzip -9 > $old_pwd/$rdz_fname 2> /dev/null
     2791        cd $old_pwd
     2792        umount $mountpoint || Die "Cannot unmount $tempfile"
     2793        # log that we are done
     2794            LogIt "done.\n"
     2795    ;;
     2796    *)
     2797        Die "Filesystem $gvFileSystem not supported for initrd image. Terminating."
     2798    ;;
     2799    esac
    27082800    if [ "$res" -eq "0" ] ; then
    27092801        echo -en "..."
Note: See TracChangeset for help on using the changeset viewer.