LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-15-2008, 11:47 AM   #1
habitue01
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Rep: Reputation: 0
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!

Last edited by habitue01; 11-15-2008 at 11:48 AM.
 
Old 11-15-2008, 12:26 PM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Quote:
Originally Posted by habitue01 View Post
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!
I wonder what these problems were. In fact, cp (or tar, rsync or whatever you prefer) is the way to go. Making a disk image makes no sense in linux and usually just adds complexity, like you already saw.

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.
 
Old 11-15-2008, 12:43 PM   #3
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,252

Rep: Reputation: 118Reputation: 118
Quote:
Originally Posted by habitue01 View Post
.. 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.
Now this is really a bad idea. Keeping your personal stuff separated from the system can save you a lot of trouble later on.
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:
--- assumption:
/ is /dev/hda1
/home is /dev/hda2

("edgar" is the name of my computer, type everything after "edgar:~#")
unmount /home:
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!
Good luck!
 
Old 11-15-2008, 01:29 PM   #4
habitue01
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 11-15-2008, 01:38 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
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.
 
Old 11-15-2008, 01:44 PM   #6
habitue01
LQ Newbie
 
Registered: Apr 2008
Posts: 4

Original Poster
Rep: Reputation: 0
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?
 
Old 11-15-2008, 01:55 PM   #7
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Quote:
Originally Posted by habitue01 View Post
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?
Well, you need to know where everything resides now.

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).
 
Old 11-15-2008, 03:24 PM   #8
habitue01
LQ Newbie
 
Registered: Apr 2008
Posts: 4

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


Reply

Tags
backup, harddrive, partitions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
fdisk reports odd "Start "and "End" sectors on single partition eponymous Linux - Software 3 10-01-2007 03:41 PM
Problems configuring "xorg.conf" with "ATI FGLRX" BlueSpirit Slackware 3 09-16-2006 02:01 PM
Common problems explained: "kernel panic - not syncing", "unable to mount..." sundialsvcs Linux - Newbie 2 03-01-2006 12:17 PM
why iam getting problems like "...too many files opened" or "segmentation fault" naren_0101bits Linux - Newbie 2 07-19-2004 12:20 PM
anging "Protocol" option to "IMPS/2" in XF86Config-4 causes problems zstingx Linux - General 2 10-27-2003 09:47 AM


All times are GMT -5. The time now is 03:38 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration