0% found this document useful (0 votes)
18 views2 pages

How To Move VAR

This document provides instructions for moving the /var directory to a separate mount point on Linux. It involves using LVM to create a new volume group and logical volume, formatting it, backing up and copying over the existing /var contents, and updating /etc/fstab to mount the new /var partition permanently across reboots. Key steps include initializing a new disk partition for LVM, creating a volume group and logical volume, formatting it, mounting it at /var, and making the change persistent by adding an entry to /etc/fstab.

Uploaded by

Perico Martinez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

How To Move VAR

This document provides instructions for moving the /var directory to a separate mount point on Linux. It involves using LVM to create a new volume group and logical volume, formatting it, backing up and copying over the existing /var contents, and updating /etc/fstab to mount the new /var partition permanently across reboots. Key steps include initializing a new disk partition for LVM, creating a volume group and logical volume, formatting it, mounting it at /var, and making the change persistent by adding an entry to /etc/fstab.

Uploaded by

Perico Martinez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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

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.

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/var_vg/var_lv

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

You might also like