• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Howto

How to move /tmp on a separate disk as a separate mount point

Published: January 21, 2020 | Modified: August 13, 2022



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

Create /tmp as a new mount point

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 –

  1. Prepare a new disk for /tmp
    1. Create LV on new disk (pvcreate, lvcreate)
      • pvcreate /dev/sdb
      • vgcreate vg_tmp /dev/sdb
      • lvcreate -l 100%FREE -n lv_tmp vg_tmp
    2. Format LV with the filesystem of your choice
      • mkfs.ext4 /dev/vg_tmp/lv_tmp
    3. Mount it on a temporary mount
      • mount /dev/vg_tmp/lv_tmp /mnt
  2. Copy data from /tmp directory to the new disk
    • cp -pr /tmp/* /mnt
    • ls -lrt /mnt
    • ls -lrt /tmp
  3. Reboot server into single-user mode
  4. Prepare new /tmp mount point
    1. Delete/move existing /tmp directory depending on space availability in /
      • rm -rf /tmp OR
      • mv /tmp /tmp.orig
    2. Create new /tmp for the mount point
      • mkdir /tmp
    3. Set permission and ownership
      • chmod 1777 /tmp
      • chown root:root /tmp
    4. Add entry in /etc/fstab
      1. echo “/dev/vg_tmp/lv_tmp /tmp defaults 1 2″>>/etc/fstab
  5. Reboot the server normally.
  6. 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.

⇠ Previous article
Troubleshooting Ansible errors
Next article ⇢
How to configure SFTP with restricted directory access

Related stuff:

  • How to find the process using high memory in Linux
  • Run command on multiple linux servers from windows
  • How to resolve the MFA entity already exists error
  • How to disable GUI in SUSE Linux
  • How to install patch/software in HPUX
  • How to add Cloundfront CDN in WordPress blog with SSL
  • How to change timezone in Linux server (RedHat, CentOS, Ubuntu)
  • How to identify current boot disk in HPUX
  • How to disable direct root login on Linux & HPUX
  • How to disable IPv6 on Linux
  • 4 steps guide for SMTP configuration in HPUX
  • How to find AWS resources that need to be tagged

Filed Under: Howto Tagged With: mount /tmp, move /tmp from /, Reconfigure /tmp, tmp filesystem on new disk

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Comments

  1. Hamza says

    July 26, 2021 at 5:53 pm

    Thank you for your help,I allow myself to add one more thing, you must specify the fielsystem type in 4th step, otherwise after, the reboot, the OS goes straight to emergency mode and event when you delete the line from /etc/fstab, and try to mount it by mount -a it will reply unkown filesystem (ebcause he is taking defaults as a FS type..)
    I tried this on RHAT7.2 3.10.0-327.el7.x86_64

    Reply
  2. Hamza says

    July 26, 2021 at 5:55 pm

    Thank you for your post, it was very helpful

    I allow myself to add one more thing, you must specify the fielsystem type in 4th step, otherwise after, the reboot, the OS goes straight to emergency mode and event when you delete the line from /etc/fstab, and try to mount it by mount -a it will reply unkown filesystem (ebcause he is taking defaults as a FS type..)
    I tried this on RHAT7.2 3.10.0-327.el7.x86_64

    Reply
  3. Ori says

    July 28, 2022 at 12:36 pm

    There is a typo in 3.Set permission and ownership
    chwon -> chown

    Reply
    • Shrikant Lavhate says

      August 13, 2022 at 9:49 am

      Thank you, Ori. Typo is corrected now.

      Reply

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.