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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubunto and slowly switching to debian
Posts: 308
Rep:
best way to copy a drive including boot sector?
Hi there,
what is the best way to copy every thing from one drive to another. I have 2 drives a 300GB drive and an 80GB drive. My os is installed on the 300GB drive but only 17 GB is been used so the drive could be put to better use. I want to copy all info without any change (ie permission change) plus the boot sector.
I have done this several years ago but cant remember how also that was onto a larger drive rather than a smaller drive, so i dont know if it is all the same.
My OS is SLES 9, and their is currently no data on the 80GB drive. also will i have to change any files ie fstab bearing in mind i will swap the sata cables over so that the 80GB drive will become sda1 instead of the 300GB drive
You can use the dd command to do what you want, but you'll need to use a partition editor to "correct" the partitioning you'll end up with on the smaller drive, since the partition information from the 300GB drive will have been copied to the smaller drive. The last time I did a dd drive copy, the only partition editor that could "fix" the partition table was gparted. (All of qtparted, kparted, and parted itself, "barfed" at the bad partition table but would only "fix" it by creating a new table which, of course, logically deleted the drive contents. Note, however, that it has been at least two years since I did a dd drive clone, so the other tools may now work.) The drive I was cloning contained a Fedora 8 installation and a XP installation in four partitions (ext3, lvm, ntfs, ntfs recovery), and -- after the "fix" -- both Fedora, XP and the MiniNT all worked as expected.)
See man dd for information on using the dd command, or, if you want more information, look in the "how to" LQ sub-forum.
Distribution: Ubunto and slowly switching to debian
Posts: 308
Original Poster
Rep:
if i create a new partition on the 80GB drive and rsync the 300GB drive to the 80GB drive would this work? forgetting the boot sector of course. no permission changes or any thing?
as for the boot sector i will install it on a floppy until the drives are swapped then re-install it into the boot sector of the 80GB drive.
would this work? its just i am wary of file permissions changing or any thing like that.
Well, yes, you can do it that way but some of the things in /dev don't copy as you might expect. (For example, copying /dev/null or /dev/random to a new partition could fill the new partition with undesirable things. And not having those devices in the new system could make it less functional than you might desire.)
So, if you want to clone the stuff from the large drive to the smaller one, I'd still suggest using dd. If you skip the boot sector and partition table, you should have no problems, and you can always run grub-install after you boot from the 80GB drive to get the boor sector set up properly. Look, for example, at this thread where all this is described in great detail with the precise command format illustrated.
Last edited by PTrenholme; 09-06-2008 at 12:00 PM.
Reason: Typos
Distribution: Ubunto and slowly switching to debian
Posts: 308
Original Poster
Rep:
another question, whether i use dd or rsync do i have to unmount any file systems so it doesnt copy 2TB of data out of /mnt/raid5 or doesnt it copy mounted filesystems?
Boot off a live cd, this eliminates the problem handling stuff in /{dev,sys,proc}, and also avoids corruption/locking problems due to the files being used (or even changed) concurrently while you copy them.
Use cp -a, tar -p, rsync or whatever you preffer to copy the files. Make sure you use the relevant parameter to preserve the permissions and ownerships.
For the boot sector you have two options. I would personally just run grub-install to reinstall it into the new hard disk, and forget about tinkering with odd stuff. The second option, if you really like risk, is to use dd, use bs=512 count=1 to save the boot record only (the first 512 bytes of the disk), then dump that on the other disk using dd again.
Distribution: Ubunto and slowly switching to debian
Posts: 308
Original Poster
Rep:
i have ran
fsck.reiserfs /dev/sdb1 --rebuild-sb
than
fsck.reiserfs /dev/sdb1 --rebuild-tree
than the file system could be mounted
now for the real test when i swap the drives over
Plus i am going to try installing the boot loader and MBR using yast but on sdb so hopefully the OS will load when I swap the drives. will let you know what happens when i try it
The second option, if you really like risk, is to use dd, use bs=512 count=1 to save the boot record only (the first 512 bytes of the disk), then dump that on the other disk using dd again.
Distribution: Ubunto and slowly switching to debian
Posts: 308
Original Poster
Rep:
at the minuet i swapped the drives, inserted the original lses9 install disk, select install and then select boot installed system where i get the error message invalid root partition.
this may be due to what keefaz posted above. i will re try coping the fs again using the above command
dd is not the tool for this. See post #6 for my preferred method also - for copying the data, not the MBR. Always reinstall the bootloader - you can also do it from the liveCD.
You're making your life harder imho
I would just boot from a live CD (like the gparted live CD) partition the new drive the way I want, mount the new partition (say in /mnt/hd2), mount the original root partition (say in /mnt/h1)
cp -a /mnt/h1/* /mnt/h2, edit /mnt/h2/etc/fstab and set bootloader to boot in new partition from new drive
I agree with those who argue that dd is not the tool to be using for backups. You should backup and restore by file, not by hard drive. For things like the MBR and the partition table which are not files you are best off to restore using the utilities which create the MBR and the partition table.
If you use a direct copy method then you can run into a lot of flaky errors. One major problem is that updates to the original files while you are doing the dd can cause the backup files and/or filesystem tree to be corrupt to the point of not being usable.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.