summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2018-02-19 15:09:59 +0100
committerJohn Ogness <john.ogness@linutronix.de>2018-02-19 15:09:59 +0100
commit03775051c72b38d5ff14050d755d278c8c83125d (patch)
treece8c56e7b402c583cb37e744d3169a7656711ed1
parente0a9b373261726395e470ed596959eecb8f65ab8 (diff)
dd-multi.sh: change partitioning procedure
Initially write 10MB of 0's instead of 1MB to make sure any tables at the beginning are really gone. Rather than calling 'partprobe' with no arguments, explicitly pass the list of devices to re-read. 'fdisk' is used to create the 2nd (/home) partition. Do not do that in the background but instead synchronously for each device. Add a 'sync' afterwards to hopefully create a barrier before rescanning the devices. This is should address a problem where 'partprobe' is run too early and the kernel does not find the 2nd partition of the last device. Signed-off-by: John Ogness <john.ogness@linutronix.de>
-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