Jump to content

Create system image that isn't huge

So I'm on a journey to figure out a good method to create a system image from a Raspberry Pi or any other Linux machine. So far I've tried Win32DiskImager, but it kinda sucks that if the image is on a 32GB SD card, the image file I create is 32GB's. I would assume using something like dd would create the same thing?

 

Is there an program or something out there that can make an image that is the same size as what is actually taken up on the disk I'm copying from and not all write all the blank space that wasn't being used?

 

Thanks in advance dudes!

Desktop: i9 11900k, 32GB DDR4, 4060 Ti 8GB 🙂

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

One word: compression. If most of your sd card is empty, compressing the image will result in a way smaller file. 7zip is pretty good.

 

Just for the sake of argument you could use tar to create an archive of your file system without making a bitwise copy of your sd card. Tar isn't very intuitive though and since the end result would be pretty much the same as just compressing what you have, I wouldn't bother.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

DD has a sparse option, which will result in an actual image size smaller for what is actually allocated while maintaining the partition size

 

search "DD sparse file" in Google

Link to comment
Share on other sites

Link to post
Share on other sites

On 2/13/2019 at 3:37 PM, Sauron said:

One word: compression. If most of your sd card is empty, compressing the image will result in a way smaller file. 7zip is pretty good.

  

Just for the sake of argument you could use tar to create an archive of your file system without making a bitwise copy of your sd card. Tar isn't very intuitive though and since the end result would be pretty much the same as just compressing what you have, I wouldn't bother. 

This ^

 

# dd bs=128k if=/dev/sdX | pigz -cz | dd bs=1M of=/path/to/where/you/want/to/save/it.img.gz

 

NOTES: bs should be 4k or larger (especially when writing to a flash device), you often see better perf with larger values.  pigz is just gzip but parallelized.  You don't have to use pigz, you can use gzip or bzip etc also.

 

Advanced stuff below:

If the images are still too large, you can use zerofree or the dd trick to make the FS more compressable.  dd trick being:

# dd bs=1M if=/dev/zero of=./temp.file ; rm /temp.file

This will cause most of the unused space (other than inodes) to be zeroed out.  So the FS gets compressed better.  If you're doing this, it needs to get done per FS/partition.   If you REALLY want the images small, you can zero the swap partition and then recreated it but that's often more work than is needed.

"Anger, which, far sweeter than trickling drops of honey, rises in the bosom of a man like smoke."

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×