You are not logged in.

#1 2009-12-20 19:21:18

JMO
Member
From: Argentina
Registered: 2006-04-08
Posts: 98

Moving /home to a new partition

I had an order craving recently, and wanted to move my home directory to a separate partition. My hard disk is currently divided like this:

S.ficheros          Tamaño Usado  Disp Uso% Montado en
/dev/sda5              51G   35G   14G  73% /
none                  941M   88K  941M   1% /dev
none                  941M     0  941M   0% /dev/shm
/dev/sda8             219G  128G   92G  59% /homefedora
/dev/sda6              22G   22G     0 100% /fedora

/homefedora was an old partition I used to have on Fedora for the same porpouses that those I want now. The deal would be to take sda8 free space, put it on sda6, having previously formated it and being my new /home partition, and then move everything from /home and /homefedora to it. Finally, merge sda8 to sda6

I think that Gparted can do most of those things, but my question is about changing /home path and the precautions I should have when doing it.

Thanks for your time!

Last edited by JMO (2009-12-20 19:22:00)

Offline

#2 2009-12-20 20:32:36

R00KIE
Forum Fellow
From: Between a computer and a chair
Registered: 2008-09-14
Posts: 4,734

Re: Moving /home to a new partition

Do a search on the forums and the web and you will see that it's quite easy, mostly its just moving the directories, update /etc/passwd either manually or with usermod (I think).

I have changed mine very recently (due to a reorganization/resize of partitions) and the only other thing I did was be careful to check and change all config files that had the path hardcoded.

When copying things with cp beware that cp -a doesn't copy really everything, if you have dot files in the working directory they will not be copied (make some tests before). To do it all at once use:

cp -a `ls -A | grep -v lost` destination

to find config files that may need changing I've used:

grep -irl old_home_path `ls -A | grep '^\.'` > files_to_change.txt

then inspected the file for possible binary file matches (firefox and thunderbird will have some files on the list).

Finally just did

cat files_to_change.txt | while read -r ff; do sed -i s/old_path/new_path/ $ff; done

As always __backup everything before you start__, I had a disk image of the whole hard disk, I could afford to screw things up. Make sure you have a safety net in case something goes wrong.

On the use of gparted, I didn't want to use it because it makes a mess out of the partition table and there are cases where it screwed things up quite badly (specially when moving/resizing partitions, I had a really bad encounter with this problem and other people too), I did a full disk image (I had a spare disk big enough for that) and started from scratch. As a plus you can change the filesystem of the partition easily and take advantage of all the features of recent filesystems (ext4 comes to mind wink ).

Edit:
Small code correction.

Last edited by R00KIE (2009-12-20 20:33:16)


R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K

Offline

#3 2009-12-20 21:00:49

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 788
Website

Re: Moving /home to a new partition

I have done this sort of thing quite often. The most recent was on the weekend I converted my main workstation to lvm. I never use any partition resizing apps for this as they just make me too nervous. I always just back up everything to external storage using cp -av in a livecd environment, repartition, create file systems and then copy everything back. Fix /etc/fstab, grub and your initrd and you are good to go.

Offline

#4 2009-12-20 22:08:30

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Moving /home to a new partition

Alternative way of copying (ensuring symlinks and whatnot are handled properly):

find <src_dir> -depth -print0 | cpio --sparse --null -pvd <dest_dir>

Offline

#5 2010-01-28 01:13:13

JMO
Member
From: Argentina
Registered: 2006-04-08
Posts: 98

Re: Moving /home to a new partition

Thanks for the code. That was helpful smile

Offline

#6 2010-01-28 03:00:54

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: Moving /home to a new partition

This is Alan Cox's backup script - I just love it for the ease and simplicity and it does dot-files and links perfectly ...
So here goes:

(cd $SRC && tar cf - .) | (cd $DEST && tar xvpf -)

Offline

#7 2010-07-16 06:24:05

T-u-N-i-X
Member
From: İstanbul
Registered: 2006-03-14
Posts: 435
Website

Re: Moving /home to a new partition

perbh wrote:

This is Alan Cox's backup script - I just love it for the ease and simplicity and it does dot-files and links perfectly ...
So here goes:

(cd $SRC && tar cf - .) | (cd $DEST && tar xvpf -)

wow this looks great! i really appreciate it, thanks!


Quis custodiet ipsos custodiet?

Offline

Board footer

Powered by FluxBB