You cannot remove /dev/loop0 with rm; detach the loop device instead
Cannot delete device /dev/loop0Short answer
A loop device is a kernel device, not a normal file, so deleting it is the wrong tool. Find what backs it with losetup, unmount any filesystem on it, then detach it with losetup -d. If the unmount says the target is busy, find what is using the mount first.
Fix it fast
1Find out which cause you have
List every loop device with the file that backs it, so you know what you are about to free.
losetup --list2Match what you see, then jump to its fix
- 1
rm or a delete command on /dev/loop0 is refused or has no effectYou are trying to delete it like a fileFix - 2
detach is accepted but the device stays in use, or umount was never runA filesystem is still mounted from the loop deviceFix - 3
umount: target is busyThe unmount fails because the target is busyFix
- 1
What does the error look like?
Cannot delete device /dev/loop0umount: /mnt/image: target is busy.
Cause 1 of 3
You are trying to delete it like a file
1Check
A loop device connects a block device to a backing file. The way to free it is to detach it, not delete the node. Look at which loop devices are attached and to what.
losetup --all2Fix
Detach the device with losetup. This needs root.
sudo losetup --detach /dev/loop03Verify
The device no longer appears with a backing file.
losetup --listConfirmed by man7.org
Cause 2 of 3
A filesystem is still mounted from the loop device
1Check
Find out whether something is mounted from it. The losetup manual shows the order: unmount first, then detach.
grep loop0 /proc/mounts2Fix
Unmount the mount point shown, then detach the device.
sudo umount /dev/loop0
sudo losetup --detach /dev/loop03Verify
No backing file is listed for the device.
losetup --list | grep loop0 || echo detachedConfirmed by man7.org
Cause 3 of 3
The unmount fails because the target is busy
1Check
A filesystem cannot be unmounted while a process has a file open on it, or uses it as a working directory, or an active swap file lives on it. Stop those first.
sudo umount /mnt/image2Fix
Close the program, or cd out of the mount point, then unmount. The -d option also frees the loop device in the same step.
cd ~
sudo umount -d /mnt/image3Verify
The mount point is gone and the loop device is free.
grep /mnt/image /proc/mounts || echo unmounted
losetup --listConfirmed by man7.org
How do I stop it coming back?
- Detach a loop device with losetup -d as soon as you finish with the image.
- Unmount before you detach, in that order.
- Use umount -d when you mounted an image yourself, so the loop device is freed with the unmount.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Servers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix