Util-Linux package development
 help / color / mirror / Atom feed
* `losetup --remove` is confusing, and misuse silently fails
@ 2025-10-10  9:41 Benno Schulenberg
  2025-10-11 10:16 ` Nuno Silva
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Benno Schulenberg @ 2025-10-10  9:41 UTC (permalink / raw)
  To: Util-Linux; +Cc: wguanghao


[-- Attachment #1.1: Type: text/plain, Size: 2520 bytes --]


After setting up a loop device with:

   # ./losetup loop4 some.img

I wanted to see what happens when trying to "remove" it
(since the man page says it is "not recommended"):

   # ./losetup -R loop4

There is no feedback, but it failed:

   # echo $?
   1

When a command fails, shouldn't it print an error message?


Then I tried detaching and removing at the same time:

   # ./losetup -R -d loop4

No feedback, but it didn't do anything:

   # ./losetup loop4
   /dev/loop4: [66306]:5939273 (/home/ben/Sources/util-linux/some.img)

Trying a different order of the options:

   # ./losetup -d -R loop4
   losetup: /dev/-R: detach failed: No such file or directory

Huh?  Why does it try to interpret an option as a loop device name?

   # ./losetup -d loop4 -R
   /home/ben/Sources/util-linux/.libs/losetup: option requires an argument -- 'R'
   Try 'losetup --help' for more information.

   # ./losetup -d loop4 -R loop4

Oh.  Surprisingly, this last invocation worked.

   # ls -l /dev/loop? | grep loop4
   # lsblk -a | grep loop4


However, the loop4 device is not really gone, because one can attach
a file to it again:

   # ./losetup --show loop4 some.img
   /dev/loop4
   # ./losetup -a
   /dev/loop4: [66306]:5939273 (/home/ben/Sources/util-linux/some.img)

When the device is really gone, attaching doesn't work:

   # rm /dev/loop3
   # ./losetup loop3 some.img
   losetup: /dev/loop3: failed to set up loop device: No such file or directory
   losetup: device node /dev/loop3 (7:3) is lost. You may use mknod(1) to 
recover it.

In my opinion --remove is not a good name for the option, as it doesn't
actually remove anything.  Also, its meaning is too similar to "detach":
when the computer asks me to "Remove the USB stick", I detach this stick
from the USB port.

What --remove accomplishes is that it prevents the specified loop device
from getting listed.  So in my opinion a better name for the option would
be: --unlist.

But what is the purpose of --unlist?  Why would one want it?  What harm
is there in listing empty, fallow loop devices?

   # ./lsblk -a | grep loop
   loop0         7:0    0     0B  0 loop
   loop1         7:1    0     0B  0 loop
   loop2         7:2    0     0B  0 loop
   loop3         7:3    0     0B  0 loop
   loop4         7:4    0   400M  0 loop
   loop5         7:5    0     0B  0 loop
   loop6         7:6    0     0B  0 loop
   loop7         7:7    0     0B  0 loop


Benno


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-11-07 11:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-10  9:41 `losetup --remove` is confusing, and misuse silently fails Benno Schulenberg
2025-10-11 10:16 ` Nuno Silva
2025-10-11 12:47   ` [DKIM] " Benno Schulenberg
2025-10-14 10:06 ` Karel Zak
2025-10-16 10:28 ` Karel Zak
2025-10-17  8:37   ` Benno Schulenberg
2025-10-17  8:55   ` Benno Schulenberg
2025-10-21 10:00     ` Karel Zak
2025-10-21 13:49       ` Benno Schulenberg
2025-11-03 12:49         ` Karel Zak
2025-11-03 14:42           ` Benno Schulenberg
2025-11-07 10:16             ` Karel Zak
2025-11-07 11:21               ` Benno Schulenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox