diff options
| author | John Ogness <john.ogness@linutronix.de> | 2018-04-05 14:57:42 +0200 |
|---|---|---|
| committer | John Ogness <john.ogness@linutronix.de> | 2018-04-05 14:57:42 +0200 |
| commit | c01430b37be9903fc8f144920d60dc2aa4f208c9 (patch) | |
| tree | 3377b072980b9143fff33cd1621759e0c024b726 | |
| parent | d1af6befdc11877d642208ac38c5652e3fbdd767 (diff) | |
dd-multi: update/cleanup for gpt support
- require gpt images and expect partition layout
and sizes from lx-trainer-vm.xml
- cleanup output
- use dd instead of cat (to allow progress status)
- use parted instead of fdisk (necessary to fix gpt table)
- remove unnecessary partprobe's
Signed-off-by: John Ogness <john.ogness@linutronix.de>
| -rwxr-xr-x | lx-trainer-vm/dd-multi.sh | 90 |
1 files changed, 56 insertions, 34 deletions
diff --git a/lx-trainer-vm/dd-multi.sh b/lx-trainer-vm/dd-multi.sh index c99fca7..50f8786 100755 --- a/lx-trainer-vm/dd-multi.sh +++ b/lx-trainer-vm/dd-multi.sh @@ -1,10 +1,14 @@ #!/bin/sh set -e +# This script only supports GPT partitions for the lx-trainer image. +ROOTPT=3 +HOMEPT=4 + usage_exit() { echo - echo "usage: $0 src [--layer=tarball]... dest [dest]..." + echo "usage: sudo $0 src [--layer=tarball]... dest [dest]..." echo echo "example: copying image to devices: sde, sdf, sdg" echo "$0 lx-trainer.img /dev/sde /dev/sdf /dev/sdg" @@ -12,17 +16,17 @@ usage_exit() exit 1 } -if [ `id -u` -ne 0 ]; then - echo "error: sorry, this script must be run as root" - exit 1 -fi - # minimum 2 arguments if [ $# -lt 2 ]; then echo "error: invalid arguments" usage_exit fi +if [ `id -u` -ne 0 ]; then + echo "error: sorry, this script must be run as root" + exit 1 +fi + # gather arguments SRC="" LAYERS="" @@ -61,36 +65,49 @@ for dest in $DESTS; do fi done -# delete mbr's and rescan devices -dd if=/dev/zero bs=1M count=10 | tee $DESTS > /dev/null -partprobe $DESTS +# detect partion type of source +if [ "`env - /sbin/parted --script $SRC print | \ + grep 'Partition Table' | awk '{print $3}'`" != "gpt" ]; then + echo "error: only gpt partition tables supported" + usage_exit +fi + +# delete mbr's +dd if=/dev/zero bs=10M count=1 2> /dev/null | tee $DESTS > /dev/null # efficiently copy source to all destinations and rescan devices -cat $SRC | tee $DESTS > /dev/null -partprobe $DESTS +echo 'monitor copy status with: sudo kill -s USR1 `pidof dd`' +dd if=$SRC bs=64M | tee $DESTS > /dev/null -# add 2nd partition +echo 'setting up /home partition' + +# fix partition table and add extra /home partition for dest in $DESTS; do - /bin/echo -e "n\np\n\n\n\nw" | fdisk $dest + parted $dest print fix > /dev/null 2>&1 + parted --script --align optimal -- $dest mkpart /home 17GB -1MB done # rescan devices -while ! partprobe $DESTS; do +while ! partprobe $DESTS 2> /dev/null; do echo "waiting for partprobe..." sleep 1 done # wait for partitions to appear for dest in $DESTS; do - while [ ! -b ${dest}2 ]; do - echo "waiting for ${dest}2..." + while [ ! -b ${dest}${ROOTPT} ]; do + echo "waiting for ${dest}${ROOTPT}..." + sleep 1 + done + while [ ! -b ${dest}${HOMEPT} ]; do + echo "waiting for ${dest}${HOMEPT}..." sleep 1 done done -# create ext4 on 2nd partition +# create ext4 on home partition for dest in $DESTS; do - mkfs.ext4 -L lxhome ${dest}2 & + mkfs.ext4 -L lxhome ${dest}${HOMEPT} > /dev/null 2>&1 & done wait @@ -98,27 +115,28 @@ wait TMP_ROOT="/tmp/dd-multi-`date +%s`.$$" rm -rf $TMP_ROOT mkdir -p $TMP_ROOT -echo "using temp directory $TMP_ROOT" +echo "using directory $TMP_ROOT for mount points" for dest in $DESTS; do # create mountpoints - mkdir -p ${TMP_ROOT}${dest}1 - mkdir -p ${TMP_ROOT}${dest}2 + mkdir -p ${TMP_ROOT}${dest}${ROOTPT} + mkdir -p ${TMP_ROOT}${dest}${HOMEPT} # mount partitions - mount ${dest}1 ${TMP_ROOT}${dest}1 - mount ${dest}2 ${TMP_ROOT}${dest}2 + mount ${dest}${ROOTPT} ${TMP_ROOT}${dest}${ROOTPT} + mount ${dest}${HOMEPT} ${TMP_ROOT}${dest}${HOMEPT} - # move home directories to 2nd partition - mv ${TMP_ROOT}${dest}1/home/* ${TMP_ROOT}${dest}2/ + # move home directories to home partition + echo "moving /home/* to ${dest}${HOMEPT}" + mv ${TMP_ROOT}${dest}${ROOTPT}/home/* ${TMP_ROOT}${dest}${HOMEPT}/ - # setup 2nd partition to be mounted as /home + # setup home partition to be mounted as /home echo 'LABEL=lxhome /home ext4 defaults 0 0' | \ - tee -a ${TMP_ROOT}${dest}1/etc/fstab + tee -a ${TMP_ROOT}${dest}${ROOTPT}/etc/fstab > /dev/null # copy layer tarballs to /home for tarball in $LAYERS; do - destfile="${TMP_ROOT}${dest}2/`basename $tarball`" + destfile="${TMP_ROOT}${dest}${HOMEPT}/`basename $tarball`" if [ -f $destfile ]; then echo echo "WARNING: OVERWRITING $destfile" 1>&2 @@ -129,20 +147,24 @@ for dest in $DESTS; do done # remount home to /home - umount ${TMP_ROOT}${dest}2 - mount ${dest}2 ${TMP_ROOT}${dest}1/home + umount ${TMP_ROOT}${dest}${HOMEPT} + mount ${dest}${HOMEPT} ${TMP_ROOT}${dest}${ROOTPT}/home # unpack layers for tarball in $LAYERS; do destfile=`basename $tarball` - chroot ${TMP_ROOT}${dest}1 tar -x -f /home/$destfile --numeric-owner -C / - rm ${TMP_ROOT}${dest}1/home/$destfile + echo "unpacking $destfile to ${dest}" + chroot ${TMP_ROOT}${dest}${ROOTPT} \ + tar -x -f /home/$destfile --numeric-owner -C / + rm ${TMP_ROOT}${dest}${ROOTPT}/home/$destfile done # unmount partitions - umount ${TMP_ROOT}${dest}1/home - umount ${TMP_ROOT}${dest}1 + umount ${TMP_ROOT}${dest}${ROOTPT}/home + umount ${TMP_ROOT}${dest}${ROOTPT} done # cleanup temp directory rm -rf $TMP_ROOT + +echo "done, no errors" |
