LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Create Smaller USB Flash Drive Image? (https://www.linuxquestions.org/questions/linux-software-2/create-smaller-usb-flash-drive-image-587093/)

Githlar 09-24-2007 06:30 PM

Create Smaller USB Flash Drive Image?
 
OK, I have a bootable 2GB USB flash drive. It has one partition that is around 100M and the rest is free space.

I wanted to create an image of the flash drive to use with memdisk. So, I used dd. However, dd copies the entire flash drive, even the free space.

What I want to do is extract the MBR/bootrecord and the first partition into a disk image. Or, in simpler terms - extract everything but the free space. Since the image file is the same size of my USB flash drive, I can't fit it on my flash drive, so I need to cut off all that unneeded free space.

Any suggestions?

I tried using Qemu-img to create a raw image of the size I need and then formatting it right in FreeDOS from Qemu and copying over the files, but the image doesn't seem to want to boot (at least in Qemu).

osor 09-25-2007 11:41 AM

You didn’t tell use the dd command you used. You can specify the size to the dd command by using the count and bs flags. E.g.,
Code:

dd if=/dev/sdb of=/path/to/destination/image.img bs=1048576 count=100
Of course you may need to modify the command to adapt to your particular situation.

David the H. 09-25-2007 11:42 AM

dd can certainly copy sections of a disk. You only have to use the 'count=BLOCKS' option to specify the number of blocks you want to transfer. You can use this to copy only the boot record, or only the first 100MB, for example.

The only question is determining how many blocks to copy. Unfortunately, I don't know the answer to that offhand.

You can also copy a partition instead of a drive simply by using the partition device as the input instead of the drive device. 'if=/dev/sda1' instead of 'if=/dev/sda', for example.

There's an excellent thread about all the neat things you can do with dd here:
http://www.linuxquestions.org/questi...d.php?t=362506

jiml8 09-25-2007 12:07 PM

Why are you copying the entire drive when all you want is one partition? As stated in the previous post, specify if=/dev/sda1 to get a partition.


All times are GMT -5. The time now is 01:52 PM.