0

I would like the make an image of Linux system. I have a SD card 64GB, but the system takes only 11 GB. dd command, Win32DiskManager, ... all create a raw image of 64 GB, way bigger than the 11 GB.

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        59G   11G   46G  20% /
devtmpfs        430M     0  430M   0% /dev
tmpfs           462M  4.0K  462M   1% /dev/shm
tmpfs           462M   13M  450M   3% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           462M     0  462M   0% /sys/fs/cgroup
/dev/mmcblk0p1   43M   25M   18M  59% /boot
tmpfs            93M  4.0K   93M   1% /run/user/1000

I have another 16 GB SD card, and would like transfer the whole system with to the 16 GB SD card. The best will be create a 11 GB img file I can burn on 16 GB SD cards later.

1 Answers1

0

You cannot write an image of a 64 GB device to a 16 GB card. That's in direct contradiction to what an "image" is.

But that doesn't matter at all: Linux only cares about the files on the file system, so use

sudo mksquashfs /path/where/you/mounted/your/sdcard sdcard.squashfs -comp zstd

to make a compressed archive of all the files, directories, symlinks, device files, … including all attributes.

You can later mount that archive, e.g. using udisksctl loop-setup -f sdcard.squashfs, or sudo mount -o loop sdcard.squashfs /mnt to look inside, get files from there and so on.

You can also restore all files to a freshly formatted (e.g. ext4, F2FS) SD card, either by mounting and using

sudo cp -ar /mnt/* /mount/point/of/sdcard

or simply by running

sudo unsquashfs -d /mount/point/of/sdcard sdcard.squashfs