Clone area between MBR & 1st partition using dd


Results 1 to 7 of 7

Thread: Clone area between MBR & 1st partition using dd

  1. #1
    Join Date
    Sep 2009
    Location
    Toronto
    Posts
    24

    Question Clone area between MBR & 1st partition using dd

    Hi
    I would like to clone (backup) the data (not really data per se) that resides in the area after the mbr and before the first partition. How can I do that using dd? I know I'd probably go about something like this:
    dd if=/dev/sda of=backup-of-data-between-mbr-and-1st-part.bin bs=512 skip=1 count=?

    I've seen 1st partition starting at different places on different disks. Also, what exactly is stored in this area? If it's just a Win 7 installation on sda, what is stored there? How can I check if anything is stored there at all. And if it's a multiboot setup with grub2, what resides there?
    Perhaps Saikee, the master, can shed some light on this
    Thanks guys.

  2. #2
    Join Date
    Jul 2003
    Location
    Spokane, Washington
    Posts
    580
    All the maps I've seen simply say, "Thar be dragons there."

  3. #3
    Join Date
    Sep 2009
    Location
    Toronto
    Posts
    24
    then how do i dd dragons outta there?
    lol, all jokes aside, seriously, how ?

  4. #4
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,984
    The MBR is only the first sector or 512 bytes of the hard disk as that is all the Bios would read.

    It appears the whole track or the first head, equal to the number of sectors per head times sector size, is reserved for the MBR usage. I suppose in the old day when each hard disk can have its own geometry, like the USB flash drive today, it would make sense to leave out the first head completely when starting the first partition, as Manufacturer A might opt for 16 sectors per head while another manufacturer B chose 32 sectors per head. It only got standardised to 255 heads and 63 sectors when the hard disk capacity exceeded the limit addressed by Cylinder/Head/Sector method.

    Nowadays a hard disk commonly uses the LBA addressing system with each cylinder standardised to 255 heads, each head has 63 sectors and each sector has 512 bytes one could have expected if the first head is omitted the first partition will start at the 63+1 = 64th sector. However the partitioning programs always report the starting position is 63th sector. I suspect this is the terminology and the starting position should be interpreted what needs to be "skipped". In fdisk I can change the unit to display in Sector by parameter "u" as follow
    Code:
    root@saikee-desktop:/home/saikee# fdisk /dev/sdc
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): u
    Changing display/entry units to sectors
    
    Command (m for help): p
    
    Disk /dev/sdc: 1000.2 GB, 1000203804160 bytes
    255 heads, 63 sectors/track, 121601 cylinders, total 1953523055 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0xc100c100
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdc1              63  1953520064   976760001    7  HPFS/NTFS
    
    Command (m for help):
    Similarly the same information in Program "parted" shows the first partition starts at 63th sector by command "u" followed by the unit "s" for sector. However in Program "parted" one can also show unit in byte by parameter "B"
    Code:
    root@saikee-desktop:/home/saikee# parted /dev/sdc
    GNU Parted 2.2
    Using /dev/sdc
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) u s                                                              
    (parted) p                                                                
    Model: SAMSUNG HD103UJ (scsi)
    Disk /dev/sdc: 1953523055s
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start  End          Size         Type     File system  Flags
     1      63s    1953520064s  1953520002s  primary  ntfs
    
    (parted) u B                                                              
    (parted) p                                                                
    Model: SAMSUNG HD103UJ (scsi)
    Disk /dev/sdc: 1000203804160B
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    
    Number  Start   End             Size            Type     File system  Flags
     1      32256B  1000202273279B  1000202241024B  primary  ntfs
    
    (parted)
    The above is the evidence clearly showing a full track or the first head of 63x512 = 32256 bytes has been reserved for the MBR usage and the 1st partition starts after the 32256th byte.


    The standard block size used in dd is in sector or 512 bytes.

    Therefore the space between the MBR and the first partition should be 2nd to 63th sector.

    Just use the skip parameter in dd to locate any sector you want from the above, like
    Code:
    dd if=/dev/sdc any2 bs=512 count=1 skip=2
    cat any2
    Just a word of warning

    I am not aware of how the space is supposed to be used as that is not part of the hard disk any operating system has declared a usage of it. However some installers and programs, in both Linux and MS Windows systems, that need to reboot the system several times could possibly alter the MBR temporary and leave some codes in the first track to maintain continuation between reboots. The information may not be cleaned up and left there as junk.

    Therefore if you find a dragon there it is just its carcass.
    Last edited by saikee; 09-17-2011 at 06:53 AM.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  5. #5
    Join Date
    Sep 2009
    Location
    Toronto
    Posts
    24
    Thank you so much Saikee for your detailed explanation. Sorry for the 3 days gap in replying to your post... I was actually reading up on hard drive geometry so I can make better sense of your reply.

    It appears the whole track or the first head, equal to the number of sectors per head times sector size, is reserved for the MBR usage.
    You mean 'equal to the number of sectors per TRACK times the sector size.
    Because from what I gleaned, head is simply the physical head to read sectors on the platter. The actual sectors are on the tracks. Right.

    as Manufacturer A might opt for 16 sectors per head while another manufacturer B chose 32 sectors per head
    again, you mean 16 sectors per track, 32 sectors per track.. right?

    Code:
    dd if=/dev/sda of=dragons-enclave.bak bs=512 skip=1 count=61
    The above command will skip the first sector (which is the true MBR), start and the 2nd sector and go all the way upto 62nd sector. Am I right?

    Therefore if you find a dragon there it is just its carcass.
    Thus, if I turn the carcass into ash by the following command:
    Code:
    dd if=/dev/zero of=/dev/sda bs=512 skip=1 count=62
    it shall zero out everything between the 1st sector (true MBR) and the 63rd sector. And after doing so, if the Operating System boots just fine, then there is nothing of value there, indeed just some carcasses laying around... Right?

  6. #6
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,984
    The cylinder, head and sector are not physical entities as far as I know. It is like a 3 dimension matrix system for access the data and the depth and width of the matrix can be freely fixed by the manufacturer.

    99.99% of the hard disks do use 512 bytes per sector and this seems to be the read write head would communicated with the outside world. I believe you can ask dd to read a sector. If you want a particular byte inside you have to use the operating system to strip out the information for you. The physical read/write head seems to pick up 512 bytes in each operation according to dd behaviour.

    I haven't tried much of it myself but Linux partitioning tools do allow a user to change the cylinder, head and even the sector size.

    You have interpreted my post the way I believe so but do make a backup if you mess around with the partition table.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  7. #7
    Join Date
    Sep 2009
    Location
    Toronto
    Posts
    24
    Thank you for all your help and insight

Tags for this Thread

Posting Permissions

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