summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlx-trainer-vm/dd-multi.sh63
1 files changed, 27 insertions, 36 deletions
diff --git a/lx-trainer-vm/dd-multi.sh b/lx-trainer-vm/dd-multi.sh
index 2af3798..998aaf5 100755
--- a/lx-trainer-vm/dd-multi.sh
+++ b/lx-trainer-vm/dd-multi.sh
@@ -6,14 +6,14 @@ usage_exit()
echo
echo "usage: $0 src [--layer=tarball]... dest [dest]..."
echo
- echo "example: copying image to devs sde, sdf, sdg"
+ echo "example: copying image to devices: sde, sdf, sdg"
echo "$0 lx-trainer.img /dev/sde /dev/sdf /dev/sdg"
echo
exit 1
}
if [ `id -u` -ne 0 ]; then
- echo "error: this script must be run as root"
+ echo "error: sorry, this script must be run as root"
exit 1
fi
@@ -29,22 +29,22 @@ LAYERS=""
DESTS=""
for arg in $@; do
-case $arg in
---layer=*)
- LAYERS="$LAYERS `echo $arg | sed -e 's/^--layer=//'`"
- ;;
---*)
- echo "error: unknown option: $arg"
- usage_exit
- ;;
-*)
- if [ -z "$SRC" ]; then
- SRC="$arg"
- else
- DESTS="$DESTS $arg"
- fi
- ;;
-esac
+ case $arg in
+ --layer=*)
+ LAYERS="$LAYERS `echo $arg | sed -e 's/^--layer=//'`"
+ ;;
+ --*)
+ echo "error: unknown option: $arg"
+ usage_exit
+ ;;
+ *)
+ if [ -z "$SRC" ]; then
+ SRC="$arg"
+ else
+ DESTS="$DESTS $arg"
+ fi
+ ;;
+ esac
done
# source must be file or block device
@@ -61,31 +61,22 @@ for dest in $DESTS; do
fi
done
-# check if we are root (but keep going)
-if [ `id -u` -ne 0 ]; then
- echo "warning: not root, may not work"
-fi
+# delete mbr's and rescan devices
+dd if=/dev/zero bs=1M count=10 | tee $DESTS > /dev/null
+partprobe $DESTS
-# delete mbr
-for dest in $DESTS; do
- dd if=/dev/zero of=$dest bs=1M count=1 &
-done
-wait
-
-partprobe
-
-# efficiently copy source to all destinations
+# efficiently copy source to all destinations and rescan devices
cat $SRC | tee $DESTS > /dev/null
-
-partprobe
+partprobe $DESTS
# add 2nd partition
for dest in $DESTS; do
- /bin/echo -e "n\np\n\n\n\nw" | fdisk $dest &
+ /bin/echo -e "n\np\n\n\n\nw" | fdisk $dest
done
-wait
+sync
-partprobe
+# rescan devices
+partprobe $DESTS
# create ext4 on 2nd partition
for dest in $DESTS; do