无法删除设备 /dev/loop0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5881134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 00:48:07  来源:igfitidea点击:

Cannot delete device /dev/loop0

linuxubuntumount

提问by BiX

I unsafely removed a USB device that was attached to loop0 with losetupand could not delete nor detach loop0 afterwards.

我不安全地移除了一个连接到 loop0 的 USB 设备,losetup之后无法删除或分离 loop0。

losetup -ashows /dev/loop0: [0005]:145606719 (/dev/sdb1)

losetup -a显示 /dev/loop0: [0005]:145606719 (/dev/sdb1)

When I remount the device to /dev/sdb1, umountit and try losetup -d /dev/loop0, I will still get the same error loop: can't delete device /dev/loop0: Device or resource busy. Is there a way to get rid of the loop device?

当我将设备重新安装到 /dev/sdb1umount并尝试时losetup -d /dev/loop0,我仍然会遇到相同的错误loop: can't delete device /dev/loop0: Device or resource busy。有没有办法摆脱循环设备?

采纳答案by The Bndr

Are you sure that the device isn't busy? Have you ever tried fuser to determine an possible PID?

您确定设备不忙吗?您是否曾尝试过 fuser 来确定可能的 PID?

Precautionary get all possible information:

预防性获取所有可能的信息:

fuser -c /dev/loop0
fuser -d /dev/loop0
fuser -f /dev/loop0

Try to stop the process, which could use /dev/loop0. If necessary use kill -9or try fuser -kto send the kill signal -> look at man fuser.

尝试停止可能使用 /dev/loop0 的进程。如有必要,请使用kill -9或尝试fuser -k发送终止信号 -> 查看man fuser.

回答by tamasd

Try reloading the loop kernel module. If it does not help then reboot.

尝试重新加载循环内核模块。如果它没有帮助,则重新启动。

回答by Aaron Flin

You may have to also use dmsetupto remove the device mapping. Easiest way, if it doesn't interfere with any other mappings is to use a dmsetup remove_all.

您可能还必须使用dmsetup删除设备映射。最简单的方法,如果它不干扰任何其他映射是使用dmsetup remove_all.

回答by Mike.P

I had a similar issue with an SD card and Aaoron Flin's suggestion to use dmsetup worked for me.

我在 SD 卡上遇到了类似的问题,Aaoron Flin 建议使用 dmsetup 对我有用。

Specifically, you should be able to ls/dev/mapper to see if any loop0pXpartitions exist.

具体来说,您应该能够ls/dev/mapper 查看是否loop0pX存在任何分区。

If so, you can use dmsetup remove /dev/mapper/loop0p2to get rid of any unnecessary partitions. This can be useful if you want to keep some mappings attached.

如果是这样,您可以使用dmsetup remove /dev/mapper/loop0p2删除任何不必要的分区。如果您想保留一些映射,这会很有用。

回答by choad rocker

If you're using Luks, you need to luksClose first

如果你使用 Luks,你需要先 luksClose

cryptsetup luksClose $whatever
losetup -D

回答by user3578181

Definitely there is a process using it. If you couldn't determine which process is preventing it from deleting, then restart your server if you can.

肯定有一个使用它的过程。如果您无法确定哪个进程阻止它删除,请尽可能重新启动服务器。

回答by frntn

I had the same issue today and none of the previous answers fixed it (I didn't try to reload the loop kernel module, because I wanted to understand the actual issue).

我今天遇到了同样的问题,之前的答案都没有解决它(我没有尝试重新加载循环内核模块,因为我想了解实际问题)。

It turns out the image file associated with the loop device contained an "Linux LVM" partition, which was automatically set as shown by pvscan:

事实证明,与循环设备关联的映像文件包含一个“Linux LVM”分区,该分区已自动设置为如下所示pvscan

$ pvscan
  PV /dev/sda1    VG server-vg   lvm2 [417,76 GiB / 0  free]
  PV /dev/loop0   VG vbox-vg     lvm2 [7,81 GiB / 0    free]
  Total: 2 [425,57 GiB] / in use: 2 [425,57 GiB] / in no VG: 0 [0   ]

So I had de deactivate all the logical volumes inside the volume group:

所以我已经停用了卷组内的所有逻辑卷:

$ vgchange --activate n vbox-vg
  0 logical volume(s) in volume group "vbox-vg" now active

Eventually I was able to nicely detach the loop device:

最终我能够很好地分离循环设备:

$ losetup -d /dev/loop0
$ losetup -a

回答by MolbOrg

Same as by @frntn.

与@frntn 相同。

Loops were occupied by RAID:

循环被 RAID 占用:

# cat /proc/mdstat

Personalities : [raid0]

md126 : active raid0 loop6p5[1] loop5p3[0]
  209584128 blocks super 1.2 512k chunks

md127 : active raid0 loop6p2[1] loop5p2[0]
  31440896 blocks super 1.2 512k chunks

I removed them and everything obeys the orders again.

我删除了它们,一切都再次服从命令。

回答by Brons0nmarlotcheechdexter

I just right click the loop device in dolphin and unmount it.

我只需右键单击 dolphin 中的循环设备并卸载它。

回答by dwb.kelmark

I chased this loop solution to the end of the Internet and found the solution is uninstall snapdand purge all associatedfiles: (In my case this was 167 Gb)

我将这个循环解决方案追到了互联网的尽头,发现解决方案是卸载snapd清除所有相关文件:(在我的情况下,这是 167 Gb)

sudo apt purge snapd