A quick post explaining how you can move out /tmp directory from / to new mount point on the new disk

One of the headaches for sysadmin is getting a file system full. It can have many reasons from blaming application, and un-adequate capacity planning to an un-organized file system structure. We are going to look at the file system aspect of it.
Server with a single disk approach i.e. root disk is formatted as one partition and mounted as / is common these days. But, there are servers on-prem that still follow the slicing of disks and mounting different root FS on their approach. So if your server is one of them and for some reason, your /tmp directory is part of / and not separate mount point then this article is for you.
In this article, we will walk you through step by step procedure to mount /tmp on another disk as a separate mount point. We are going to separate out /tmp directory from / file system as /tmp mount point. We are taking an example with LVM but the procedure remains the same if you want to mount /tmp on another partition. Only replace LVM parts i.e. VG, and LV stuff with an equivalent partition creation procedure.
Make sure you have a valid backup of the server before proceeding.
How to move /tmp as new mount point with downtime
/tmp is used by many processes on the server to open up temp files during execution. So this directory is always in use and rebooting in single-user mode to perform a such activity is the safest and clean way. You can check processes using /tmp by lsof command.
The complete procedure can be done in the below order –
- Prepare a new disk for /tmp
- Create LV on new disk (pvcreate, lvcreate)
- pvcreate /dev/sdb
 - vgcreate vg_tmp /dev/sdb
 - lvcreate -l 100%FREE -n lv_tmp vg_tmp
 
 - Format LV with the filesystem of your choice
- mkfs.ext4 /dev/vg_tmp/lv_tmp
 
 - Mount it on a temporary mount 
- mount /dev/vg_tmp/lv_tmp /mnt
 
 
 - Create LV on new disk (pvcreate, lvcreate)
 - Copy data from /tmp directory to the new disk
- cp -pr /tmp/* /mnt
 - ls -lrt /mnt
 - ls -lrt /tmp
 
 - Reboot server into single-user mode
 - Prepare new /tmp mount point
- Delete/move existing /tmp directory depending on space availability in / 
- rm -rf /tmp OR
 - mv /tmp /tmp.orig
 
 - Create new /tmp for the mount point
- mkdir /tmp
 
 - Set permission and ownership
- chmod 1777 /tmp
 - chown root:root /tmp
 
 - Add entry in /etc/fstab
- echo “/dev/vg_tmp/lv_tmp /tmp defaults 1 2″>>/etc/fstab
 
 
 - Delete/move existing /tmp directory depending on space availability in / 
 - Reboot the server normally.
 - Log in and check /tmp is mounted as the separate mount point.
 
Setting up permission 1777 is an important step in this. Otherwise /tmp will not function as it is expected to.