[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Copy 2 partitions to .img file



Hélder Pinheiro wrote:
> I have a memory card with 16GB of size, but only 4GB are partitioned
> through 2 partitions (sdb1 and 2).

I understand that:

  sdb1 is 2G
  sdb2 is 2G
  Total of 4G

> I want to copy the content of both partitions into a .img file, in order to
> be able to flash it on another 4GB memory card..

Okay.  Then copy each of the partitions off.  Then copy each of the
partitions onto the new device.  Right?

> I tried with dd command, but I am only able to copy one partition each time
> or the entire 16 GB.

Right.  But isn't that what you want?

> Could you help me copying only the two partitions?

  dd if=/dev/sdb1 of=sdb1.img
  dd if=/dev/sdb2 of=sdb2.img

Then partition the new device with two 2G partitions, the same size as
the previous partitions.  If you need help doing this ask.  I would
use 'sfdisk -d' to dump the previous and 'sfdisk' again to write the
new partitions.  This is the only tricky part of things.  Then copy
the saved data off to the new partitions.

  dd if=sdb1.img of=/dev/sdb1
  dd if=sdb2.img of=/dev/sdb2

If the above just isn't going to work for you then if the file size is
only 4G in total then you could simply copy the data off the
filesystem and then copy the data back onto the new device.

  mount /dev/sdb1 /mnt
  rsync -a /mnt/ ./backupdir/sdb1/
  umount /mnt
  mount /dev/sdb2 /mnt
  rsync -a /mnt/ ./backupdir/sdb2/
  umount /mnt

Then mount the new device:

  mount /dev/sdb1 /mnt
  rsync -a ./backupdir/sdb1/ /mnt/
  umount /mnt
  mount /dev/sdb2 /mnt
  rsync -a ./backupdir/sdb2/ /mnt/

Note the trailing '/' characters on the rsync command args are
intentional and important.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: