mount Command: Mounting Disks and Image Files, Unmounting with umount, and Fixing target is busy
The mount command is a Linux command that attaches the file system of a disk partition or an image file to a directory, and umount is used to detach it. On an AlmaLinux 9 test server, a partition of a practice image was mounted, switched to read-only and unmounted, and the target is busy error that appeared while unmounting was solved by finding the process in use with fuser.
The output below is exactly the result of running the commands under the root account of an AlmaLinux 9 test server with a 2 GiB image created by truncate and attached to the loop device /dev/loop0. mount is version util-linux 2.37.4. Partition 1 of the image was formatted as ext4 and partition 2 as xfs. The /mnt/data, /mnt/backup and /mnt/x directories used as mount points were created first with mkdir. The connection address shown in the simulator is an example value.
1️⃣ Basic Usage of the mount Command
mount is run with the device and the mount point written in that order. Before mounting, the partitions and file system types of the practice device were checked first with lsblk.
lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINTS /dev/loop0NAME FSTYPE LABEL MOUNTPOINTS
loop0
|-loop0p1 ext4 data
`-loop0p2 xfs backup loop0p1 was ext4 and loop0p2 was xfs, and the MOUNTPOINTS column was empty, so neither partition was mounted. Partition 1 was mounted on /mnt/data.
mount /dev/loop0p1 /mnt/dataWhen mounting succeeds, nothing is printed. The result was checked by passing the mount point to findmnt.
findmnt /mnt/dataTARGET SOURCE FSTYPE OPTIONS
/mnt/data /dev/loop0p1 ext4 rw,relatime,seclabelThe SOURCE column showed the device, the FSTYPE column the file system type, and the OPTIONS column the mount options. Since no options were given, it was mounted as rw, which allows both reading and writing. The capacity was checked with [df -h].
df -h /mnt/dataFilesystem Size Used Avail Use% Mounted on
/dev/loop0p1 974M 24K 907M 1% /mnt/dataThe 1 GiB partition was attached to /mnt/data with a size of 974M. Because it was a newly created ext4 file system, ls showed only the lost+found directory.
ls /mnt/datalost+foundRunning mount without arguments lists every file system that is currently mounted. On this server it printed 26 lines, so grep was used to print only the /mnt/data line.
mount | wc -l26mount | grep /mnt/data/dev/loop0p1 on /mnt/data type ext4 (rw,relatime,seclabel)Each line shows the device, mount point, type and options in that order. Giving only a type to -t without a device lists only the lines mounted with that type.
mount -t ext4/dev/vda2 on / type ext4 (rw,relatime,seclabel)
/dev/loop0p1 on /mnt/data type ext4 (rw,relatime,seclabel)Two lines appeared: /dev/vda2 for the root (/) and /dev/loop0p1, which had just been mounted.
Adding -t when mounting specifies the file system type. Partition 2, formatted as xfs, was mounted on /mnt/backup with [-t xfs].
mount -t xfs /dev/loop0p2 /mnt/backupfindmnt /mnt/backupTARGET SOURCE FSTYPE OPTIONS
/mnt/backup /dev/loop0p2 xfs rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquotaThe FSTYPE column showed xfs. When -t is omitted, mount detects the file system type automatically. After unmounting the same partition and running the command again without -t, it was also mounted without errors.
umount /mnt/backupmount /dev/loop0p2 /mnt/backupFile systems to be mounted automatically at boot are written in /etc/fstab. To add a line to fstab, see Linux disk mount for the full process.
2️⃣ mount Options: Read-Only and remount
After -o, mount options are written one after another, separated by commas. ro is the read-only option, used when opening a file system whose contents must not be changed. /mnt/data was unmounted and then mounted again with [-o ro].
umount /mnt/datamount -o ro /dev/loop0p1 /mnt/datafindmnt -o TARGET,OPTIONS /mnt/dataTARGET OPTIONS
/mnt/data ro,relatime,seclabelThe first value in the OPTIONS column changed from rw to ro. In this state, creating a file with touch produced an error.
touch /mnt/data/test.txttouch: cannot touch '/mnt/data/test.txt': Read-only file systemA [Read-only file system] error appeared and the exit code was 1. If writing is needed, only the options can be changed with [-o remount,rw] without unmounting. For remount, only the mount point was given, without the device.
mount -o remount,rw /mnt/datatouch /mnt/data/test.txtfindmnt -o TARGET,OPTIONS /mnt/dataTARGET OPTIONS
/mnt/data rw,relatime,seclabelThe same touch finished without errors, and the OPTIONS column was back to rw.
3️⃣ The umount Command and target is busy
To unmount, give the mount point to umount. /mnt/backup was unmounted.
umount /mnt/backupWhen unmounting succeeds, nothing is printed, just as with mount. If a process is using that file system, it cannot be unmounted. umount was run while a sleep process whose working directory was /mnt/data had been left running in the background.
umount /mnt/dataumount: /mnt/data: target is busy.A [target is busy] error appeared and the exit code was 32. The process in use was checked with [fuser -vm].
fuser -vm /mnt/data USER PID ACCESS COMMAND
/mnt/data: root kernel mount /mnt/data
root 6444 ..c.. sleepThe kernel line is the mount itself, and the line below it is the process in use. A sleep process with PID 6444 appeared. The same information was checked with lsof.
lsof +f -- /mnt/dataCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sleep 6444 root cwd DIR 259,2 4096 2 /mnt/dataThe FD column showed cwd, confirming that the working directory of this process was /mnt/data. After the process was terminated, umount was run again.
kill 6444umount /mnt/dataThis time it finished without errors, and [findmnt /mnt/data] printed nothing, confirming that it had been unmounted.
The option that unmounts without terminating the process is [umount -l]. The manual describes -l as an option that detaches the file system from the directory tree right away and cleans up the remaining references once they are no longer in use. After mounting again and leaving a sleep process running the same way, it was unmounted with -l.
mount /dev/loop0p1 /mnt/dataumount -l /mnt/datalsblk /dev/loop0NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2G 0 loop
|-loop0p1 259:2 0 1G 0 part
`-loop0p2 259:3 0 1023M 0 part [umount -l] finished without errors, and /mnt/data disappeared from the MOUNTPOINTS column of lsblk. The sleep process was still running at that point, so it was terminated with kill.
4️⃣ Image Files and bind Mounts
A disk image file can be mounted directly with [-o loop]. A 200 MiB file was created with truncate and formatted with mkfs.ext4. mkfs.ext4 is the command that creates an ext4 file system. -F was added so that it creates one even on a regular file that is not a partition, and -q so that it does not print progress.
truncate -s 200M /root/lab/fs.imgmkfs.ext4 -q -F /root/lab/fs.imgmount -o loop /root/lab/fs.img /mnt/xfindmnt /mnt/xTARGET SOURCE FSTYPE OPTIONS
/mnt/x /dev/loop1 ext4 rw,relatime,seclabelThe SOURCE column showed /dev/loop1, not the image file. This is because mount attached the image file to a free loop device and then mounted that device. Unmounting with umount also detached the loop device, so only /dev/loop0, which had been there from the start, remained in the losetup list.
umount /mnt/x--bind attaches a directory, not a device, to another path once more. The /root/lab directory was attached to /mnt/x.
mount --bind /root/lab /mnt/xfindmnt /mnt/xTARGET SOURCE FSTYPE OPTIONS
/mnt/x /dev/vda2[/root/lab] ext4 rw,relatime,seclabelThe SOURCE column showed the device of the original file system, /dev/vda2, followed by the attached directory /root/lab in square brackets. /mnt/x was checked with ls.
ls /mnt/xdisk.img
fs.imgdisk.img and fs.img from /root/lab appeared as they were.
umount /mnt/xA path attached with --bind was also detached with umount, like any other mount.
🔲 mount Command Options
| Option | Copy | Description |
|---|---|---|
| -t--types | Mount with the given file system type. Without a device, list only the mounts of that type | |
| -o ro | Mount read-only | |
| -o remount,rw | Switch a mounted file system to read-write without unmounting it | |
| -o loop | Attach an image file to a loop device and mount it | |
| -o loop,ro | Mount an image file read-only | |
| --bind-B | Attach a directory to another path once more | |
| umount | Unmount by giving the mount point or device name | |
| umount -l--lazy | Detach from the directory tree right away and clean up when no longer in use |
| Option | Copy | Description |
|---|---|---|
| -a--all | Mount all file systems listed in fstab | |
| -r--read-only | Mount read-only (same as -o ro) | |
| -w--rw | Mount read-write (default) | |
| -L--label | Specify the device by file system label | |
| -U--uuid | Specify the device by file system UUID | |
| -v--verbose | Print progress details | |
| -f--fake | Test run without actually mounting | |
| -T--fstab | Specify a file to use instead of /etc/fstab | |
| -R--rbind | Attach a directory, including the mounts below it, to another path | |
| -M--move | Move a mounted directory to another path | |
| umount -a--all | Unmount all file systems | |
| umount -f--force | Force unmount (for unreachable NFS) | |
| umount -R--recursive | Unmount the mount point and the mounts below it in order | |
| umount -d--detach-loop | When a loop device was mounted, detach that loop device as well | |
| umount -r--read-only | If unmounting fails, remount read-only | |
| umount -q--quiet | Do not print not mounted error messages |
🔲 mount Command Simulator
In the simulator below, the mount and umount commands from this article can be entered with the chips or the keyboard. Moving with [cd /mnt/data] and then running umount lets you see the [target is busy] error as well.
5️⃣ Practical Examples of the mount Command
This section shows the results of creating a new practice image on the same test server, and the same steps can be entered in the mount command simulator.
🔲 mount Read-Only Mount Example
When copying files from a backup partition, it was mounted read-only so that its contents could not be changed by mistake. First, the xfs partition was mounted, a configuration file app.conf was created on it, and it was unmounted.
mount /dev/loop0p2 /mnt/backuptouch /mnt/backup/app.confumount /mnt/backupThe same partition was mounted with [-o ro], and the options were checked with findmnt.
mount -o ro /dev/loop0p2 /mnt/backupfindmnt -o TARGET,SOURCE,OPTIONS /mnt/backupTARGET SOURCE OPTIONS
/mnt/backup /dev/loop0p2 ro,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquotaThe OPTIONS column starts with ro. In this state, the file list was checked and app.conf was copied to /root/lab with cp.
ls /mnt/backupapp.confcp /mnt/backup/app.conf /root/lab/ls /root/labapp.conf
disk.imgThe copy finished without errors. Trying to delete the same file with rm produced an error.
rm /mnt/backup/app.confrm: cannot remove '/mnt/backup/app.conf': Read-only file systemA [Read-only file system] error appeared and the file was not deleted. After the work was done, it was unmounted with umount.
umount /mnt/backupAn image file becomes read-only when mounted with the options joined by a comma, as in [-o loop,ro]. A new 200 MiB image fs.img was created with truncate and mkfs.ext4, mounted on /mnt/x, and checked with findmnt and losetup.
mount -o loop,ro /root/lab/fs.img /mnt/xfindmnt -o TARGET,SOURCE,FSTYPE,OPTIONS /mnt/xTARGET SOURCE FSTYPE OPTIONS
/mnt/x /dev/loop1 ext4 ro,relatime,seclabellosetup -l -O NAME,RO,BACK-FILENAME RO BACK-FILE
/dev/loop1 1 /root/lab/fs.img
/dev/loop0 0 /root/lab/disk.imgThe OPTIONS column of findmnt was ro, and in the RO column of losetup, only /dev/loop1, to which fs.img was attached, showed 1. After unmounting with umount, losetup was run again.
umount /mnt/xlosetup -l -O NAME,RO,BACK-FILENAME RO BACK-FILE
/dev/loop0 0 /root/lab/disk.imgThe /dev/loop1 line disappeared and only /dev/loop0 remained.
🔲 Common Mistakes When Using mount
A mistake that is easy to make at first is giving a directory that has not been created as the mount point. It was run with /mnt/nodir, a directory that does not exist.
mount /dev/loop0p1 /mnt/nodirmount: /mnt/nodir: mount point does not exist.A [mount point does not exist.] error appeared. mount does not create the mount point, so the directory must be created first with mkdir.
The mistake of giving the whole disk instead of a partition was also checked. The file system is on the partition /dev/loop0p1, but /dev/loop0 was given.
mount /dev/loop0 /mnt/datamount: /mnt/data: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.A [wrong fs type, bad option, bad superblock] error appeared. Giving -t a type different from the actual one also produced the same error. This is the result of specifying [-t ext4] for an xfs partition.
mount -t ext4 /dev/loop0p2 /mnt/xmount: /mnt/x: wrong fs type, bad option, bad superblock on /dev/loop0p2, missing codepage or helper program, or other error.When this error appears, first check the device name (NAME column) and the file system type (FSTYPE column) in lsblk. For a new disk with no partitions, create partitions with the gdisk command, then create a file system with mkfs and mount it.
Mounting an already mounted device on the same mount point again produced an [already mounted] error.
mount /dev/loop0p1 /mnt/datamount: /mnt/data: /dev/loop0p1 already mounted on /mnt/data.Running umount once more on a mount point that had already been unmounted produced a [not mounted] error.
umount /mnt/dataumount: /mnt/data: not mounted.Another mistake is running umount from inside the mount point. [umount /mnt/data] was run while the current directory of the shell was /mnt/data.
pwd/mnt/dataumount /mnt/dataumount: /mnt/data: target is busy.Because the shell was using the mount point, a [target is busy] error appeared. You need to move outside the mount point with cd and run it again. All the mount and umount errors in this section had exit code 32.
🔲 Checking the Change in mount Output
mount and umount print nothing even when they succeed, so the result was checked by comparing the output of findmnt and df before and after running them. Before mounting, [findmnt /mnt/data] printed nothing and the exit code was 1. Passing the same path to df showed the root file system.
df --output=source,fstype,target /mnt/dataFilesystem Type Mounted on
/dev/vda2 ext4 /This means /mnt/data was still a regular directory on the root (/) file system. Files saved in this state are written to the root disk, not to the practice partition. After mounting partition 1, the same commands were run.
df --output=source,fstype,target /mnt/dataFilesystem Type Mounted on
/dev/loop0p1 ext4 /mnt/dataThe Filesystem column changed from /dev/vda2 to /dev/loop0p1, and the Mounted on column from / to /mnt/data. In lsblk as well, /mnt/data appeared in the MOUNTPOINTS column of the loop0p1 line.
lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINTS /dev/loop0NAME FSTYPE LABEL MOUNTPOINTS
loop0
|-loop0p1 ext4 data /mnt/data
`-loop0p2 xfs backup In a script, the exit code can be checked instead of the output. The exit code of findmnt was 0 when mounted and 1 when not mounted.
🔢 FAQ & Recommended Content
Linux · Disk
Linux blkid Command | UUID vs GUID
How to use the blkid command to check the file system type and UUID of block devices.
Linux · Disk
Swap Memory setup: 2 methods, partition & file | swapon, mkswap commands
How to create swap, which uses disk space like memory, in two ways, as a partition and as a file, and enable it with mkswap and swapon.
ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.