Project

General

Profile

Support #492

Updated by Daniel Curtis over 9 years ago

While modifying the stock image of Raspbian, I decided to take a backup image of my drive using dd: 
 dd if=/dev/sdb of=modified-raspbian.img 

 Then shrunk main partition image to the value I desired using gparted: 
 gparted modified-raspbian.img 

 However the image of the entire drive left a lot of unallocated space left in the image. After searching online I found that all I needed to do was to use dd to extract just the raspbian image apart from the unallocated space. The parameter for dd that does this is count=. 

 * Get the needed block information by running the following: 
 <pre> 
 fdisk -u -l modified-raspbian.img 
 </pre> 
 #* Example output: 
 <pre> 
 Disk /dev/sdb: 8462 MB, 8462008320 bytes 
 255 heads, 63 sectors/track, 1028 cylinders 
 Units = cylinders of 16065 * 512 = 8225280 bytes 
 Sector size (logical/physical): 512 bytes / 512 bytes 
 I/O size (minimum/optimal): 512 bytes / 512 bytes 
 Disk identifier: 0x5c0894d9 

 Device Boot        Start           End        Blocks     Id    System 
 /dev/sdb1     *             1             9         72261      e    W95 FAT16 (LBA) 
 /dev/sdb2                10           103        755055     83    Linux 
 </pre> 

 * In the following example the last partition ends on 103, and the unit size is 8225280 bytes. So simply run command: 
 <pre> 
 dd if=modified-raspbian.img if=modified-raspbian of=modified-raspbian-stripped.img bs=8225280 count=103 
 </pre> 
 #* *NOTE*: I had problems with a couple of images being corrupt after this process, so I found that adding 1 to the count argument will correct this.  
 <pre> 
 dd if=modified-raspbian.img if=modified-raspbian of=modified-raspbian-stripped.img bs=8225280 count=104 
 </pre> 

 h2. Resources 

 * http://serverfault.com/questions/446529/create-image-of-a-usb-drive-without-unallocated-partition

Back