diff options
| author | John Ogness <john.ogness@linutronix.de> | 2019-01-28 20:17:39 +0106 |
|---|---|---|
| committer | John Ogness <john.ogness@linutronix.de> | 2019-01-28 20:25:28 +0106 |
| commit | 0ebf05951ff0855d96ed53730269e4a07c4e860f (patch) | |
| tree | db67c880979b512027bc47bc9981e7dcb1e641dd | |
| parent | 34d19fc6b1a814a9b65651980011d6a47af606d1 (diff) | |
dd-multi: create vmdk partition instead of /home parition
As of 6f5bc54("lx-trainer-vm: increase image size to 64GiB") the
root filesystem is now large enough for all layers and training
work. So there is no reason to create a separate /home partition.
Change the dd-multi.sh script to instead:
- create an exfat partition
- convert the image to VMDK format and copy to exfat partition
This allows participants who cannot boot from USB to be able to
use VMware or VirtualBox during the training. They need only to
create a virtual machine and set the "training-hd.vmdk" file as
the hard drive.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
| -rwxr-xr-x | lx-trainer-vm/dd-multi.sh | 122 |
1 files changed, 63 insertions, 59 deletions
diff --git a/lx-trainer-vm/dd-multi.sh b/lx-trainer-vm/dd-multi.sh index 01105aa..d31482b 100755 --- a/lx-trainer-vm/dd-multi.sh +++ b/lx-trainer-vm/dd-multi.sh @@ -27,6 +27,22 @@ if [ `id -u` -ne 0 ]; then exit 1 fi +if [ -z "`which mkexfatfs`" ]; then + echo "error: mkexfatfs program not found" + echo + echo "try this:" + echo "sudo apt install exfat-utils exfat-fuse" + exit 1 +fi + +if [ -z "`which qemu-img`" ]; then + echo "error: qemu-img program not found" + echo + echo "try this:" + echo "sudo apt install qemu-utils" + exit 1 +fi + # gather arguments SRC="" LAYERS="" @@ -51,8 +67,8 @@ for arg in $@; do esac done -# source must be file or block device -if [ ! -f "$SRC" -a ! -b "$SRC" ]; then +# source must be file +if [ ! -f "$SRC" ]; then echo "error: invalid src" usage_exit fi @@ -80,19 +96,51 @@ if [ "`env - /sbin/parted --script $SRC print | \ usage_exit 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 + +# setup temp directory for mountpoints +TMP_ROOT="/tmp/dd-multi-`date +%s`.$$" +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}" + + mkdir -p ${TMP_ROOT}${LOOPPT} + mount $LOOPPT ${TMP_ROOT}${LOOPPT} + + for tarball in $LAYERS; do + echo "unpacking layer: $tarball" + tar -x -f $tarball --numeric-owner -C ${TMP_ROOT}${LOOPPT} + done + + sync + umount ${LOOPPT} + + losetup -d $LOOPDEV +fi + +echo 'creating vmdk file' +qemu-img convert -O vmdk $SRC_FILE $VMDK_FILE + # delete mbr's dd if=/dev/zero bs=10M count=1 2> /dev/null | tee $DESTS > /dev/null +partprobe $DESTS # efficiently copy source to all destinations and rescan devices -echo 'monitor copy status with: sudo kill -s USR1 `pidof dd`' -dd if=$SRC bs=64M | tee $DESTS > /dev/null - -echo 'setting up /home partition' +echo 'writing image to disks, monitor with: sudo kill -s USR1 `pidof dd`' +dd if=$SRC_FILE bs=64M | tee $DESTS > /dev/null -# fix partition table and add extra /home partition +# fix partition table and add extra partition for dest in $DESTS; do - parted $dest print fix > /dev/null 2>&1 - parted --script --align optimal -- $dest mkpart /home 17GB -1MB + echo fix | sudo parted ---pretend-input-tty $dest print > /dev/null 2>&1 + parted --script --align optimal -- $dest mkpart /extra ntfs 128GB 256GB done # rescan devices @@ -112,66 +160,22 @@ for dest in $DESTS; do sleep 1 done done +sleep 1 -# create ext4 on home partition +# create exfat on extra partition for dest in $DESTS; do - mkfs.ext4 -L lxhome ${dest}${EXTRAPT} > /dev/null 2>&1 & + mkexfatfs ${dest}${EXTRAPT} > /dev/null 2>&1 done -wait - -# setup temp directory for mountpoints -TMP_ROOT="/tmp/dd-multi-`date +%s`.$$" -rm -rf $TMP_ROOT -mkdir -p $TMP_ROOT -echo "using directory $TMP_ROOT for mount points" for dest in $DESTS; do - # create mountpoints - mkdir -p ${TMP_ROOT}${dest}${ROOTPT} mkdir -p ${TMP_ROOT}${dest}${EXTRAPT} - - # mount partitions - mount ${dest}${ROOTPT} ${TMP_ROOT}${dest}${ROOTPT} mount ${dest}${EXTRAPT} ${TMP_ROOT}${dest}${EXTRAPT} - - # move home directories (if any) to home partition - if [ -n "`ls ${TMP_ROOT}${dest}${ROOTPT}/home`" ]; then - echo "moving /home/* to ${dest}${EXTRAPT}" - mv ${TMP_ROOT}${dest}${ROOTPT}/home/* ${TMP_ROOT}${dest}${EXTRAPT}/ - fi - - # setup home partition to be mounted as /home - echo 'LABEL=lxhome /home ext4 defaults 0 0' | \ - tee -a ${TMP_ROOT}${dest}${ROOTPT}/etc/fstab > /dev/null - - # remount home to /home + cp -v $VMDK_FILE ${TMP_ROOT}${dest}${EXTRAPT}/training-hd.vmdk + sync umount ${TMP_ROOT}${dest}${EXTRAPT} - mount ${dest}${EXTRAPT} ${TMP_ROOT}${dest}${ROOTPT}/home -done - -# unpack layers (in parallel) -for tarball in $LAYERS; do - echo "unpacking layer: $tarball" - for dest in $DESTS; do - tar -x -f $tarball --numeric-owner \ - -C ${TMP_ROOT}${dest}${ROOTPT} & - done - wait -done - -for dest in $DESTS; do - # If there were no layer files added, umount might return a busy - # error since we just mounted. (Possibly a kernel bug.) By - # accessing the filesytem before unmounting it, the mount/umount - # problem seems to go away. Use "ls" to access the filesystem. - ls ${TMP_ROOT}${dest}${ROOTPT}/home/ > /dev/null - - # unmount partitions - umount ${TMP_ROOT}${dest}${ROOTPT}/home - umount ${TMP_ROOT}${dest}${ROOTPT} done # cleanup temp directory -rm -rf $TMP_ROOT +rm -rf $TMP_ROOT $VMDK_FILE $SRC_FILE echo 'done, no errors' |
