Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
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.
I am running Centos 6.2 and the hard disk in the system started to fail, so I was able to clone it to another, slower disk to keep things running temporarily.
I want to replace that disk with a new one, but the new one is slightly smaller than the original and the partitions don't fit. The disk has an LVM on it, and while there is plenty of unused space and I was able to resize the partitions inside the logical volume (doing a resize2fs followed by an lvreduce) so that there is free space, I cannot shrink the LVM itself to get the physical partition to be small enough so that I can clone it to the new disk.
I have tried to vgreduce it (while booted into a rescue cd) but I am told it is "still in use". I also looked at pvresize but that gave me an error (sorry, did not make a note) and would not do anything.
I also tried gparted to resize the partitions as I cloned the disk, but found that it does not support lvm2.
Actually, you may be able to do it more simply using dump and restore. (assuming the same filesytem type in use...) As long as the old filesystem is smaller than the new partition, the restore command will do the right thing.
Create fresh and clean filesystems and mount them on your OS.
install dump and restore.
resize your old disk to slightly smaller than the new replacement disk's.
note the disk partitions that correspond to your old disk
cd <new mount point!)
dump -0af - /dev/<partition on old disk> | restore -rf -
run fsck on the restored filesystem, if all is well, delete the "restoresymtable" file.
The part about "resize your old disk to slightly smaller than the new replacement disk's." is exactly the part I can't figure out how to do. So if you could tell me how I can do that, then I am all set.
Sorry, I made the assumption you had already done that based on a tiny blurb in your initial post.
Quote:
(doing a resize2fs
once you use resize2fs, you don't really need to do much else, at least as far as using the dump command is concerned. Resize2fs will alter the size of the filesystem, but not the partition size. dump looks only at the filesystem-block level, and the partition size won't even interest the program. That's why I suggested dump: you can totally skip resizing the original partition.
Actually, now that I think about it, so long as the actual used filesystem space is smaller than the destination partition, dump and restore are smart enough to do that correctly.
restore will take the output of dump (or a dump file) and re-build the filesystem structure onto an existing filesystem. It CAN be used to restore to a subdirectory on a used filesystem, it is best to have a clean filesystem to restore to.
dump and restore will ALSO place important files such as your boot images (if it's THAT partition) at the correct inode number, which rsync, tar, cp, et al will not. dump and restore also correctly handle sparse files, sockets, block and character devices, and will stay in it's own filesystem (won't accidentally backup up /proc for instance).
so I will carefully list out the steps:
Quote:
1) note the original parition number you wish to backup (in this example, I will call it /dev/sdb1)
2) unmount the original filesystem (this will ensure it is totally quiescent!)
a) umount /dev/sdb1
3) build a new filesystem on the new disk, and mount it. (in this example, I will call the new partition /dev/sdc2 and the mount point /mnt/newfs)
a) mkfs.ext4 /dev/sdc2 <-- I like ext4 filesystem, but you choose...
b) mount /dev/sdc2 /mnt/newfs
4) dump and restore
a) cd /mnt/newfs
b) dump -0af - /dev/sdb1 | restore -rf -
5) cd /
6) umount /mnt/newfs
7) fsck -f /dev/sdc2
once done, mount the new filesystem and make sure it looks right. alter your fstab and boot into it.
I ended up following the directions here: http://fedorasolved.org/Members/zcat...-new-partition to shrink the physical partition enough so that I could clone the disk to the new one using Acronis True Image. Things seem to working ok with the new disk, and hopefully will stay that way.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.