Lxw2015
Posts: 84
Joined: Fri Feb 12, 2016 4:05 am

save RPi Micro SD to a image

Wed Aug 12, 2020 2:52 pm

Hi, Friends,
I flashed a SD card with OS, update, upgrade, and install some packages. now I want save SD card. so next time, I don't need install package again. I use SD clone generate a image file. the image is the size of my SD card, 32G. I check the SD card files, it only ~80M. How could I just generate the SD card image to reflect files on the SD card, rather than entire SD card.

thanks
Xian

User avatar
TommyG007
Posts: 64
Joined: Fri Jun 26, 2020 4:30 pm
Location: South Wales, UK

Re: save RPi Micro SD to a image

Wed Aug 12, 2020 6:11 pm

Take a look at this thread, a user has modified the piclone program so it can create and save a .img file anywhere: viewtopic.php?f=63&t=281190&p=1710151#p1710151

Lxw2015
Posts: 84
Joined: Fri Feb 12, 2016 4:05 am

Re: save RPi Micro SD to a image

Wed Aug 12, 2020 7:16 pm

thanks for reply. but that is not what I m looking for. I don't want clone whole SD card. I just need the necessary OS image. which is much smaller than whole SD card size.

User avatar
TommyG007
Posts: 64
Joined: Fri Jun 26, 2020 4:30 pm
Location: South Wales, UK

Re: save RPi Micro SD to a image

Wed Aug 12, 2020 7:21 pm

The image files it creates are far smaller than the SD card, for me, it creates 8GB images. It doesn't matter what size SD card is in the Pi at the time.

User avatar
CaptainMidnight
Posts: 150
Joined: Sun Nov 03, 2019 4:32 pm
Location: UK

Re: save RPi Micro SD to a image

Thu Aug 13, 2020 12:15 am

Lxw2015 wrote:
Wed Aug 12, 2020 2:52 pm
I use SD clone generate a image file. the image is the size of my SD card, 32G. I check the SD card files, it only ~80M.

Not sure what you are using to tell you that you are only using 80MB? A good way to clarify your understanding of what is actually being used and required to duplicate your current configuration, is to use the command 'df -h' at the cli prompt: -

Code: Select all

pi@phoenix-pi-noc:~ $ df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/root             29G  5.4G   23G  20% /
/dev/mmcblk0p1       253M   55M  198M  22% /boot

The above is a cut-down output of the 'df -h' command - it shows a PiOS 32bit install on a 32GB SDcard, which is currenlty sitting at 5.45GB used (root and boot partitions).

Using the SDcard to Img file utility as referenced by TommyG007, i.e. imgclone https://github.com/tom-2015/imgclone and forum post viewtopic.php?f=63&t=281190, you would be able to create a compressed xxxxxxx.img.bz2 file of 2.05GB in this instance.

The compressed image file could then be used in an image writer to recreate your as of now, fully updated and configured SDcard in the future.

Just a thought ;)
"Never get out of the boat." Absolutely goddamn right!
Unless you were goin' all the way...

Lxw2015
Posts: 84
Joined: Fri Feb 12, 2016 4:05 am

Re: save RPi Micro SD to a image

Thu Aug 13, 2020 5:08 pm

I tried imgclone. failed. see below.
pi@raspberrypi:/media/pi/x $ sudo imgclone -d xxx.img
---- Raspberry Pi clone to image V1.2 ---
-----------------------------------------------
---- DO NOT CHANGE FILES ON YOUR SD CARD ---
---- WHILE THE BACKUP PROGRAM IS RUNNING ---
---- THE DESTINATION .IMG FILE MUST BE ---
---- ON AN EXTERNAL STORAGE / NETWORK SHARE ---
-----------------------------------------------
Cloning /dev/mmcblk0 to xxx.img
uuid | cut -f1 -d-
mktemp -d
mktemp -d
-----------------------------------------------
---- READING PARTITIONS ------
-----------------------------------------------
Partition 1 start: 8192 end: 532479 ptype:primary ftype:fat32 flags: lba
.Partition 2 start: 532480 end: 15415295 ptype:primary ftype:ext4 flags:
.partprobe
Last partition starts at 272629760 bytes.
mount /dev/mmcblk0p2 /tmp/tmp.3RgFzhVKOG
df /tmp/tmp.3RgFzhVKOG | tail -n 1 | tr -s " " " " | cut -d ' ' -f 2
df /tmp/tmp.3RgFzhVKOG | tail -n 1 | tr -s " " " " | cut -d ' ' -f 4
Used size of last partition is 6534172672 bytes.
umount /tmp/tmp.3RgFzhVKOG
Required size for destination image: 6953424384 bytes
-----------------------------------------------
---- ALLOCATING SPACE FOR .IMG FILE ------
-----------------------------------------------
touch "xxx.img"
df "xxx.img" | tail -n 1 | tr -s " " " " | cut -d ' ' -f 1
/dev/sda1
df --output=avail -B 1 "xxx.img" | tail -n 1
15589818368
truncate --size 6953424384 "xxx.img"
truncate: failed to truncate 'xxx.img' at 6953424384 bytes: File too large
Could not create file large enough on destination disk.
check usb driver capacity. it's big enough.
pi@raspberrypi:/media/pi/x $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.0G 5.8G 858M 88% /
devtmpfs 431M 0 431M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 13M 452M 3% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 87M 166M 35% /boot
tmpfs 93M 0 93M 0% /run/user/1000
/dev/sda1 15G 68M 15G 1% /media/pi/x

RonR
Posts: 1699
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: save RPi Micro SD to a image

Thu Aug 13, 2020 5:59 pm

Lxw2015 wrote:
Wed Aug 12, 2020 2:52 pm
I flashed a SD card with OS, update, upgrade, and install some packages. now I want save SD card. so next time, I don't need install package again. I use SD clone generate a image file. the image is the size of my SD card, 32G. I check the SD card files, it only ~80M. How could I just generate the SD card image to reflect files on the SD card, rather than entire SD card.

image-backup

emma1997
Posts: 1088
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: save RPi Micro SD to a image

Thu Aug 13, 2020 6:06 pm

I second that. Image-Backup revolutionized my systems. What used to take hours now takes seconds or, worst case, couple minutes. I don't care if SD corrupts or crashes anymore. lol

User avatar
TommyG007
Posts: 64
Joined: Fri Jun 26, 2020 4:30 pm
Location: South Wales, UK

Re: save RPi Micro SD to a image

Fri Aug 14, 2020 2:14 pm

Lxw2015 wrote:
Thu Aug 13, 2020 5:08 pm
I tried imgclone. failed. see below.
pi@raspberrypi:/media/pi/x $ sudo imgclone -d xxx.img
---- Raspberry Pi clone to image V1.2 ---
-----------------------------------------------
---- DO NOT CHANGE FILES ON YOUR SD CARD ---
---- WHILE THE BACKUP PROGRAM IS RUNNING ---
---- THE DESTINATION .IMG FILE MUST BE ---
---- ON AN EXTERNAL STORAGE / NETWORK SHARE ---
-----------------------------------------------
Cloning /dev/mmcblk0 to xxx.img
uuid | cut -f1 -d-
mktemp -d
mktemp -d
-----------------------------------------------
---- READING PARTITIONS ------
-----------------------------------------------
Partition 1 start: 8192 end: 532479 ptype:primary ftype:fat32 flags: lba
.Partition 2 start: 532480 end: 15415295 ptype:primary ftype:ext4 flags:
.partprobe
Last partition starts at 272629760 bytes.
mount /dev/mmcblk0p2 /tmp/tmp.3RgFzhVKOG
df /tmp/tmp.3RgFzhVKOG | tail -n 1 | tr -s " " " " | cut -d ' ' -f 2
df /tmp/tmp.3RgFzhVKOG | tail -n 1 | tr -s " " " " | cut -d ' ' -f 4
Used size of last partition is 6534172672 bytes.
umount /tmp/tmp.3RgFzhVKOG
Required size for destination image: 6953424384 bytes
-----------------------------------------------
---- ALLOCATING SPACE FOR .IMG FILE ------
-----------------------------------------------
touch "xxx.img"
df "xxx.img" | tail -n 1 | tr -s " " " " | cut -d ' ' -f 1
/dev/sda1
df --output=avail -B 1 "xxx.img" | tail -n 1
15589818368
truncate --size 6953424384 "xxx.img"
truncate: failed to truncate 'xxx.img' at 6953424384 bytes: File too large
Could not create file large enough on destination disk.
check usb driver capacity. it's big enough.
pi@raspberrypi:/media/pi/x $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.0G 5.8G 858M 88% /
devtmpfs 431M 0 431M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 13M 452M 3% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 87M 166M 35% /boot
tmpfs 93M 0 93M 0% /run/user/1000
/dev/sda1 15G 68M 15G 1% /media/pi/x

What format is your USB drive in?
If it's FAT32, you can't create files with more than 4GB size on FAT32 filesystems.

geekinchief
Posts: 5
Joined: Thu Sep 06, 2018 3:01 pm

Re: save RPi Micro SD to a image

Fri Aug 14, 2020 8:23 pm

I just published a step-by-step on how to do this:

https://www.tomshardware.com/how-to/bac ... disk-image

Lxw2015
Posts: 84
Joined: Fri Feb 12, 2016 4:05 am

Re: save RPi Micro SD to a image

Fri Aug 14, 2020 8:29 pm

yeah, I just figured that out. I need format USB to NTFS format. it take loooong time to generate image. and the generated image is bigger than I expected.

for example

pi@phoenix-pi-noc:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 29G 5.4G 23G 20% /
/dev/mmcblk0p1 253M 55M 198M 22% /boot

I was hoping the generated image is 5.5G, but it generated 6.0G image.

Lxw2015
Posts: 84
Joined: Fri Feb 12, 2016 4:05 am

Re: save RPi Micro SD to a image

Fri Aug 14, 2020 8:32 pm

geekinchief wrote:
Fri Aug 14, 2020 8:23 pm
I just published a step-by-step on how to do this:

https://www.tomshardware.com/how-to/bac ... disk-image
I'll try it. thanks

User avatar
TommyG007
Posts: 64
Joined: Fri Jun 26, 2020 4:30 pm
Location: South Wales, UK

Re: save RPi Micro SD to a image

Fri Aug 14, 2020 9:18 pm

Lxw2015 wrote:
Fri Aug 14, 2020 8:29 pm
yeah, I just figured that out. I need format USB to NTFS format. it take loooong time to generate image. and the generated image is bigger than I expected.

for example

pi@phoenix-pi-noc:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 29G 5.4G 23G 20% /
/dev/mmcblk0p1 253M 55M 198M 22% /boot

I was hoping the generated image is 5.5G, but it generated 6.0G image.

You'll get much faster speeds if you format the USB drive to ext4.

For example, when I create a backup to my NAS SSD drive formatted in ext4, it takes about 4 minutes to create the 8GB image file.

User avatar
TommyG007
Posts: 64
Joined: Fri Jun 26, 2020 4:30 pm
Location: South Wales, UK

Re: save RPi Micro SD to a image

Fri Aug 14, 2020 9:39 pm

geekinchief wrote:
Fri Aug 14, 2020 8:23 pm
I just published a step-by-step on how to do this:

https://www.tomshardware.com/how-to/bac ... disk-image

Yours is a guide on using PiShrink (great guide btw).

We're talking about using the modified version of PiClone which a user has created over on this thread: viewtopic.php?f=63&t=281190&p=1703077#p1703077

https://github.com/tom-2015/imgclone

Return to “General discussion”