summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2019-04-26 15:06:20 +0206
committerJohn Ogness <john.ogness@linutronix.de>2019-04-26 15:06:20 +0206
commitfb816880451696c1bdb72493b38a8c8778ac8fb9 (patch)
tree7caec9c37737f2704ffec9991ae227f760998f92
parenta25ffd05f44634ddfdfc987f22e3cd3006ab5e1e (diff)
dd-multi.sh: add --keep-files
The first couple steps of the dd-multi.sh script is to: 1. make a sparse copy of the original image 2. loop mount the copy 3. unpack the layers to the loop mount 4. create a vmdk of the copy 5. copy the image and vmdk to the usb drives If many USB drives need to be prepared at once, usually the dd-multi.sh script will need to be called multiple times (due to not enough USB-3 ports being available). However, there is no need for steps 1-4 to run each time. Add a --keep-files argument that will not delete the copy and vmdk files on completion. The --keep-files argument also tells the dd-multi.sh script to look for existing copy and vmdk files. If they are found, they are used. Signed-off-by: John Ogness <john.ogness@linutronix.de>
-rwxr-xr-xlx-trainer-vm/dd-multi.sh64
1 files changed, 45 insertions, 19 deletions
diff --git a/lx-trainer-vm/dd-multi.sh b/lx-trainer-vm/dd-multi.sh
index 78740f1..4dbaac7 100755
--- a/lx-trainer-vm/dd-multi.sh
+++ b/lx-trainer-vm/dd-multi.sh
@@ -13,6 +13,9 @@ usage_exit()
echo "example: copying image to devices: sde, sdf, sdg"
echo "$0 lx-trainer.img /dev/sde /dev/sdf /dev/sdg"
echo
+ echo " use --keep-files to speed up multiple calls"
+ echo " (so that vmdk and img can be re-used later)"
+ echo
exit 1
}
@@ -48,11 +51,15 @@ SRC=""
LAYERS=""
DESTS=""
+KEEP_FILES=0
for arg in $@; do
case $arg in
--layer=*)
LAYERS="$LAYERS `echo $arg | sed -e 's/^--layer=//'`"
;;
+ --keep-files)
+ KEEP_FILES=1
+ ;;
--*)
echo "error: unknown option: $arg"
usage_exit
@@ -97,10 +104,7 @@ if [ "`env - /sbin/parted --script $SRC print | \
fi
SRC_FILE="${SRC}_copy.img"
-VMDK_FILE="${SRC}.vmdk"
-
-echo 'creating a sparse copy of the image'
-cp -a --sparse=always $SRC $SRC_FILE
+VMDK_FILE="${SRC_FILE}.vmdk"
# setup temp directory for mountpoints
TMP_ROOT="/tmp/dd-multi-`date +%s`.$$"
@@ -108,26 +112,41 @@ rm -rf $TMP_ROOT
mkdir -p $TMP_ROOT
echo "using directory $TMP_ROOT for mount points"
-if [ -n "$LAYERS" ]; then
- LOOPDEV=`losetup --show -P -f $SRC_FILE`
- LOOPPT="${LOOPDEV}p${ROOTPT}"
+if [ $KEEP_FILES -eq 1 -a -f $SRC_FILE ]; then
+ echo 'using existing prepared copy of the image'
+ if [ -n "$LAYERS" ]; then
+ echo '(SPECIFIED LAYERS WILL NOT BE RE-UNPACKED)'
+ fi
+else
+ echo 'creating a sparse copy of the image'
+ cp -a --sparse=always $SRC $SRC_FILE
- mkdir -p ${TMP_ROOT}${LOOPPT}
- mount $LOOPPT ${TMP_ROOT}${LOOPPT}
+ if [ -n "$LAYERS" ]; then
+ LOOPDEV=`losetup --show -P -f $SRC_FILE`
+ LOOPPT="${LOOPDEV}p${ROOTPT}"
- for tarball in $LAYERS; do
- echo "unpacking layer: $tarball"
- tar -x -f $tarball --numeric-owner -C ${TMP_ROOT}${LOOPPT}
- done
+ mkdir -p ${TMP_ROOT}${LOOPPT}
+ mount $LOOPPT ${TMP_ROOT}${LOOPPT}
- sync
- umount ${LOOPPT}
+ for tarball in $LAYERS; do
+ echo "unpacking layer: $tarball"
+ tar -x -f $tarball --numeric-owner \
+ -C ${TMP_ROOT}${LOOPPT}
+ done
- losetup -d $LOOPDEV
+ sync
+ umount ${LOOPPT}
+
+ losetup -d $LOOPDEV
+ fi
fi
-echo 'creating vmdk file'
-qemu-img convert -O vmdk $SRC_FILE $VMDK_FILE
+if [ $KEEP_FILES -eq 1 -a -f $VMDK_FILE ]; then
+ echo 'using existing prepared vmdk file'
+else
+ echo 'creating vmdk file'
+ qemu-img convert -O vmdk $SRC_FILE $VMDK_FILE
+fi
# delete mbr's
dd if=/dev/zero bs=10M count=1 2> /dev/null | tee $DESTS > /dev/null
@@ -181,6 +200,13 @@ for dest in $DESTS; do
done
# cleanup temp directory
-rm -rf $TMP_ROOT $VMDK_FILE $SRC_FILE
+rm -rf $TMP_ROOT
+if [ $KEEP_FILES -ne 1 ]; then
+ rm -f $VMDK_FILE $SRC_FILE
+else
+ echo "as requested, not removing:"
+ echo " $VMDK_FILE"
+ echo " $SRC_FILE"
+fi
echo 'done, no errors'