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.
midnite
  • 423

1 Answers1

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.