4

For example, I would like to setup mydata.img to /dev/loop5, I would expect using the command below. However it gives the error losetp: unexpected arguments.

losetup --show -Pvf /dev/loop5 mydata.img

(-v is optional, just for more verbose output. -P is not a main concern in this question too. It forces partition scan. --show is also optional. It shows the assigned loop device.)

In particular, the simpler command below gives the same losetp: unexpected arguments error.

losetup -f /dev/loop5 mydata.img

I think I am following the syntax below. But why -f does not setup mydata.img to /dev/loop5? I know losetup -f will find the first unused loop device. But is it possible to assign another loopdev instead of the first unused found? In particular, there is a loopdev argument in the syntax below. How should we interpret it?

man losetup

Set up a loop device:

   losetup [-o offset] [--sizelimit size] [--sector-size size] [-Pr]
   [--show] -f loopdev file

...

-f, --find [file]
       Find the first unused loop device. If a file argument is
       present, use the found device as loop device. Otherwise, just
       print its name.

1 Answer 1

4

If you want to select which loop device will be used, you need to use this syntax

losetup /dev/loopX mydata.img

The man page is a little bit confusing, but technically correct, because it shows

losetup ... [-Pr] [--show] -f|loopdev file

and if you check what | means in man man it says:

options delimited by | cannot be used together.

so you can use either losetup -f (optionally with file argument) or losetup <loopdev> <file>. So -f in the command replaces the loop device positional argument in this case.

Edit: As pointed in the comments, the | was lost between util-linux 2.36 and the latest 2.37 so now the man page is not correct.

4
  • "The man page is a little bit confusing, but technically correct" – Well, the man page in Debian or so is technically correct. The online man page the OP links to is exactly as the OP cites, -f loopdev is there. This particular manual seems wrong. Commented Jan 6, 2022 at 7:02
  • 1
    The pipe was lost when the losetup manual page was converted to Asciidoc. Commented Jan 6, 2022 at 7:09
  • 2
    Thanks, I checked only my local losetup manpage and I'm still on 2.36. I've created a PR for util-linux to add the pipe back. Commented Jan 6, 2022 at 8:24
  • 2
    Heh, I didn’t realise that GH PRs were accepted, I submitted a patch too ;-). Yours is merged now, so the problem is fixed! Commented Jan 6, 2022 at 10:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.