Clone SD Card without unallocated space

I am using Raspberry Pi to clone another raspbian operating system card:
The things i do is:

Check if usb flash drive is mounted:
sudo fdisk -l
This will report the Raspberry Pi system disk /dev/mmcblk0 and flash drive /dev/sda:
Disk /dev/mmcblk0: 64.4 GB, 64423460864 bytes
4 heads, 16 sectors/track, 1966048 cylinders, total 125827072 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: 0x000981cb

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880   125827071    62852096   83  Linux

Disk /dev/sda: 8026 MB, 8026849280 bytes
247 heads, 62 sectors/track, 1023 cylinders, total 15677440 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: 0xb3c5e39a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192      131071       61440    c  W95 FAT32 (LBA)
/dev/sda2          131072     3276799     1572864   83  Linux
So we need to know 3 thigs:
SD card destination which is /dev/sda
The Units size which is 512
The end sector of second partition which is 3276799

Now we create magical command:
sudo dd if=/dev/sda of=/home/pi/backup.img bs=512 count=3276799
And 10 minutes later output will be something like this:
3276799+0 records in
3276799+0 records out
1677721088 bytes (1.7 GB) copied, 569.322 s, 2.9 MB/s
And this is how we backup Raspbian operating system like a Pro :)

No comments: