losetup
losetup is a Linux command to set up and control loop devices.
Create a big file for bingding:
$ sudo mkdir -p /srv/ceph-test
$ sudo truncate -s 20G /srv/ceph-test/osd.0.img
20G is the size of the file, but is actually not occupied:
$ ls -lh
total 0
-rw-r--r-- 1 root root 20G Apr 15 14:21 osd.0.img
Bind it to loop deivce:
$ sudo losetup -f /srv/ceph-test/osd.0.img
-f to find an available loop device number.
List all loop devices:
$ losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop0 0 0 0 0 /srv/ceph-test/osd.0.img 0 512
$ losetup -a
/dev/loop0: [64513]:6368 (/srv/ceph-test/osd.0.img)
Unbind the device:
$ losetup -d /dev/loop0
Unbind all loop devices:
$ losetup -D