atux_null
Posts: 135
Joined: Thu Jun 21, 2012 1:58 pm

transfer image to another card

Wed Jun 24, 2015 6:56 am

hello everyone.
i do have rpi2 with a 32GB card, the system uses only 2.4GB. the rest is free space. i got it working with my settings for all for my programs (asterisk, cctv,...). i would like to keep a backup of the card so i could move it any time to a new card. if i use dd it will create a 32GB image and it will be usable only to cards from that size (32GB) and more. i would like to keep an image even for smaller cards such as 4GB.
is there any way i could do that?

betruk
Posts: 36
Joined: Fri Apr 24, 2015 8:17 am

Re: transfer image to another card

Wed Jun 24, 2015 7:57 am

You can downsize the image size before transferring with a video editor like Pavtube.

ghans
Posts: 7883
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: transfer image to another card

Wed Jun 24, 2015 8:29 am

The OP is talking about disk images , not pictures.

@atux_null
You need Linux tools for this or at least a Linux Live CD. Use gparted to shrink the partitions and image them seperately. Alternatively
mount the image, shrink the partitions inside it and then unmount it. Now you can truncate the image.


ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

atux_null
Posts: 135
Joined: Thu Jun 21, 2012 1:58 pm

Re: transfer image to another card

Wed Jun 24, 2015 11:04 am

thanks a lot for the quick replies.
@ghans
i have another raspberry that i already have gparted installed.
i would like some help since i am confused now.
the 32GB card has a fat32 partition of ~150MB, a partition of 2.4GB ext4 and empty space the rest of the card. what do i need to resize?
when i plug that sd card to the usb adapter it has been seen as /dev/sdc and i want to save it to /home/pi
if i do
dd /dev/sdc of=/home/pi/32gb_sd.img bs=512k it creates a 32gb img file.

what can i do?

User avatar
rpdom
Posts: 17569
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: transfer image to another card

Wed Jun 24, 2015 11:16 am

You could limit the size of the dd to just copy the allocated part of the card.

Use fdisk -l /dev/sdc to get the information about the partition sizes. The number you need is the highest one in the "End" column.
Add one to that number to get the number of used sectors.
Check the sector size. It is normally 512 bytes, but may be different on large cards.

Then

Code: Select all

dd if=/dev/sdc of=/home/pi/32gb_sd.img count=USED
replacing USED with the number of used sectors that you just worked out.

You should end up with a file of just over 2.4GB

atux_null
Posts: 135
Joined: Thu Jun 21, 2012 1:58 pm

Re: transfer image to another card

Thu Jun 25, 2015 1:46 pm

i am on the system that i want to backup.
root@rasp:~# fdisk -l

Disk /dev/mmcblk0: 16.2 GB, 16172187648 bytes
4 heads, 16 sectors/track, 493536 cylinders, total 31586304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00092fac

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 2048 114687 56320 c W95 FAT32 (LBA)
/dev/mmcblk0p2 114688 31586303 15735808 83 Linux
root@rasp:~#


so what do i have to use as used?

User avatar
RaTTuS
Posts: 10574
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: transfer image to another card

Thu Jun 25, 2015 2:26 pm

you can just make the filesystems [fat32 and ext[234]]
on the new card then
copy the files over
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: transfer image to another card

Thu Jun 25, 2015 2:29 pm

RaTTuS wrote:you can just make the filesystems [fat32 and ext[234]]
on the new card then
copy the files over
Bingo! Give that man a cigar!

I was wondering how long it would take for someone to get around to the right , simple, and easy answer.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

atux_null
Posts: 135
Joined: Thu Jun 21, 2012 1:58 pm

Re: transfer image to another card

Sat Jun 27, 2015 3:07 pm

sorry but thus does not get my job done. i do need to create an image (.img) which is a backup of my working system. the actual size, not the whole sd with the empty space.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: transfer image to another card

Sat Jun 27, 2015 3:28 pm

atux_null wrote:sorry but thus does not get my job done. i do need to create an image (.img) which is a backup of my working system. the actual size, not the whole sd with the empty space.
Whatever that means...
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

atux_null
Posts: 135
Joined: Thu Jun 21, 2012 1:58 pm

Sat Jun 27, 2015 3:33 pm

i have a working 16GB card. most of it is empty space. the actual space occupied by the OS is ~ 4GB.
if i try to take a backup with dd to create an img it will create a 16GB img file. i do need to have a small file of backup so i can install it to smaller card in case of failure of the 16GB card.
i am using dd as a tool to create it. the df -h has
root@raspberrypi:[~]: df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 15G 983M 14G 7% /
/dev/root 15G 983M 14G 7% /
devtmpfs 182M 0 182M 0% /dev
tmpfs 38M 220K 37M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 75M 0 75M 0% /run/shm
/dev/mmcblk0p1 56M 19M 37M 34% /boot
root@raspberrypi:[~]:

jpezz
Posts: 98
Joined: Fri Apr 26, 2013 6:14 pm
Location: North Carolina, U.S.

Re: transfer image to another card

Sat Jun 27, 2015 6:07 pm

atux_null wrote:thanks a lot for the quick replies.
@ghans
i have another raspberry that i already have gparted installed.
i would like some help since i am confused now.
the 32GB card has a fat32 partition of ~150MB, a partition of 2.4GB ext4 and empty space the rest of the card. what do i need to resize?
when i plug that sd card to the usb adapter it has been seen as /dev/sdc and i want to save it to /home/pi
if i do
dd /dev/sdc of=/home/pi/32gb_sd.img bs=512k it creates a 32gb img file.

what can i do?
Use the "count=BLOCKS" option of dd
dd /dev/sdc of=/home/pi/32gb_sd.img bs=4M count=650 # will copy 2.6GB

User avatar
rpdom
Posts: 17569
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: transfer image to another card

Sat Jun 27, 2015 6:56 pm

atux_null wrote:i am using dd as a tool to create it. the df -h has
root@raspberrypi:[~]: df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 15G 983M 14G 7% /
That is showing a 15GB ext4 filesystem, not a 2.4GB one!You are using the full 16GB card.

There are various ways of making images of that card. You'll find how to do them with a quick search.

Basically you could
a) Use the Pi or a Linux box to partition a new card and copy the contents of the file systems over with rsync. That is probably the fastest.
b) Use the Pi or a Linux box to do as a) but create a minimal image file instead.
c) Create a full sized image of the card, then use one of the image-shrinking scripts to reduce its size. Again, a Linux system is best to do this on.

Return to “Beginners”