LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-01-2007, 06:56 PM   #1
bharath_neo
LQ Newbie
 
Registered: May 2007
Posts: 8

Rep: Reputation: 0
DD Command doubts


Hi,
Firstly a huge thanks for the 'dd tutorial' posted. I want to use dd to create a clone file of a bootable partition and use this file to replicate the data (not the geometry) in other systems.

There was a command in the tutorial which does this:
dd if=smaller_partition of=/home/sam/smaller_partition.img

** Does this copy the boot files (boot sector), FAT and also the partition table of the disk?

The command to clone it in other systems in the tutorial was :
mount -o loop /home/sam/smaller_partition.img /mnt/directory
cd /mnt/directory
cp -r * /mnt/larger_partition_already_partitioned_and_formatted _to_the_size_you_want

** Wont this just copy the files per say and not do a clone like what a dd should do? (Will the boot sector & FAT be updated?)

** And the final question is - Is there a method to truncate the free space while creating the image file?

Regards,
Bharath
 
Old 08-01-2007, 07:11 PM   #2
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
Quote:
There was a command in the tutorial which does this:
dd if=smaller_partition of=/home/sam/smaller_partition.img

** Does this copy the boot files (boot sector), FAT and also the partition table of the disk?
If "smaller_partition" is /dev/sda1, /dev/hdb4 or something similar (a single partition of a device), then no, the boot sector and partition table are not copied. The FAT is part of the file system, so it is copied in this case.

If "smaller_partition" is /dev/sdb or somesuch (ie there's no number at the end indicating a single partition), then everything is copied. So for example a flash card with multiple partitions would have the entire image saved. It's possible to mount individual partitions inside the image afterwards using the offset= option of mount.

Quote:
cp -r * /mnt/larger_partition_already_partitioned_and_formatted _to_the_size_you_want

** Wont this just copy the files per say and not do a clone like what a dd should do? (Will the boot sector & FAT be updated?)
In this case you will have already had to create the partition and the file system, as indicated, so the boot sector is irrelevant. The FAT (if applicable) will be updated as you copy the files over

The advantage to doing it this way is that you can change file system types - if you use dd then the file system will be exactly the same.

Quote:
Is there a method to truncate the free space while creating the image file?
Not really, that's not the purpose of dd. There are other ways to accomplish this, though.
 
Old 08-01-2007, 09:22 PM   #3
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Quote:
Originally Posted by bharath_neo
There was a command in the tutorial which does this:
dd if=smaller_partition of=/home/sam/smaller_partition.img

** Does this copy the boot files (boot sector), FAT and also the partition table of the disk?
The partition table is in the MBR, (Master boot record), All you are doing here is copying all sectors of the partition which will include the partition boot sector, including the MFT (Master file table) which would be the FAT in a Fat file system partition.
Quote:
Originally Posted by bharath_neo
mount -o loop /home/sam/smaller_partition.img /mnt/directory
cd /mnt/directory
cp -r * /mnt/larger_partition_already_partitioned_and_formatted _to_the_size_you_want

** Wont this just copy the files per say and not do a clone like what a dd should do? (Will the boot sector & FAT be updated?)
This will probably do as you suspect and copy all files, not necessarily all sectors as/is. Whether this will put the boot files in the first sector like the original is a little of a mystery to me also, trial and error would tell for sure.
Quote:
Originally Posted by bharath_neo
Is there a method to truncate the free space while creating the image file?
Yes there is, see this thread.
 
Old 08-01-2007, 09:33 PM   #4
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
PS:
Quite frankly, if you're transferring the image to another computer with a larger partition, it is probably better to reduce the partition size to the exact same size as the original, then resize it after it is up a running. If it's a boot-able operating system partition, you more than likely will have issues trying to get the image to work if the hardware is not the same from one system to the next. If they are identical systems as far as hardware goes, you may only have small issues with IP addresses and mac addresses of network interfaces, which may be resolved automatically upon first boot depending on which operating system.
 
Old 08-02-2007, 01:02 PM   #5
bharath_neo
LQ Newbie
 
Registered: May 2007
Posts: 8

Original Poster
Rep: Reputation: 0
Hi,
Thanks a lot for the replies.

Quote:
Originally Posted by Ciotog
If "smaller_partition" is /dev/sda1, /dev/hdb4 or something similar (a single partition of a device), then no, the boot sector and partition table are not copied. The FAT is part of the file system, so it is copied in this case.
The GRUB is stored in boot sector and the boot files of the OS in the start of the partition, right? I am sorry with the mistake in the 1st post. Its the boot files of the OS (present in that partition) that I want to copy.(The MBR can anyways be copied through dd separately right?)

Quote:
Originally Posted by Junior Hacker
This will probably do as you suspect and copy all files, not necessarily all sectors as/is. Whether this will put the boot files in the first sector like the original is a little of a mystery to me also, trial and error would tell for sure.
So, to test this is there any software that lets me see if the first sector has boot files or not?

Is it possible to unpack the contents from the image file to the disk using 'dd command' instead of 'cp command'?? (also from windows, if i want to unpack the same to a fat disk?)

Regards,
Bharath

Last edited by bharath_neo; 08-02-2007 at 04:09 PM.
 
Old 08-02-2007, 01:26 PM   #6
bharath_neo
LQ Newbie
 
Registered: May 2007
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Junior Hacker
Quote:
Originally Posted by bharath_neo
Is there a method to truncate the free space while creating the image file?
Yes there is, see this thread.
This reduces the size of the image but when it has to be laid on another disk, it has to uncompress to the original size (this means that the 2nd partition has to be the size of the 1st partition even though the image of the 1st partition can be really small). I am trying to create the image small so that it can be laid on a smaller partition (not recovering the string of zeros)
 
Old 08-02-2007, 02:19 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,805

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
I've just been doing some checking and verifying (since I get confused easily...

First, the "boot sector" is the first sector of a partition and DOES get copied with dd. I just ran some tests to prove this.

GRUB stage1 normally goes in the MBR (first sector of the drive), but CAN be in a partition boot sector. If, so, then something in the MBR needs to point to it (could be GRUB also)

The "boot files"--eg the GRUB stage files, the kernel, etc. are stored in the /boot directory which is part of the filesystem on the designated partition. No way to say if they are "at the start of the partition".

PS--possibly useless trivia: In verifying all of this, I discovered that creating a filesystem on a partition wipes out GRUB---ie you have to format first, then install GRUB
 
Old 08-02-2007, 02:30 PM   #8
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Quote:
Originally Posted by bharath_neo
I am trying to create the image small so that it can be laid on a smaller partition (not recovering the string of zeros)
There are plenty of utilities that will assist you in shrinking the partition prior to making the image.

Last edited by Junior Hacker; 08-02-2007 at 04:48 PM.
 
Old 08-02-2007, 04:16 PM   #9
bharath_neo
LQ Newbie
 
Registered: May 2007
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks a lot. Awesome help.

Quote:
Originally Posted by pixellany
First, the "boot sector" is the first sector of a partition and DOES get copied with dd. I just ran some tests to prove this.
Does it gets copied back into the new partition at the 1st sector of the partition when copied from the image? How to test this?

$Junior Hacker: Made the correction in post #5

Last edited by bharath_neo; 08-02-2007 at 04:20 PM.
 
Old 08-02-2007, 07:07 PM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,805

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by bharath_neo
Thanks a lot. Awesome help.

Does it gets copied back into the new partition at the 1st sector of the partition when copied from the image? How to test this?
If you are using dd, the whole partition--including the first (boot) sector gets copied.

To read the first sector of--eg---/dev/hda4:

dd if=/dev/hda4 bs=512 count=1|hexdump -C

There are some characteristic "fingerprints"--including the word "grub" towards the end. Remember that grub stage1 gets "hard-coded" with pointers to the correct /boot partition---thus not all MBR or bootsector contents are the same.
You can get a sample from various places--MBR, boot sector, etc.--or look at the generic version in /boot/grub
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LVM doubts .. kirtikjr Linux - Software 1 07-13-2007 06:29 AM
doubts about dd brazilian_user Linux - General 6 09-18-2006 07:58 PM
Several doubts talpa_sai Linux - Newbie 1 09-08-2006 04:06 AM
Doubts in c rajesh_b Programming 2 06-06-2005 10:54 PM
Networking doubts pongsu Linux - General 2 10-02-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration