Let's consider these conditions:
- There's multiple nested mounts with a lot of folders/files in
/mnt
:sdb 8:16 0 300G 0 disk ├─sdb1 8:17 0 256M 0 part /mnt/1/1 ├─sdb2 8:18 0 199.7G 0 part /mnt/2 └─sdb3 8:19 0 100G 0 part /mnt/3/1/2
- Let's pretend I don't know which device(s) (such as
/dev/sdb
) are mounted under/mnt
(as I'd like to use this in a unattended script). - The path to mounted directories aren't known either.
not mounted
error shouldn't stop the process
Here's what I've tried with illustration of the result:
$ umount --all-targets --recursive /mnt; lsblk /dev/sdb
umount: /mnt: not mounted
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 300G 0 disk
├─sdb1 8:17 0 256M 0 part /mnt/1/1
├─sdb2 8:18 0 199.7G 0 part /mnt/2
└─sdb3 8:19 0 100G 0 part /mnt/3/1/2
$ umount --all-targets --recursive /mnt/*/**; lsblk /dev/sdb
umount: /mnt/2/boot: not mounted
umount: /mnt/2/ostree: not mounted
umount: /mnt/3/1: not mounted
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 300G 0 disk
├─sdb1 8:17 0 256M 0 part
├─sdb2 8:18 0 199.7G 0 part /mnt/2
└─sdb3 8:19 0 100G 0 part /mnt/3/1/2
$ umount --all-targets --recursive /mnt/*?; lsblk /dev/sdb
umount: /mnt/1: not mounted
umount: /mnt/3: not mounted
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 300G 0 disk
├─sdb1 8:17 0 256M 0 part /mnt/1/1
├─sdb2 8:18 0 199.7G 0 part
└─sdb3 8:19 0 100G 0 part /mnt/3/1/2
$ umount --all-targets --recursive /mnt/*/**?; lsblk /dev/sdb
umount: /mnt/2/boot: not mounted
umount: /mnt/2/ostree: not mounted
umount: /mnt/3/1: not mounted
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 0 300G 0 disk
├─sdb1 8:17 0 256M 0 part
├─sdb2 8:18 0 199.7G 0 part /mnt/2
└─sdb3 8:19 0 100G 0 part /mnt/3/1/2
Is there any good way of doing this without installing any extra packages?