Sparse (Shrunken) Image Cloning Instructions:
Plug in bootable Ubuntu persistent live USB with image file in usbdata partition into Single-Board Computer such as UP² Board. Boot to USB (default persistent live option).
Launch Terminal and type in the following command (single line):
sudo dd if=/media/ubuntu/usbdata/ubuntu.img of=/dev/mmcblk0 bs=1M status=progress
Wait 15-20 minutes. When completed, shutdown and disconnect USB.
Boot to internal eMMC drive
Creating the Image:
Create uncompressed sparse image file from internal eMMC and save to flash drive
sudo dd if=/dev/mmcblk0 bs=1M status=progress | cp --sparse=always /dev/stdin /media/ubuntu/usbdata/ubuntu.img
Extract uncompressed image file to internal eMMC
sudo dd if=/media/ubuntu/usbdata/ubuntu.img of=/dev/mmcblk0 bs=1M status=progress
Create compressed image file from internal eMMC and save to Desktop
sudo dd if=/dev/mmcblk0 bs=1M status=progress | gzip > /home/user/Desktop/ubuntu.img.gz
Extract compressed image file to internal eMMC
sudo gzip -cd /home/user/Desktop/ubuntu.img.gz | dd of=/dev/mmcblk0 bs=1M status=progress
Sources:
http://dustymabe.com/2012/11/15/create-a-disk-image-without-enough-free-space/
https://forum.up-community.org/discussion/1197/solved-cloning-the-image-of-an-up-board
To modify an existing Linux image or drive from within Linux, plug in drive or mount the image:
sudo mkdir /media/root
sudo mount -t ext4 -o loop,offset=537919488 /media/user/usbdata/ubuntu.img /media/root
To determine the offset for your image or drive, run:
fdisk -l /media/user/usbdata/ubuntu.img
Then, multiply block-size of 512 bytes by the start-block of the Linux partition, 1050624. 512*1050624 = 537,919,488
Also mount other system folders:
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /media/root$i; done
Then cd into root folder of img and chroot:
cd /media/root
sudo chroot .
Then you can update files, passwd, etc. To unmount, run:
for i in /dev /dev/pts /proc /sys /run; do sudo umount /media/root$i; done
sudo umount /media/root
Creating Ubuntu Persistent Live USB Image
Follow these steps to flash a USB drive with a persistent live installation of Ubuntu: https://www.howtogeek.com/howto/14912/create-a-persistent-bootable-ubuntu-usb-flash-drive/