Pages

8/31/2013

How to move some system directory to another disk

This blog post is not much networking related and it is a modified sequence that proposed by my chef. There could be errors. Feel free to correct me in comments.

In this tutorial I am going to move /usr directory to a new physical disk. Reason of moving this directory is because there is no much space left on /dev/sda1. System used is Ubuntu Server 10.4.

Login as root:
$ sudo su -

Command to check how to see how much space do left on /dev/sda1 (root directory: /)
$ df -H

Format disk sdb1 with ext3. Same as is sda1. Partitions should have been created on sdb [1]
$ mkfs -t ext3 /dev/sdb1

Stop as much proccesses as you can. So copying files is more "safe".
$ ps aux | more
$ netstat -tulpn | more
$ killall <processname>
$ kill <processid>

Make new directory on a root directory
$ mkdir /usrtmp

get disk UUID [2]
$ ls -l /dev/disk/by-uuid
or
$ blkid

modify /etc/fstab. Add line like this [3]
UUID=aabbccdd-eeff-1234-5678-abcdef01234 /usrtmp  ext3  relatime,errors=remount-ro  0  1
  
mount disk to directory /usrtmp.
$ mount /dev/sdb1 /usrtmp
 
copy files from /usr to /usrtmp (for example via Midnight Commander - mc) and preserve Attributes or

$ copy -pR /usr/ /usrtmp/

erase content of original /usr (via mc) or
$ rm -rf /usr

umount new disk

$ umount /usrtmp



change /etc/fstab

UUID=aabbccdd-eeff-1234-5678-abcdef01234 /usr  ext3  relatime,errors=remount-ro  0  1

remount it to /usr
$ mount /dev/sdb1 /usr




References:
[1] https://help.ubuntu.com/community/InstallingANewHardDrive#Partition_The_Disk
[2] http://liquidat.wordpress.com/2007/10/15/short-tip-get-uuid-of-hard-disks/
[3] https://help.ubuntu.com/community/Fstab