76

The way to check is fuser -vm /mnt/dir, which must be run as root. It will tell you which processes are accessing the mount point. An alternative is lsof /mnt/dir, which will show each open file on the mount. Again best run as root. You can run either of these as non-root, but then the output will be limited to your processes—ones from other users will ...


66

If you are using systemd then use udisksctl utility with power-off option: power-off Arranges for the drive to be safely removed and powered off. On the OS side this includes ensuring that no process is using the drive, then requesting that in-flight buffers and caches are committed to stable storage. I would recommend first to unmount all ...


59

The [ command is to evaluate conditional expressions. It's of no use here. Because umount doesn't output anything on its standard output (the errors go to stderr), `sudo umount mount` expands to nothing. So it's like: while [ ] do sleep 0.1 done The [ command, when not passed any argument beside [ and ] returns false (a non-zero exit status), so you ...


20

You should use: sudo umount -l <path>


15

You need to exit the directory to unmount it, like this: #!/bin/bash sudo mount -o loop Sample.iso /tmp/mnt cd /tmp/mnt tar -cvf /tmp/sample.tar * #Got to the old working directory. **NOTE**: OLDPWD is set automatically. cd $OLDPWD #Now we're able to unmount it. sudo umount /tmp/mnt That is it.


14

Execute the below command to force and Detach the filesystem from the filesystem hierarchy, and cleanup all references to the filesystem as soon as it is not busy anymore. umount -lf /mnt/rescue


14

You have to first exit the chroot session, usually a simple exit will do: exit Then umount ALL binded directories: umount /mnt/rescue/dev/ umount /mnt/rescue/proc/ umount /mnt/rescue/sys/ Then: umount /mnt/rescue In case you were worried that sync isn't used here, note that it has no influence on whether unmounting is possible. Unmounting flushes ...


14

umount is perfectly safe for the disk. Once you've done that you have successfully unmounted the filesystem and you needn't worry along those lines. The primary difference between eject and umount doesn't concern the disk at all - rather it is about the USB port's 5v power output. After umount you can still see your disk listed in lsblk because it is still ...


11

This worked for me correctly -- https://unix.stackexchange.com/a/264488/4319: mount --rbind /dev /mnt/test mount --make-rslave /mnt/test umount -R /mnt/test It was important to have the two first commands as two separate commands: do not combine --rbind and --make-rslave in one invocation of mount. Without --make-rslave, the behavior was unwanted (and not ...


11

The device is "busy" since you just used cd to move into it. You can not unmount the partition of the current working directory (of any process, in this case the shell). Your script: sudo mount -o loop Sample.iso /tmp/mnt cd /tmp/mnt tar -cvf /tmp/sample.tar * sudo umount /tmp/mnt Modified script without the same issue: sudo mount -o loop Sample.iso /...


11

A lazy unmount creates a Schrödinger's cat mount You cannot know if the the device is actually unmounted or not The "unmounted" filesystem remains accessible in some circumstances The "unmounted" filesystem is not accessible in some circumstances There is a false sense of security: it appears that the filesystem has been unmounted, but in reality it has ...


10

The credit goes to Gilles for this answer; Gilles noted in the question comments that the '-n' switch ignores the mtab and unmounts anything listed in /proc/mounts. From the manpage: -n Unmount without writing in /etc/mtab. So to answer my question of how to unravel a --rbind mount, this is the full command that worked for me: grep /mnt/chroot/sys /...


10

umount: /home device is busy This means that you (or someone) is currently using files on the /home filesystem. The simplest solution is to have all normal users logout of the system and then log back in as root. (You might need to configure the system to "Allow local system administrator login" in the Login Window application, Security tab.) If umount ...


9

I found the solution myself. I simply just need to use --make-rslave to make any changes in A_dir/mount_b not propagate back to B_dir: sudo mount --make-rslave A_dir/mount_b sudo umount -R A_dir/mount_b See mount man page section The shared subtree operations.


9

You could try fusermount -u somemountpoint. edit: As sshfs makes use of the FUSE (Filesystem in Userspace) kernel module, one should use fusermount to unmount FUSE filesystems, at least in userspace.


8

It seems there's been some mis-information sitting here for a while now. The most likely reason for the umount command having the abbreviated name is because it follows from the name of the system call which it uses: umount(). The probable reason the "unmount" system call having the name umount() is because early linkers limited the length of external ...


7

A mount -t nfs fails with Stale file handle if the server has some stale exports entries for that client. Example scenario: this might happen when the server reboots without the client umounting the nfs volumes first. When the server is back and the client then umounts and tries to mount the nfs volume the server might respond with: mount.nfs: Stale file ...


6

That's to do with the kernel doing a lot of buffering, including buffering writes to your device. If you issue: cp large_file /mnt/htc/ cp will return as soon as it has finished writeing the data, but (for reasonably "slow" devices/connections) well before that data has actually been written. (Unless cp or the tool you use itself issues fsync or similar ...


6

Open files Processes with open files are the usual culprits. Display them: lsof +f -- <mountpoint or device> There is an advantage to using /dev/<device> rather than /mountpoint: a mountpoint will disappear after an umount -l, or it may be hidden by an overlaid mount. fuser can also be used, but to my mind lsof has a more useful output. ...


6

Another volume is mounted on top of a volume we want to unmount : The mount command lets you know all the mounted volumes if invoqued without arguments nor options (except -v). You can have a list of active mountpoints by adding a bit of perl : mount | perl -pe 's/.*on (\S+) type.*/\1/' Then, just grep over the mointpoint from which you wish to unmount ...


6

I found a reliable solution: Just put the script in /usr/lib/systemd/system-shutdown/. See also: https://www.freedesktop.org/software/systemd/man/systemd-halt.service.html Immediately before executing the actual system halt/poweroff/reboot/kexec systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/ and pass one arguments to them: ...


5

reusable function, and will timeout in 'n' seconds _umount() { [[ $# -lt 2 ]] && { echo "Usage: ${FUNCNAME} <timeout_secs> <mnt_point>"; return 1 } timeout=$(($(date +%s) + ${1})) until umount "${2}" 2>/dev/null || [[ $(date +%s) -gt $timeout ]]; do : done } no need to sleep


5

The problem is journald Or rather how it is still logging to /var while systemd is trying to unmount it. Solutions According to this thread, there are two ways to go about it: Make journald log to a volatile location in /run so it doesn't lock /var, but the tradeoff is that you lose logs at shutdown. Edit /etc/systemd/journald.conf to change the Storage=...


5

Yes. The relevant code is in sb_prepare_remount_readonly (as of Linux 4.0, the code may be organized differently on other versions). The logic is: For each instance of the mount: If that instance is not read-only: Prevent any new writer from registering (MNT_WRITE_HOLD). If there are registered writers, set the error flag (return EBUSY). If there are any ...


5

Mounting just means "set up the operating system to actively use the some (part of) a block device". Often there is some "busy" or "dirty" on the superblock that gets changed when a file system is mounted, but otherwise the hardware is unaffected. OTOH, eject sends a SCSI "START STOP" command to the device, with option "eject" set. The USB controller in a ...


5

You want to unmount by label. Invoke umount directly instead of writing a script: sudo umount /dev/disk/by-label/$label


4

If the mount is busy it shouldn't be able to unmount*. An easy way to make a mount busy is to have at least one process with its CWD (Current Working Directory) under the mount point. *Lazy unmounts will still return but it shouldn't actually unmount until the filesystem is no longer busy.


4

The reason why you get the 'target is busy.' message is because the mount point (/mnt/rescue) is open in a file browser or in a terminal session, and also the order of unmounting process (here I mean dev/pts should be umounted before dev/ ) Well, in order to successfully umount all fs there : Make sure the mountpoint isn't open in a file browser! After ...


Only top voted, non community-wiki answers of a minimum length are eligible