Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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?
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.
** 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.
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?
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.
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.
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)
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.