[Ilugc] doubt in dd

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Wed Oct 11 19:50:37 2006

On Wed, Oct 11, 2006 at 01:57:41PM +0100, pnv kannan wrote:

Hi,
   
  can dd command be used to check the contents of a file?
  please clarify
   
  thanks
  kannan v
dd stands for "disk dump" just like grep stands for "graphic regular expression 
print" and ping stands for "packet internet groper"...


It is mostly used for copying from device files though it is sometimes used to 
copy back to them as well. It gives you raw access. For instance, this is 
really cool.

dd if=/dev/cdrom of=cd.iso 

This will get you the cd ISO. In my linux box, cdrom device is /dev/hdc

Note that since it is raw access there is no need to mount. 

It also takes offsets using skip and seek. And you customize how much you want 
to read or write with count= and bs= parameters.

I use dd for backing up or restoring my MBR since it is guaranteed to be 512 
bytes.

dd if=/dev/hda of=mbr bs=512 count=1

Another thing I do is create memory filesystems known in linux as loopback 
device files.

/dev/zero is a special file like /dev/null which gives an inexhaustible string 
of zeroes.

So you can create a file of arbitrary size quickly with

#dd if=/dev/zero of=1mfile count=1024 bs=1024\*1024

And later you can mount it using the loopback mechanism and then create a 
filesystem on it.,

I have already mailed this before, check the archives.

If you want to create a CD/USB/DVD image file you can use dd.

For instance, my USB flash stick has only 256 MB space. So I do a

# dd if=/dev/zero of=usb-flash bs=1024 count=256\*1024\*1024

Then I 
#losetup -f usb-flash
#mkfs.vfat /dev/loop/0(this cud be different in your case)

After that, I can mount the loopback device just like a USB flash disk. Copy 
all the files, run grub or syslinux on it and then.

You plug in the USB flash drive and do this.

#dd if=usb-flash of=/dev/sda

You are done. :-)

Or still better send this file to someone else and ask him to make the flash 
stick for you.

regards,
Girish

Other related posts: