Useful Linux Commands: Part III

30 Sep

Linux Tools


This post continues from Useful Linux Commands: Part I , Useful Linux Commands: Part I and list the commands which I found special in embedded Linux environment.

While working on Pandaboard related project, which boots using a SD card, I needed to backup the SD card before I experimented with boot sequences, display resolution, etc. I knew direct cpying the two partitions (FAT32 and linux partition) to backup may not be a 100% backup.

I found a really very neat way to backup using ‘dd‘ tool. There may be other better options to backup in Linux environment, however I found ‘dd’ very convenient and reliable. explains dd as:

The dd command is one of the original Unix utilities and should be in everyone’s tool box. It can strip headers, extract parts of binary files and write into the middle of floppy disks; it is used by the Linux kernel Makefiles to make boot images. It can be used to copy and convert magnetic tape formats, convert between ASCII and EBCDIC, swap bytes, and force to upper and lowercase.

For blocked I/O, the dd command has no competition in the standard tool set. One could write a custom utility to do specific I/O or formatting but, as dd is already available almost everywhere, it makes sense to use it.

Like most well-behaved commands, dd reads from its standard input and writes to its standard output, unless a command line specification has been given. This allows dd to be used in pipes, and remotely with the rsh remote shell command.

Before taking backup I need to understand where my dd input coming from and where it should output the backup.

Since, in my case it was a SD card backup, I could either use a SD Card Reader or laptop’s SD/MMC card reader to read my card and proceed. The only difference in both is the listing of device under /dev/ and subsequent use of that listing during backup process. I used my laptop’s SD/MMC card reader.

First I need to understand how my laptop has listed the SD card under /dev/. To know that I ran fdisk :

sudo fdisk -l

It lists all the disks (hard disk, SD card) details. After listing hard disk details it listed SD card details as:

Disk /dev/mmcblk1: 15.9 GB, 15931539456 bytes
255 heads, 63 sectors/track, 1936 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: 0x00000000

Device Boot Start End Blocks Id System
/dev/mmcblk1p1 * 1 9 72261 c W95 FAT32 (LBA)
/dev/mmcblk1p2 10 1936 15478627+ 83 Linux

Now its time to backup the data from Linux partition! Here, I used the ‘dd’ command as below. ‘

sudo dd if=/dev/mmcblk1p2 | gzip -c > Linux_image.img
[sudo] password for $user:
30957255+0 records in
30957255+0 records out
15850114560 bytes (16 GB) copied, 1646.46 s, 9.6 MB/s

  1. ‘if’ indicates the input file
  2. Pipe (‘|’) was used to direct the output to gzip for compressing
  3. ‘>’ was used to direct the compressed backup to a aptly named file

Similarly, backup the FAT32 partition, using:

sudo dd if=/dev/mmcblk1p1 | gzip -c > FAT32_image.img
144522+0 records in
144522+0 records out
73995264 bytes (74 MB) copied, 7.39546 s, 10.0 MB/s


  • dd on Wikipedia
  • : Details some of the cautionary notes while using ‘dd’ the ‘data destructor’ 🙂

  • dd on
  • : Gives details of the various command line options

  • dd on
  • This lists the user experiences with dd and explains practical aspects related to backup, cloning, etc.

Leave a comment

Posted by on September 30, 2011 in Linux, Programming, Technical


Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: