Showing posts with label new partition. Show all posts
Showing posts with label new partition. Show all posts

24 October 2014

598. Move /var, /tmp, /opt to separate partitions

1. First create the partitions on a disk. In my case I created partitions on a different disk from the root partition.

2. Figure out the uuids:
ls /dev/disk/by-uuid -lah
lrwxrwxrwx 1 root root 10 Oct 22 14:02 28b59809-7dfb-4ce4-a4da-6f118171ea07 -> ../../sdb2 lrwxrwxrwx 1 root root 9 Oct 22 14:45 52f07f83-3a72-457c-b25f-7aa4f3e76461 -> ../../sdc lrwxrwxrwx 1 root root 10 Oct 7 14:42 8a5ca4ae-9963-47ea-99c3-2335c7dc8118 -> ../../sda6 lrwxrwxrwx 1 root root 10 Oct 7 14:42 9243ff6b-9834-4fa3-a93f-10a350f85687 -> ../../sda1 lrwxrwxrwx 1 root root 10 Oct 22 14:02 9f785dde-1d3a-4063-90e7-054f3d031e05 -> ../../sdb3 lrwxrwxrwx 1 root root 10 Oct 22 14:02 eacf2cad-d462-45b2-afeb-2c5ddf5669b8 -> ../../sdb4 lrwxrwxrwx 1 root root 10 Oct 7 14:42 f25a484c-e8e2-4ead-808b-96dd5e915020 -> ../../sda5 lrwxrwxrwx 1 root root 10 Oct 22 14:02 f4280c34-04d6-4def-963a-507e68dd483d -> ../../sdb1
I know that I'm looking for sbd2 (label: tmp), sdb3 (label: opt) and sdb4 (label: var). We'll use these uuids later for our /etc/fstab

3. Move /opt, as it's the easiest (should be reasonably static).

sudo udisks --mount /dev/sdb3
Mounted /org/freedesktop/UDisks/devices/sdb3 at /media/opt
sudo cp -ax /opt/* /media/opt

Edit /etc/fstab:
 
UUID=9f785dde-1d3a-4063-90e7-054f3d031e05 /opt ext4 defaults,user_xattr 0 2

Move the old /opt and mount the new one:
sudo mv /opt /opt.old
sudo mount /opt

And you should be good to go. Check with df -h:
[..] /dev/sdb3 72G 28G 41G 41% /opt

4. Move /var and /tmp

You can use init 1 according to http://unix.stackexchange.com/questions/131311/moving-var-home-to-separate-partition. Note that doing so will kill your graphical session and stop or restart most of the services i.e. close open documents before your continue. You'll then get dumped into a vty.

Open a terminal and type
 
init 1

which dumps you into a root terminal. Then, as root, do
 
mkdir /media/var
mount /dev/sdb4 /media/var
cp -ax /var/* /media/var
mkdir /media/tmp
mount /dev/sdb2 /media/tmp
cp -ax /tmp/* /media/tmp
mv /tmp /tmp.old
mv /var /var.old
mkdir /tmp
chmod 777 /tmp
mkdir /var
umount /media/var
umount /media/tmp

Changing the permissions for /tmp is important -- if they aren't generous enough it can cause all sorts of issues. In my case it was manifested by me being unable to log onto a GUI (e.g. gnome) from GDM3 -- I would get booted back to the login screen.

Edit /etc/fstab and add:
UUID=28b59809-7dfb-4ce4-a4da-6f118171ea07 /tmp ext4 defaults,user_xattr 0 2 UUID=eacf2cad-d462-45b2-afeb-2c5ddf5669b8 /var ext4 defaults,user_xattr 0 2
Note: I don't know what the best values for the attributes are. I just took what I used for /home, which is probably not optimal. You may want to do your own research into this. Then do

mount /tmp
mount /var
init 2

Once you've established that all is well you can delete /var.old and /tmp.old.
df -h shows
Filesystem Size Used Avail Use% Mounted on rootfs 92G 32G 56G 37% / udev 10M 0 10M 0% /dev tmpfs 798M 1.1M 797M 1% /run /dev/disk/by-uuid/9243ff6b-9834-4fa3-a93f-10a350f85687 92G 32G 56G 37% / tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 4.6G 88K 4.6G 1% /run/shm /dev/sda6 734G 555G 142G 80% /home /dev/sdb3 72G 28G 41G 41% /opt /dev/sdb2 72G 53M 69G 1% /tmp /dev/sdb4 48G 8.8G 37G 20% /var