Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
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?)
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
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 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.
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.
(for example, would I need to do something about the partition IDs in fstab?)
Yes, Grub needs re-installing and /etc/fstab needs correct uuids (or disk labels which is what i'm using). But that's not really so much work. A few other things include confirming SSH fingerprints on the new system once again, and stuff like that. Otherwise, moving a system isn't that difficult. Once u got the bootloader and /etc/fstab updated, the whole shebang should already boot quite smoothly.
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:
Error opening '/dev/sde1': Permission denied
Failed to mount '/dev/sde1': Permission denied
Please check '/dev/sde1' and the ntfs-3g binary permissions,
and the mounting user ID. More explanation is provided at
http://ntfs-3g.org/support.html#unprivileged
So I tried "sudo mount /dev/sde1 /media/usb0", which worked -- although the same command without 'sudo' doesn't. I temporarily chmod'd /media/usb0 to 777, but still couldn't mount the drive as a normal user. Here's my /etc/fstab:
Code:
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
# / was on /dev/sda1 during installation
UUID=31a8b5b0-8985-4d97-97e9-d695dc379eb0 / ext3 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=e5d582b9-9cfd-4530-9171-e475609a2cb9 none swap sw 0 0
#
# New SATA drives
/dev/sdb1 /var/multimedia ext3 defaults 0 0
/dev/sdc1 /var/share/install ext3 defaults 0 0
#
# Mount LaCie backup drive on /media/LaCie
/dev/sdd1 /media/LaCie auto rw,user,noauto 0 0
#
# Now added two SATA drives and converted LaCie to ext3, the first 'other' USB drive is now on /dev/sde
/dev/sde1 /media/usb0 auto rw,user,noauto 0 0
I'm confused, partly because this fstab worked fine with the failing HD: plug in the second external drive and it automounted -- so I suspect that I'm missing something else.
Yes, Grub needs re-installing and /etc/fstab needs correct uuids (or disk labels which is what i'm using). But that's not really so much work. A few other things include confirming SSH fingerprints on the new system once again, and stuff like that. Otherwise, moving a system isn't that difficult. Once u got the bootloader and /etc/fstab updated, the whole shebang should already boot quite smoothly.
Clonezilla or mondorescue will adjust this automatically?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.