• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Linux Unmounting a file system: unmount

dEEpEst

☣☣ In The Depths ☣☣
Staff member
Administrator
Super Moderator
Hacker
Specter
Crawler
Shadow
Joined
Mar 29, 2018
Messages
13,861
Solutions
4
Reputation
32
Reaction score
45,552
Points
1,813
Credits
55,350
‎7 Years of Service‎
 
56%
Unmounting a file system: unmount

When you stop working with a disk, to completely close access to it and avoid data corruption, you should unmount it. For this purpose, there is a utility called umount .

As an example, let's take a USB drive that has data backups loaded onto it. It should be unmounted before disconnecting it from the computer.

First, let's look at the full list of available disks:


Bash:
$ sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL

Bash:
loop0 4K /snap/bare/5
sda 104G
├─sda1 vfat 1G /boot/efi
├─sda2 ext4 2G /boot
...
sdb 500g
├─sdb1 ntfs 500G /media/root-user/C2D8...


The 500GB USB drive is labeled 'sdb1' . To unmount it, run the command:

Bash:
$ sudo unmount /dev/sdb1

As a result, the disk will be disconnected. You can see that it has disappeared from the list of available devices in the file manager.

If the disk is currently busy, an error will occur. Using the ’ -l ’ option, you can unmount it when it is free:

Code:
$ sudo unmount -l /dev/sdb1

To force a shutdown, you can use the ’-f’ flag. All ongoing operations will be interrupted immediately, and you won't have to wait for anything:

Bash:
$ sudo umount -f /dev/sdb1

Unmount all devices

The ’-a’ option is responsible for unmounting all file systems. There are several sections with exceptions: ’roc’ , ’devfs’ , ’devpts’ , ’sysfs’ , ’rpc_pipefs’ and ’nfsd’ . It should be run with caution:

Bash:
$ sudo unmount -a

Before executing the command, you can see which devices will be affected. The ’--fake’ and ’-v’ options are useful for displaying detailed information:

Bash:
$ sudo unmount --fake -v -a

/run/user/1000/doc: successfully unmounted
/snap/firefox/6015: successfully unmounted
...


This will display a complete list of paths and devices that will be unmounted.

Unmount path

If you want to disable a specific path from the root FS, the approach is different.

As an example, let's take the directory ’/run/lock/tmpfs’. The command to unmount it will look like this:

Bash:
$ sudo unmount /run/lock/tmpfs

Recursive unmount

To recursively unmount a specific directory, add the ’-R’ option to the command described above:

Bash:
$ sudo umount -R /run/lock/tmpfs

If you want to get additional information during recursive unmounting, use the " -v " option:

Bash:
$ sudo umount -R -v /run/lock/tmpfs
 
Back
Top