How to PROPERLY change mount point name in Linux


Written by - Omer Cakmak
Reviewed by - Deepak Prasad

In this tutorial I will share the steps to properly change mount point name in Linux with best practices.

 

What is mount point in Linux?

A mount point is files to which a new filesystem is attached (i.e. logically mounted) and mounted to a directory on the accessible filesystem. Mount point is an ever-present concept within Linux. As the system itself creates a mount point, there are also mount points created by users.

Mount points created by the system do not change very often. But those created by users are more subject to change.

Note: Changing mount point requires sudo privilege or root user.  You can switch to root user with the following command:

[foc@rocky9 ~]$ sudo -i

Or type sudo at the beginning of the commands you will run in the terminal.

Let's take a look at "How to PROPERLY Change Mount Point Name in Linux".

 

Step-1: List Mounted Partitions with Mount Points

In Linux, mount points are listed in several different ways. Let's show two methods:

 

Method-1: Using df command

List the mount points with their available spaces using df command.

[root@rocky9 foc]# df -hP
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             712M     0  712M   0% /dev
tmpfs                732M     0  732M   0% /dev/shm
tmpfs                293M  4.3M  289M   2% /run
/dev/mapper/rl-root   17G  1.8G   16G  11% /
/dev/vda1           1014M  166M  849M  17% /boot
tmpfs                147M     0  147M   0% /run/user/1000
/dev/vdb1             20G    2G   18G   10% /backup

 

Method-2: Using mount command

We can alternatively also use mount command to list all the mount points on your Linux server.

[root@rocky9 foc]# mount -l
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=728896k,nr_inodes=182224,mode=755,inode64)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime,seclabel)
none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
/dev/mapper/rl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,nosuid,noexec,relatime)
/dev/vda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
/dev/vdb1 on /backup type ext4 (rw,relatime,seclabel)

 

Step-2: List processes accessing mount point

Once you have identified the partition for which you wish to change mount point name, check if any process is utilizing the /backup mount point. You can see which process is using this mount point with the following command:

[root@rocky9 backup]# fuser -cu /backup
/backup:          1223c(root)

To be able to change mount point name name, we must make sure that no process is using the mount point or mounted partition. Here as you can see there is an active process using /backup partition. So either you can manually exit the process or to forcefully kill the process you can use below command.

NOTE:
Please use this command cautiously as this will close any process using the provided partition, causing a risk of loosing data or even corrupting the partition. It is recommended to gracefully stop the application processes.
[root@rocky9 backup]# fuser -k /backup
/backup:          1223c
Killed

 

Step-3: Unmount mount point

Once we know that no other process is using our partition, we can safely unmount the mount point. Anyhow if any process is still using the partition, then umount will fail claiming that the target device is busy.

Use the following commands to unmount the mount point:

[root@rocky9 ~]# umount /dev/vdb1

or

[root@rocky9 ~]# umount /backup

If you get the following error while unmounting, then as explained earlier it is most likely some user is still using this mount point so please make sure to close or terminal any process using the partition:

[root@rocky9 backup]# umount /backup 
umount: /backup: target is busy.

At the end of this stage, you have successfully unmounted the partition but this DOES NOT mean that any of your data on /dev/vdb1 is lost. All your data is still safe and nothing for you to worry about.

 

Step-4: Change Mount Point Name

Use the mkdir command to create the new mount point:

[root@rocky9 ~]# mkdir /new_backup

Then remount the partition to this new mount point:

[root@rocky9 ~]# mount /dev/vdb1 /new_backup

When you list the mount points again, you can see the new directory.

[root@rocky9 ~]# mount -l
/dev/vdb1 on /new_backup type ext4 (rw,relatime,seclabel)

Now you can verify your data to make sure there are no data loss as we have successfully changed the mount point name from /backup to /new_backup.

 

Step-5: Update /etc/fstab

If you wish to auto-mount your partition post reboot then you must also add or update the existing entry of /dev/vdb1 in /etc/fstab with the new mount point or else your Linux server will fail to boot during reboot stage.

NOTE:
In some Linux distributions, fstab has been replaced with systemd-fstab so you can follow How to mount filesystem without fstab using systemd for more information and steps.

Here is my old /etc/fstab file content:

[root@rocky9 ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Sun Jul 17 20:35:50 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rl-root     /                       xfs     defaults        0 0
UUID=76590820-3a66-498d-83ba-73c6ce457531 /boot                   xfs     defaults        0 0
/dev/mapper/rl-swap     none                    swap    defaults        0 0
/dev/vdb1	/backup	ext4	defaults	0	0

 

Open the file with an application like nano or vi and update this line as follows (new_backup instead of backup):

/dev/vdb1	/new_backup	ext4	defaults	0	0

 

Summary

This article was a guide on how to successfully mount a new mount point on your system. For help with commands used in mount point changes:

[root@rocky9 ~]# mount -h

Usage:
 mount [-lhV]
 mount -a [options]
 mount [options] [--source] <source> | [--target] <directory>
 mount [options] <source> <directory>
 mount <operation> <mountpoint> [<target>]

Mount a filesystem.

You can follow the same steps for detailed information about fuser, umount and mkdir commands.

 

References

Stackoverflow - How to change mountpoint name?
Askubuntu -  Mount point name changed

 

Views: 25

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on LinkedIn or check his projects on GitHub page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

2 thoughts on “How to PROPERLY change mount point name in Linux”

Leave a Comment