Here is the documentation for using device-mapper linear: https://www.kernel.org/doc/Documentation/device-mapper/linear.txt

I am trying to understand this documentation. It says it takes 2 parameters: dev path and offset. Yet all the examples I find show other stuff both in front of and after linear. You can see examples in the documentation and here: http://pig.made-it.com/devicemapper.html

Here is an example from that last link:

echo 0 $(blockdev --getsize /dev/loop1) linear /dev/loop1 0 > /tmp/onedisk SIZE1=$(blockdev --getsize /dev/loop1) SIZE2=$(blockdev --getsize /dev/loop2) echo ${SIZE1} ${SIZE2} linear /dev/loop2 0 >> /tmp/onedisk dmsetup create twoasone /tmp/onedisk

As far as I can tell, the first line is taking the output of some stuff and putting it into /tmp/onedisk. Why is there stuff in front of linear, and what does it do?

Ok, I have been looking at this a for a while now. My guess is that this is basically three parameters to echo.

  1. 0
  2. $(blockdev --getsize /dev/loop1)
  3. linear /dev/loop1 0

The output of echo is then stored in /tmp/onedisk. The contends of tmp/ondisk eventually become a parameter for dmsetup create. Is that correct, and am I correct in thinking that really I need to be looking at the documentation for dmsetup create if I want to understand why a 0 and size are being stored at the beginning of /tmp/onedisk?

1 Answer 1


In the first line from the above example, linear is never actually run. This is all just being echoed out into /tmp/onedisk. I know this because the output for tmp/onedisk is very similar to

0 2048 linear /dev/loop0 0

linear does not get used until the last line. The last line runs dmsetup with the create command. twoasone is the device name passed to the create command. /tmp/onedisk is also passed to the create command as containing the table format. So linear is actually a table format option. You can see more information about it from the dmsetup manual by running man dmsetup. Look for "linear" under the "TABLE FORMAT" section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.