Last active
September 30, 2022 12:37
-
-
Save waja/c780d4217fd695e4f55f to your computer and use it in GitHub Desktop.
Remove unused loop devices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
for LOOPS in $(losetup -a | awk -F':' {'print $1'} | awk -F'/' {'print $3'}); do | |
for LOOPPART in $(ls /dev/mapper/${LOOPS}*| awk -F'/' {'print $4'}); do | |
dmsetup remove ${LOOPPART}; | |
done; | |
losetup -d /dev/${LOOPS}; | |
done |
The same errors of @tripulse also in my Ubuntu 20.04
sudo losetup --detach-all
works well
Seriously? You guys have an error message and there is written Try 'losetup --help' for more information.
but it's too hard to look into this?
$ /sbin/losetup --help | grep detach
-d, --detach <loopdev>... detach one or more devices
-D, --detach-all detach all used devices
Indeed, the command from @captn3m0 works, but I replaces the losetup --d
by losetup -d
which can be easily spotted in the --help
output.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got a bunch of errors while executing the script through (
/bin/sh
). I copy-pasted from the terminal output.