Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
Hello fellow Linux peoples... I am working with a Dreamplug (plug computer) that runs Debian Wheezy and have found that they use dd to copy built images to a USB ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie jkwilborn's Avatar
    Join Date
    Nov 2012
    Posts
    214

    How 'dd' can copy to device and not partition?


    Hello fellow Linux peoples...

    I am working with a Dreamplug (plug computer) that runs Debian Wheezy and have found that they use dd to copy built images to a USB stick. I, being a hardware person down deep have always been able to understand the software operation with respect to the hardware that I know.

    I have a hard time with a copy where you have created a partitioned USB drive with a fat16 and an ext2 partition and then copy to it specifying the whole device, such as:

    Code:
    dd if=/home/development/image of=/dev/sdg bs=1M
    If you df, you see the device as /dev/sdg1 and /dev/sdg2. Sorry but I can't understand how this can occur, yet the device seems to maintain the format and partitions??? How does it write or who controls why it doesn't cream the partitions? The image shows up in the ext2 partition, I believe whatever difference it makes...

    I know that I am writing to the whole device and not a specific partition, but how does the software know where to put this as not to interfere with the pre-partitioned areas? Is this something the USB stick handles internally? We do the same with an SD card, that is writing to the whole device and not tot a partition.

    Any help would be appreciated...

    Thanks...

    Jack

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,517
    Actually, you can use dd to copy a file system image to an appropriately sized partition. Example:
    Code:
    dd if=imagefile of=/dev/sdg1 bs=1M
    I use dd to create bit-image copies of both devices, as well as file systems (partitions) for forensic purposes. I can then loop mount the file system (partition) image and access and analyze the data there without touching the device itself. If it is for cleaning viruses for a client, then once it is clean I can write it back to the partition on the disc/device, again using dd as shown above.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Linux Newbie jkwilborn's Avatar
    Join Date
    Nov 2012
    Posts
    214
    Yes, but it still doesn't answer the question of how and why it works like it does.

    Jack

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,517
    Quote Originally Posted by jkwilborn View Post
    Hello fellow Linux peoples...

    I am working with a Dreamplug (plug computer) that runs Debian Wheezy and have found that they use dd to copy built images to a USB stick. I, being a hardware person down deep have always been able to understand the software operation with respect to the hardware that I know.

    I have a hard time with a copy where you have created a partitioned USB drive with a fat16 and an ext2 partition and then copy to it specifying the whole device, such as:

    Code:
    dd if=/home/development/image of=/dev/sdg bs=1M
    If you df, you see the device as /dev/sdg1 and /dev/sdg2. Sorry but I can't understand how this can occur, yet the device seems to maintain the format and partitions??? How does it write or who controls why it doesn't cream the partitions? The image shows up in the ext2 partition, I believe whatever difference it makes...

    I know that I am writing to the whole device and not a specific partition, but how does the software know where to put this as not to interfere with the pre-partitioned areas? Is this something the USB stick handles internally? We do the same with an SD card, that is writing to the whole device and not tot a partition.

    Any help would be appreciated...

    Thanks...

    Jack
    To continue from my previous post:

    The first sector on the disc is the MBR (master boot record) which contains the partition table along with other information. When you use dd to backup an entire disc, the partition table / MBR is copied, so when you write it back, that data remains intact. That said, if you manipulate the image file you must be careful to leave the partitions where they logically reside. You could change their sizes, as well as locations, but that is very advanced stuff. Having written boot loaders in the past, and (once upon a time) knew the formation of the partition table like the back of my hand, I was able to do many wonky things with them! Only one more thing to say - caveat programmer! Dragons be here!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,517
    Quote Originally Posted by jkwilborn View Post
    Yes, but it still doesn't answer the question of how and why it works like it does.

    Jack
    Consider the following, remembering that dd is a bit-exact copy tool:
    Code:
    # Copy device image to file
    dd if=/dev/sdg of=somefile.img bs=1M
    
    # Now, get another device of the same size as the original
    dd if=somefile.img of=/dev/sdh bs=1M
    
    # Voila! We have now cloned the drive! Of course we could have done that directly, as here:
    dd if=/dev/sdg of=/dev/sdh bs=1M
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Linux User IsaacKuo's Avatar
    Join Date
    Feb 2005
    Location
    Baton Rouge, LA, USA
    Posts
    405
    When you write to the whole device, the partition table definitely gets creamed. It will get overwritten with whatever the partition table of the image was.

    However, that doesn't mean the computer has any idea that the partition table has been updated. Unless it knows to rescan the partition table, it will happily continue to use the old one and will probably still find the other partition where it expects it (unless the image file is big enough to hit it).
    Isaac Kuo, ICQ 29055726 or Yahoo mechdan

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,517
    You can force the system to rescan the partition table for a device: use the partprobe command.
    Code:
    PARTPROBE(8)                   GNU Parted Manual                  PARTPROBE(8)
    
    NAME
           partprobe - inform the OS of partition table changes
    
    SYNOPSIS
           partprobe [-d] [-s] [devices...]
    
    DESCRIPTION
           This manual page documents briefly the partprobe command.
    
           partprobe  is a program that informs the operating system kernel of partition table changes, by requesting that the oper-
           ating system re-read the partition table.
    
    OPTIONS
           This program uses short UNIX style options.
    
           -d     Donít update the kernel.
    
           -s     Show a summary of devices and their partitions.
    
           -h     Show summary of options.
    
           -v     Show version of program.
    
    SEE ALSO
           parted(8).
    
    AUTHOR
           This manual page was written by Timshel Knoll <timshel@debian.org>, for the Debian GNU/Linux system (but may be  used  by
           others).
    
    parted                          March 18, 2002                    PARTPROBE(8)
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #8
    Linux Newbie jkwilborn's Avatar
    Join Date
    Nov 2012
    Posts
    214
    So I was right, they had to make sure that the image had an internal format usable as the original drive was set up. That makes sense, I'm glad I finally asked the right people... I will have to look over what I'm doing when I build an image to make sure that is what it's doing. Seems to me that I don't need to format the drive in any certain way if I'm going to write over what I created, is this correct? I think they have to mount it to write, but any format would due.

    I'll have to hose around with it and see... I will leave this for another day then close it, thanks for all your help...

    Jack

  9. #9
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,517
    Actually, you don't want to mount the drive to over-write it with the image. Just use the device id, such as /dev/sdN (for a full disc image) or /dev/sdNX (for a particular partition image).
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  10. #10
    Linux Newbie jkwilborn's Avatar
    Join Date
    Nov 2012
    Posts
    214
    Does this mean that I can dd an .iso image to a, like USB stick without dealing with some other piece of software in between? Like if I have a Linux distro that is an install .iso, can I just dd it over to a USB memory stick and let it do what's needed to make an installable image on the USB stick? This would be wonderful...

    Thanks people (I don't like to say 'guys' anymore as I've run across some pretty wise women in computers...)

    Jack

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •