How to write a disk image on Linux

You may sometimes need to write a disk image to a USB thumbdrive or a SD card. This is typically done to create a system that you can use to boot a device. The image file typically has the .img file extension, though its not necessary and does not matter. Writing the disk image can be easily done on Ubuntu or any other Linux distribution.

  • Insert the USB thumbdrive or SD or microSD card to your computer. It should be detected and Ubuntu might mount it automatically. If it does not, that is okay as long as it is detected.

  • We need to find out what is the device file which represents the inserted USB thumbdrive or SD card as described here.

  • Before we write the disk image, we need to unmount the device. This can be done by passing the device name to the umount command:

$ umount /dev/sdb
  • To write the disk image we can use the dd command. Provide the disk image file as the input file and the device file as the output file with a suitable block size:
$ sudo dd if=/blah/foo.img of=/dev/sdb bs=1M
  • Finally, we flush the disk buffers to ensure that the writing is finished:
$ sync

That is it! The disk image is written and you can take out your USB thumbdrive or SD card to use it.

Related: How to write a disk image on Windows using Win32 Disk Imager

Tried with: Ubuntu 12.04

How to find read and write speed of any storage device in Ubuntu

You do not need to rely on the read and write speeds provided by a hard disk, USB flash drive or SD card manufacturer. It is quite easy to figure out by yourself the sustained read or write speed of any storage device in Ubuntu.

Make sure your storage device is plugged in, has a filesystem and is mounted under Ubuntu. Assume it is mounted at /media/my-usb-disk/ To find the write and read speeds, we write and read a 100MB file to and from a directory of this storage device using the dd command.

$ dd if=/dev/zero of=/media/my-usb-disk/speed-test-file bs=100K count=1k
$ dd if=/media/my-usb-disk/speed-test-file of=/dev/null bs=100K count=1k
$ rm /media/my-usb-disk/speed-test-file

Replace the location of the speed test file with any directory inside the storage medium you are testing. Also, remember to delete the speed test file once you are done.

Tried with: Ubuntu 12.04 LTS