Problems with "folding" one partition into another
I recently got a new 120 GB harddrive, and I wanted to replace the 80GB in my thinkpad. So I used a live cd and ddrescue and just copied the entire disk image, partitions and all over to the new drive. Then I used gparted to expand the partitions. So far so good.
Then, I thought I would get clever... and things went poorly. You see, the original drive had an additional partition for my /home directory, and I wanted to get rid of this partition and just have everything under the main partition. Unfortunately, the way I went about it caused a whole bunch of problems and pretty much wiped out everything in my home directory.
I have everything backed up (I still have the old drive that hasn't been touched), so I can just restore everything, but what I'm wondering is if there is a way to do this correctly. I want to take the contents of the /home partition, and actually place it in the /home folder on the main partition, and then only have one partition + swap. I tried just cp -r and this causes all sorts of problems.
Thanks for any assistance possible!
You just need to make sure you preserve the permissions (cp -a, tar -p), then you just need to install grub in the boot sector with grub-install. That can be done from a livecd. You also need to skip things like /dev and /proc, dev is handled today by udev, and /proc is a disk image of the kernel internal structures and has no real physical presence on your disk. All these "problems" go aways if you make this from a livecd, which is how you should do it anyway, because changing the volume while you are backing it up will give as a result a corrupted backup.
Making a full image is most times a waste of space and time, because you need to read the full disk, even if most of it is empty.
I strongly advice against it but well, it's your computer, do as you wish. If that's what you want here's how (I don't know how you did it, tell me more and maybe I can say where it went wrong).
Remember, while you are logged in as user you can't unmount /home, also some files under /home are used by system/programs. So log out from gui and all terminals and do the following as root:
/ is /dev/hda1
/home is /dev/hda2
("edgar" is the name of my computer, type everything after "edgar:~#")
edgar:~# umount /home
create a temp directory for old /home
edgar:~# mkdir /mnt/tf
mount your home-partition (in my example /dev/hda2) on temp directory:
edgar:~# mount /dev/hda2 /mnt/tf
Now /home is almost empty, check it to be sure:
edgar:~# ls -a /home/<username>
Copy your data:
edgar:~# cp -a /mnt/tf/* /home/
(that "-a" = dpr = copy directories, preserve ownership & timestamps, preserve links. Just "-r" is not good - it would in this example make root the owner of all files!)
Then when finished unmount from temp-dir and mount on home:
edgar:~# umount /dev/hda2
edgar:~# mount /dev/hda2 /home
That should do it. Have to go eat now, just return with further questions!
Awesome, yeah I didn't know about the -a option, that was probably my problem. I am copying it over now, I'll post when I have it finished.
It is very important to preserve the permissions, overall for the system files.
The user files are easily fixable with some find/chmod magic, but the system files need sometimes specific permissions and ownerships for everything to work ok. They also guarantee that each file has only the minimal permissions it needs, and nothing else (which would create lots of security problems). So, if you didn't think of that, then that was probably your problem.
I advise you to check the man pages for cp if you didn't already. -a is equal to -dpr, which in turn means that symlinks will be preserved (not deferenced/resolved), the permissions will be preserved and it will operate recursively across dirs. These would be default behaviors in tar except for the "preserve permissions" bit,, so only -p would be needed for tar. Other programs might use different options, it just depends on the concrete tool. So, checking the man page is always a good thing.
Don't forget to do this while the fs is mounted read only from a livecd, and you will not run into any trouble. In such case you don't have to worry about proc nor dev either.
Ok, so I copied everything over... Now I am seeing another issue that might pop up if I try to boot this disk. Basically, the /etc/fstab file still has the old partitions in it since I resized the partitions from a livecd (which assumedly changed its own fstab but left the one on the drive alone). How can I repair the fstab to reflect the new partition structure?
If /home is not mounted in another partition and you really want to have everything into a single partition (not advisable, but anyway...) then you will need to remove the line about home from fstab. For the rest, use df and fdisk -l to identify your partitions, edit fstab with a regular text editor and set it up correctly.
It shouldn't be a big problem, but if you have any doubts, just ask here being as concrete as you can (i.e. post fdisk -l and df output, your fstab and some explanation about the doubts and the new layout that you want for your disk).
Ok, I edited fstab with no problem. I was a little put off because my fstab uses UUIDs instead of /dev/* for the volumes, but I just used vol_id and added the new uuid of my swap drive and primary partition. It booted fine, and everything seems to be working great. Thanks for your help guys
|All times are GMT -5. The time now is 06:12 PM.|