How to PROPERLY change mount point name in Linux | GoLinuxCloud (2024)

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

Topics we will cover hide

What is mount point in Linux?

Step-1: List Mounted Partitions with Mount Points

Step-2: List processes accessing mount point

Step-4: Change Mount Point Name

Step-5: Update /etc/fstab

Summary

References

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 -hPFilesystem Size Used Avail Use% Mounted ondevtmpfs 712M 0 712M 0% /devtmpfs 732M 0 732M 0% /dev/shmtmpfs 293M 4.3M 289M 2% /run/dev/mapper/rl-root 17G 1.8G 16G 11% //dev/vda1 1014M 166M 849M 17% /boottmpfs 147M 0 147M 0% /run/user/1000/dev/vdb1 20G 2G 18G 10% /backup
ALSO READHow to PROPERLY kill process on Ubuntu? [SOLVED]

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 -lproc 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: 1223cKilled

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.

ALSO READConfigure High Availability Cluster in CentOS 7 (Step by Step Guide)

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 followHow 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 0UUID=76590820-3a66-498d-83ba-73c6ce457531 /boot xfs defaults 0 0/dev/mapper/rl-swap none swap defaults 0 0/dev/vdb1/backupext4defaults00

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

/dev/vdb1/new_backupext4defaults00

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 -hUsage: 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.

ALSO READPROPERLY disable IPv6 in Rocky Linux [SOLVED]

References

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

Views: 519

How to PROPERLY change mount point name in Linux | GoLinuxCloud (2024)

References

Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 5512

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.