• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to move /var on a separate disk as a separate mount point (Online)

by admin

By default when you install any Linux system, the /var directory is created automatically under the root partition(‘/’). In some situations, you might want to separate out the /var directory on a different mount point or partition altogether. Especially when you want to manage it independently and have a large amount of data to be stored under /var.

I have seen cases where users dump a lot of data under /var directory causing the root filesystem to become full and hampering many important functionalities of the system. When the /var is on a separate mount point, this issue may never arise at all. This post explains step by step procedure to move /var out of the root filesystem on a separate mount point.

Note: Please note that the below given procedure is online. But Make sure you have take a valida backup of the root filesystem, just be sure in case of any failures.

1. View the available space in the existing VGs and disks. In case of space is not available on the existent volume group, add a new disk or new partition. You may use the below commands to view the available space and disks present on the system.

# vgdisplay  
# fdisk -l

2. Initiatilize a new disk or a partition ona disk to be used by LVM to create new mount point. In our example we are using partition on sdc disk.

# pvcreate /dev/sdc1

3. Create a new volume group using this partition:

# vgcreate var_vg /dev/sdc1

4. Verify the free space available in the newly created volume group var_vg:

# vgdisplay var_vg

5. Create a new logical volume (var_lv) on this volume group. In my case I have 20GB free space in the VG. You may adjust the size as per your VG free space availability.

# lvcreate -L 20G -n var_lv var_vg

6. Create the filesystem for /var.

# mkfs.ext4 /dev/vg_var/lv_var

7. Backup the /var/ directory contents to a backup directory.

# mkdir /var_bkp
# rsync -avz /var/ /var_bkp

8. Mount the newly create /var filesystem:

# mount /dev/var_vg/var_lv /var/

At this point, you will not find any data present in /var mount point or directory.

9. Copy all the contents from backup directory to the newly mounted /var.

# rsync -avz /var_bkp/ /var/

Making Changes Persistent

Lets make the above changes to persist across reboots. For this we need to have a filesystem entry in the /etc/fstab file.

1. First, find the UUID for the var_lv logical volume with the below command:

# blkid

2. Make and entry as shown below using the UUID from the above command.

# cat /etc/fstab
UUID=[UUID-for-var_lv]   /var   ext4   defaults 0 0

replace the [UUID-for-var_lv] with the actual UUID from blkid command we just fired above.

3. You can umount the /var now and try mounting it with “mount -a” command to verify if the entry we just made in /etc/fstab is correct.

# umount /var
# mount -a     ### (or mount /var)

4. Also make sure to set the permissions of new /var/tmp to 1777 if not already set. This is required to set sticky bit on the /var mount point.

# chmod 1777 /var/tmp

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to use perf tool for tracing similar to dtrace
  2. How to effectively use Man Pages under Linux
  3. LVM and multipathing – sample LVM filter strings
  4. How to install git on ubuntu 16.04
  5. Auditd Messages Are Filling Up /var/log/messages
  6. How to change hostname in CentOS/RHEL 7
  7. CentOS / RHEL : How to set chroot jail for vsftp for all the users
  8. CentOS / RHEL 7 : How to set default target (default runlevel)
  9. How to split iso or file using ‘split’ command in Linux
  10. “userdel: user xxx is currently used by process yyy” – Unable to delete an User

You May Also Like

Primary Sidebar

Recent Posts

  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found
  • macof: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright