My system has a USB, an sd card and an SSD connected. I mounted all the devices USB(/dev/sdb1), SSD(/dev/sda1) and sd card(/dev/mmcblk1p1) under /mnt. Is there any way to unmount all the devices connected at /mnt?
(I can do this by performing grep to lsblk/df/mount output and unmounting individual one but I am looking for another easy solution OR by performing 3 times umount /mnt)
Update 2
Here is output of lsblk(multiple mountpoints)
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
└─sda1 8:1 0 232.9G 0 part /mnt
sdb 8:16 1 14.7G 0 disk
└─sdb1 8:17 1 14.7G 0 part /mntand after performing recursive umount
sudo umount --recursive /mnt
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
└─sda1 8:1 0 232.9G 0 part /mnt
sdb 8:16 1 14.7G 0 disk
└─sdb1 8:17 1 14.7G 0 part 5 4 Answers
This one-liner works for me:
while [[ $(findmnt /mnt) != "" ]]; do sudo umount /mnt; doneExplanation:
If the command findmnt /mnt produces non-empty output, something is mounted under /mnt. The test checks if the output is empty or not and if the output is not empty, we run umount /mnt once. If findmnt /mnt produces empty output, nothing is mounted under /mnt anymore and we are done.
If you run as root you can remove sudo from the line. If you run as normal user, you need sudo for the umount-command, but you need to enter your password only once.
-A, --all-targets Unmount all mountpoints in the current namespace for the specified filesystem. The filesystem can be specified by one of the mountpoints or the device name (or UUID, etc.). When this option is used together with --recursive, then all nested mounts within the filesystem are recursively unmounted. This option is only supported on systems where /etc/mtab is a symlink to /proc/mounts.Is that maybe what you want? From man 8 umount.
You can umount the device itself, wildcards allowed.
umount /dev/sda1 /dev/sdb? /dev/sdc* 1 Try with lazy unmount:
sudo umount -l /mnt 7