Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I built my Linux box (using Ubuntu 8.04 LTS, last year) in order to try Linux. As it was just a try I opted to use an old 80GB hdd and now, as was always inevitable, it's running out of room. I've bought a new drive (1TB, though I'm unsure if that's relevant) ready to install, for the space and, hopefully, to make future distro upgrades easier.

Is there an easy means by which my /home partition can be relocated to the new drive, leaving the OS on the old?

I realise that 'easy' may be only for a given value...but any help is appreciated. Also, are there likely to be any problems using a 1TB drive, my mobo seems happy to support it from the manual, but are there any esoteric Ubuntu problems with large drive sizes?

share|improve this question

2 Answers 2

up vote 11 down vote accepted

no problems with 1TB drives ( this isn't large ;-))

Create a partion and format the new drive (I call it /dev/sdb1 now). With partition sizes over 300GB I prefer XFS.

Now logout from X, login at tty1 as root. Mount the new partition on /mnt/temp-home and copy your data:

mkdir -p /mnt/temp-home && mount /dev/sdb2 /mnt/temp-home
rsync -WaP /home/ /mnt/temp-home/

Now check twice, if /mnt/temp-home holds your data with the right permissions and ownership. You can move the foldername, if you want and delete your old home later:

mv /home /home_old

As root create the new mountpoint and a fstab-entry:

umount /mnt/temp-home
mkdir /home
chmod 0755 /home
cat >> /etc/fstab <<EOF
/dev/sdb1 /home           xfs     defaults        0       2
EOF
mount /home

your are done! Now login to X (gnome/kde/xfce..). and enjoy your new drive.

Don't forget to delete /home_old to free space!

share|improve this answer
2  
I would also suggest doing the above from single-user mode, or from a boot CD. XFS is also a good tip -- fsck.ext3 takes for-fricking-ever on a large volume. –  Karl Katzke Aug 7 '09 at 20:43
    
Thank you =) I think I can follow that okay... bearing in mind that I am, completely, inexperienced to Linux are there any points that you feel merit further explanation? It's going to be a couple days before I get the sata cable, but I'll accept now, in line with the community up-votes. Thanks again! –  David Thomas Aug 7 '09 at 20:58
1  
If his old /home was on a different partition, your mv /home /home_old and fstab append aren't going to do it. –  Chad Huneycutt Aug 7 '09 at 20:59
2  
BTW, this is one of those times when it is handy to actually have a root password. Moving /home really doesn't require single user or rescue mode, but you can't really do it if you are logged in as a user and sudo'ed up. –  Chad Huneycutt Aug 7 '09 at 21:01

I'm a little more conservative, because I've had to do this on larger systems, with data that . My method:

Create the new filesystem and mount it somewhere (say /mnt/new-home)

As root, use rsync to copy the data from the current location to the new location:

# rsync -avW --progress --delete /home/* /mnt/new-home

You can do that part with the system live and users logged in. In fact you can do it more than once -- subsequent runs should be faster since most of the data is already there, and the --delete flag will clean up files which have been removed. (man rsync will help you with the other flags I've selected.)

Now you need a maintenance window where you can kick everyone off the server. Boot to single user mode, re-mount /home and /mnt/new-home, and run the rsync command again. This rsync run should be fast since 99% of the work has already been done. (Or at least faster than running it for the first time, anyways -- I've had "single-user, last-pass" rsyncs run for up to four hours to do almost nothing...)

When that's done, change /etc/fstab so that the partition you've been using as new-home gets mounted as /home. You can also mount the old home partition as /home.old, or if it was just a directory in a larger partition, rename it to /home.old.

Reboot back to multiuser, and you should be done.

The reason why I don't use mv as recommended by ThorstenS is because I've had bad experiences where mv would crap out half-way through. By using rsync, if you make a dog's breakfast of new-home, you can always unmount it, newfs it, and you are back in business -- no data lost. And also I like to keep the old source around for a while just in case my brand new 1TB drive tosses itself in the first week. After a while you'll be happy with the new drive (or desperately need the space occupied by the old) and you can clean it up.

Your backups are good, right? :)

share|improve this answer
    
In the first codeblock I also use rsync to copy the content of /home. mv is only used for 'backup-reasons'. –  ThorstenS Aug 8 '09 at 18:43
    
You are right, I read it too fast. –  David Mackintosh Aug 9 '09 at 3:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.