How to 'clone' to smaller drive?
Is it possible to directly clone a drive (500GB, 2 partitions [32GB swap with balance ext3 as sda1], 35GB of sda1 in use) to a smaller drive (160GB)?
Background: Debian Squeeze 64 bit ... I recently built a new server with a 500GB Seagate SATA drive as sda but that drive is now showing SMART errors and Disk Utility suggests the drive is about to fail. The people who sold me the drive have given me an RMA number, so I've got to replace the 500GB drive with the smaller one until I get the replacement for the duff drive. I can boot into Puppy Linux (can't remember offhand which version) and so have both drives available unmounted to copy files, MBR, etc. However, I'm not sure how to do this and so help would be most welcome. If necessary, I suppose I can do a fresh install of Debian onto the new drive and then boot into Puppy Linux to copy the contents of the old drive onto the new one, but I'm not completely sure that would work (for example, would I need to do something about the partition IDs in fstab?) All help gratefully received. Geoff |
I'm sure there are some fancy backup utilities out there which would do it. but I think you could do it with parted or resize2fs and dd.
I could be wrong on this, but I think you have to shrink your partitions first if they are bigger than the destination since data isn't always written symmetrically. Maybe that is an un-necessary step, but here is how I would do it. assuming your 160gb drive is sdb: used fdisk or parted to create sdb1. Make it the same size as sda1 you can do what you the same with the swap but if thats your only other partition I don't think you really need to copy the swap. I would run fsck on sda, before attempting any resizing. Make sure the machine was completely shut down and not hibernating. use parted or resize2fs on sda1 to shrink the partition (check the man files for details) use dd to copy the filesystem with the notrunc flag. Something like this Code:
dd if=/dev/sda1 of=/dev/sdb1 conv=notrunc |
copy -a will do.
|
Thanks guys!
Certainly a pointer in the right direction. I guess my safest 'easy' option would be to back up the old drive to an external USB HD (just in case!), then use resize2fs to shrink sda1 to fit the smaller drive, power down, add the new drive, then boot Puppy Linux to use dd to first copy over the MBR, then the ext3 filesystem to the new drive, then use gparted to create a new swap partition, move the disks to their final location on the machine, then cross fingers and power up the machine... I've scheduled the work for this weekend! Thanks again, Geoff |
I would simply use cfdisk to partiton the smaller drive, use mount the partitons, copy everything to the smaller drive using rsync and chrrot into the smaller partiton to reinstall the boot-loader. No experimenting with resize2fs and dd needed.
|
Clonezilla. This is the right tool for the job (not that there aren't others). But it's open source, easy to use, and not what I would call "fancy".
|
See also mondorescue
|
I would not try to use a filesys-resizer on a disk with damaged sectors. Get all files off that disk ASAP by copying file-by-file. Corrupt sectors have that tendency to be contagious, i.e., the more you try to read in the damaged area, the more neighbor sectors become infected, too. You might even end up with a failure when trying a fs-resize because some write op's could fail due to the damaged state of the disk, resulting in even more trouble.
I suggest to follow TobiSGD's advice, partition the smaller harddisk, copy all files over, then re-install the bootloader on the other (smaller) harddisk. Simple, safe, smart. |
Quote:
|
Thanks for the help, much appreciated.
That said, I must be missing something because every attempt to clone the drive ended up with an unbootable system. In the end, I did it the 'hard' way: 1. Do a fresh install of Debian Squeeze to the smaller HD. 2. Edit /etc/fstab by copying the 'tail' of the one from the old system to overwrite the 'tail' of the new. That way, I got to keep the new UUIDs that apply to the smaller HD. 3. Restore data to new installation from backup. 4. Install the required services and restore MySQL data from backup + create Samba accounts. Hours later, and it's all looking good except that my second USB external hard drive won't automount. When I plug it in, I get the following error: Code:
Error mounting: mount exited with exit code 1: helper failed with: Code:
# /etc/fstab: static file system information. Can someone point me in the right direction? |
Quote:
|
All times are GMT -5. The time now is 07:28 AM. |