Ignore:
Timestamp:
Apr 14, 2014, 6:47:07 PM (10 years ago)
Author:
cfuguet
Message:

Optimization in disk image generation

When disk image exists, we dont need to recreate it, we only
copy new files in it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/create_dmg

    r300 r302  
    4242
    4343                        if [[ -z $2 ]]; then
    44                                 echo "Create action need second argument: <srcdir_path>"
     44                                echo "Create action need second argument: <disk_image>"
    4545                                exit 1;
    4646                        fi;
    47 
    48                         if [[ -z $3 ]]; then
    49                                 echo "Create action need third argument: <disk_image>"
    50                                 exit 1;
    51                         fi;
    52 
    53                         # RAW DISK IMAGE READ-ONLY
    54                         # The not used space is not considered (smaller disk image)
    55                         # format="UDRO"
    56 
    57                         # RAW DISK IMAGE READ-WRITE
    58                         # None compression is made
    59                         format="UDRW"
    6047
    6148                        # -F FAT type = 32 (FAT32)
     
    6451                        # -r reserved sectors
    6552                        # -k backup boot sector (VBR and FS INFO) = 0xffff (no backup)
    66                         echo "Creating partition file $3.dmg from $2 directory"
     53                        echo "Creating empty disk image: $2.dmg"
    6754                        fsargs="-F32 -c $sectors_per_cluster -n 1 -r $reserved_sectors -k 0xffff"
     55
     56                        # -layout = NONE (No partition scheme. Hence no Master Boot Record)
    6857                        hdiutil create \
    6958                                -fs MS-DOS \
    7059                                -volname virtualdisk \
    71                                 -srcfolder $2 \
     60                                -layout NONE \
    7261                                -sectors $sectors \
    7362                                -ov \
    7463                                -fsargs "$fsargs" \
    75                                 -format $format \
    76                                 $3;
    77 #                               -verbose \
    78 
    79                         echo "Removing first sector of diskimage"
    80 
    81                         if [[ -e "/tmp" ]]; then
    82                                 if [[ -e "/tmp/diskimage" ]]; then
    83                                         echo "Warning /tmp/diskimage exists already. Rename it or"
    84                                         echo "remove it before executing this script"
    85                                         exit
    86                                 fi;
    87 
    88                                 dd if=$3.dmg of=/tmp/diskimage iseek=1 oseek=0
    89                                 mv /tmp/diskimage $3.dmg
    90                         fi;;
     64                                -type "UDIF" \
     65                                $2;
     66                        ;;
    9167
    9268                attach )
    9369                        # Attach created disk image to the system and mount it
    94                         hdiutil attach $2;;
     70                        hdiutil attach $2
     71                        ;;
    9572
    9673                detach )
    9774                        # Detach attached device. Must pass as parameter the /dev/<device>
    98                         hdiutil detach $2;;
     75                        hdiutil detach $2
     76                        ;;
    9977
    10078                info )
    101                         hdiutil imageinfo $2;;
     79                        hdiutil imageinfo $2
     80                        ;;
    10281
    10382                * )
    10483                        echo "Pass the command as the first parameter: "
    10584                        echo "  - create: create disk image"
    106                         echo "            First parameter after create action is the path"
    107                     echo "            of the directory to copy in the created "
    108                         echo "            partition"
    10985                        echo "  - attach: attach created disk image to the system and "
    11086                        echo "            mount it (arg: path to disk_image)"
     
    11591                        echo ""
    11692                        echo "EXAMPLES:"
    117                         echo " ./create_diskimage.sh create /path/to/source_dir disk_image"
     93                        echo " ./create_diskimage.sh create disk_image"
    11894                        echo " ./create_diskimage.sh attach /path/to/disk_image.dmg"
    11995                        echo " ./create_diskimage.sh detach /dev/disk5"
    12096                        echo " ./create_diskimage.sh info   /path/to/disk_image.dmg"
     97                        ;;
    12198        esac;
    12299
     
    124101        case $1 in
    125102                create )
     103
    126104                        if [[ -z $2 ]]; then
    127                                 echo "Create action need second argument: <srcdir_path>"
     105                                echo "Create action need second argument: <disk_image>"
    128106                                exit 1;
    129107                        fi;
    130108
    131                         if [[ -z $3 ]]; then
    132                                 echo "Create action need third argument: <disk_image>"
    133                                 exit 1;
    134                         fi;
    135 
    136                         echo "Creating partition file: $3"
     109                        echo "Creating empty disk image: $2"
    137110
    138111                        let "sectors = (sectors - 1) / 2"
     
    145118                                -s $sectors_per_cluster \
    146119                                -v \
    147                                 $3.dmg $sectors
    148 
    149                         if [[ -e $2 ]]; then
    150                                 echo "Copying files from $2 into partition"
    151                                 mcopy -s -i $3.dmg $2/* :://
    152                         fi;;
     120                                $2.dmg $sectors
     121                        ;;
    153122
    154123                * )
    155124                        echo "Pass the command as the first parameter: "
    156125                        echo "  - create: create disk image"
    157                         echo "            First parameter after create action is the path"
    158                     echo "            of the directory to copy in the created "
    159                         echo "            partition"
    160126                        echo ""
    161127                        echo "EXAMPLES:"
    162                         echo " ./create_diskimage.sh create /path/to/source_dir disk_image"
     128                        echo " ./create_diskimage.sh create disk_image"
     129                        ;;
    163130        esac;
    164131
Note: See TracChangeset for help on using the changeset viewer.