LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 09-06-2008, 09:50 AM   #1
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Rep: Reputation: 30
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

thanks in advance

berrance
 
Old 09-06-2008, 10:13 AM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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.
 
Old 09-06-2008, 10:19 AM   #3
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Original Poster
Rep: Reputation: 30
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.

also what would the best rsync command to use be?
 
Old 09-06-2008, 11:42 AM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
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
 
Old 09-06-2008, 01:06 PM   #5
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Original Poster
Rep: Reputation: 30
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?
 
Old 09-06-2008, 01:23 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
I would do it this way to avoid problems:
  1. 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.
  2. 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.
 
Old 09-06-2008, 01:31 PM   #7
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Original Poster
Rep: Reputation: 30
ok i just tried to run

dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=notrunc,noerror

get the error message

dd: invalid conversion: notrunk

got the command and info from

http://www.linuxquestions.org/questi...ommand-362506/

under the section linux DD

boot sector i arnt bothered about that i have done before, and if it doesnt copy properly i can try again until it works.
 
Old 09-06-2008, 01:33 PM   #8
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Original Poster
Rep: Reputation: 30
ignore me im an idiot i used a K instead of a C, i put notrunk instead of notrunc.

good old idiocy strikes again. he he he

coping now

let you how it goes
 
Old 09-06-2008, 03:02 PM   #9
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Original Poster
Rep: Reputation: 30
ok copy finished but when i try to mount the file system this happens

/ # mount /dev/sdb1 /data1 -t reiserfs
mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
or too many mounted file systems

is this the partition table thats broken?
 
Old 09-06-2008, 03:26 PM   #10
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Original Poster
Rep: Reputation: 30
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

thanks for the help so far

berrance
 
Old 09-06-2008, 04:08 PM   #11
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by i92guboj View Post
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.
Better use bs=446, else you duplicate also the partition table which may not be the same on the new drive
http://en.wikipedia.org/wiki/Master_boot_record
 
Old 09-06-2008, 04:48 PM   #12
berrance
Member
 
Registered: Aug 2004
Location: Hull - England
Distribution: Ubunto and slowly switching to debian
Posts: 308

Original Poster
Rep: Reputation: 30
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

again thanks for the help guys
 
Old 09-06-2008, 04:56 PM   #13
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
Old 09-06-2008, 04:59 PM   #14
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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

Last edited by keefaz; 09-06-2008 at 05:01 PM.
 
Old 09-06-2008, 05:12 PM   #15
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,337

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
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.

----------------
Steve Stites
 
  


Reply



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
Probem copy whole backup including hardlinks to another system hendrixx Linux - Software 3 08-05-2008 07:26 AM
Easiest way to copy a boot drive to a new hard drive lsgko Linux - Software 3 05-24-2005 09:38 PM
Boot Sector on dual boot PC. Remove Mandrake and replace with FreeBSD Phin666 *BSD 1 10-30-2004 05:02 PM
using DD to copy the boot sector in and out antken Linux - General 5 04-03-2004 06:30 PM
boot error after using Copy Commander to copy debian system onto larger new drive Interceptor Linux - Hardware 7 05-04-2003 12:40 PM

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

All times are GMT -5. The time now is 01:04 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