Updated the tool for virtual HDD image generation. It should behave better when Ubuntu tries to open the mounted image.
This commit is contained in:
parent
691a321ead
commit
e01d0905d5
@ -1,5 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
# Create sparse file of 20MB which can be used by QEMU.
|
# Create sparse file of 20MB which can be used by QEMU.
|
||||||
|
|
||||||
if [ "$1" = "-e" -o "$1" = "--empty" ] ; then
|
if [ "$1" = "-e" -o "$1" = "--empty" ] ; then
|
||||||
@ -35,7 +37,9 @@ elif [ "$1" = "-f" -o "$1" = "--folder" ] ; then
|
|||||||
echo "This file is on external hard disk." > folder/minimal/rootfs/overlay.txt
|
echo "This file is on external hard disk." > folder/minimal/rootfs/overlay.txt
|
||||||
echo "Created sample text file."
|
echo "Created sample text file."
|
||||||
|
|
||||||
|
sync
|
||||||
umount folder
|
umount folder
|
||||||
|
sync
|
||||||
rm -rf folder
|
rm -rf folder
|
||||||
echo "Unmounted hard disk image file."
|
echo "Unmounted hard disk image file."
|
||||||
|
|
||||||
@ -44,7 +48,6 @@ elif [ "$1" = "-f" -o "$1" = "--folder" ] ; then
|
|||||||
|
|
||||||
# Find the original user. Note that this may not always be correct.
|
# Find the original user. Note that this may not always be correct.
|
||||||
ORIG_USER=`who | awk '{print \$1}'`
|
ORIG_USER=`who | awk '{print \$1}'`
|
||||||
|
|
||||||
chown $ORIG_USER hdd.img
|
chown $ORIG_USER hdd.img
|
||||||
echo "Applied original ownership to hard disk image file."
|
echo "Applied original ownership to hard disk image file."
|
||||||
elif [ "$1" = "-s" -o "$1" = "--sparse" ] ; then
|
elif [ "$1" = "-s" -o "$1" = "--sparse" ] ; then
|
||||||
@ -64,6 +67,7 @@ elif [ "$1" = "-s" -o "$1" = "--sparse" ] ; then
|
|||||||
mkfs.vfat $LOOP_DEVICE_HDD
|
mkfs.vfat $LOOP_DEVICE_HDD
|
||||||
echo "Hard disk image file has been formatted with FAT filesystem."
|
echo "Hard disk image file has been formatted with FAT filesystem."
|
||||||
|
|
||||||
|
rm -rf sparse
|
||||||
mkdir sparse
|
mkdir sparse
|
||||||
mount hdd.img sparse
|
mount hdd.img sparse
|
||||||
echo "Mounted hard disk image file to temporary folder."
|
echo "Mounted hard disk image file to temporary folder."
|
||||||
@ -93,7 +97,9 @@ elif [ "$1" = "-s" -o "$1" = "--sparse" ] ; then
|
|||||||
chown -R root:root ovl
|
chown -R root:root ovl
|
||||||
echo "Applied root ownership to overlay content."
|
echo "Applied root ownership to overlay content."
|
||||||
|
|
||||||
|
sync
|
||||||
umount ovl
|
umount ovl
|
||||||
|
sync
|
||||||
sleep 1
|
sleep 1
|
||||||
rm -rf ovl
|
rm -rf ovl
|
||||||
echo "Unmounted overlay image file."
|
echo "Unmounted overlay image file."
|
||||||
@ -102,7 +108,9 @@ elif [ "$1" = "-s" -o "$1" = "--sparse" ] ; then
|
|||||||
sleep 1
|
sleep 1
|
||||||
echo "Overlay image file has been detached from loop device."
|
echo "Overlay image file has been detached from loop device."
|
||||||
|
|
||||||
|
sync
|
||||||
umount sparse
|
umount sparse
|
||||||
|
sync
|
||||||
sleep 1
|
sleep 1
|
||||||
rm -rf sparse
|
rm -rf sparse
|
||||||
echo "Unmounted hard disk image file."
|
echo "Unmounted hard disk image file."
|
||||||
@ -110,8 +118,11 @@ elif [ "$1" = "-s" -o "$1" = "--sparse" ] ; then
|
|||||||
losetup -d $LOOP_DEVICE_HDD
|
losetup -d $LOOP_DEVICE_HDD
|
||||||
sleep 1
|
sleep 1
|
||||||
echo "Hard disk image file has been detached from loop device."
|
echo "Hard disk image file has been detached from loop device."
|
||||||
|
# Find the original user. Note that this may not always be correct.
|
||||||
|
ORIG_USER=`who | awk '{print \$1}'`
|
||||||
|
|
||||||
|
chown $ORIG_USER hdd.img
|
||||||
|
|
||||||
chown $(logname) hdd.img
|
|
||||||
echo "Applied original ownership to hard disk image file."
|
echo "Applied original ownership to hard disk image file."
|
||||||
elif [ "$1" = "-h" -o "$1" = "--help" ] ; then
|
elif [ "$1" = "-h" -o "$1" = "--help" ] ; then
|
||||||
cat << CEOF
|
cat << CEOF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user