1

Why is my loop device not 600G in size?

$ fallocate --length 600G sysvol
$ sudo losetup --find sysvol
$ sudo losetup --all 
/dev/loop0: [0831]:13 (/.../sysvol)

$ sudo losetup --set-capacity /dev/loop0
$ sudo stat /dev/loop0
  File: ‘/dev/loop0’
  Size: 0               Blocks: 0          IO Block: 4096   block special file
Device: 5h/5d   Inode: 51          Links: 1     Device type: 7,0
1

stat is not the right tool to investigate block devices.

Here is an example of using --set-capacity:

root@maxim:~# blockdev --getsize64 /dev/loop0
0
root@maxim:~# dd if=/dev/zero of=/tmp/aaa.img count=10 bs=1M
10+0 записей получено
10+0 записей отправлено
скопировано 10485760 байт (10 MB), 0,00709284 c, 1,5 GB/c
root@maxim:~# blockdev --getsize64 /dev/loop0
0
root@maxim:~# losetup --find /tmp/aaa.img 
root@maxim:~# losetup -l
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE
/dev/loop0         0      0         0  0 /tmp/aaa.img
root@maxim:~#
root@maxim:~# blockdev --getsize64 /dev/loop0
10485760
root@maxim:~# dd if=/dev/zero of=/tmp/aaa.img count=10 bs=1M oflag=append conv=notrunc
10+0 записей получено
10+0 записей отправлено
скопировано 10485760 байт (10 MB), 0,00771261 c, 1,4 GB/c
root@maxim:~# blockdev --getsize64 /dev/loop0
10485760
root@maxim:~# losetup --set-capacity /dev/loop0
root@maxim:~# blockdev --getsize64 /dev/loop0
20971520
root@maxim:~# 
  • if I can't change its capacity, what is the --set-capacity loopdev option meant for? It seem to be what I need: "reread size of the file associated with the specified loop device". I can create a loopback filesystem successfully, but I need to operate on a device, not on a filesystem. – Jean Jordaan May 7 '15 at 7:38
  • according to manpage --set-capacity force the loop driver to reread the size of the file associated with the specified loop device. So you should run sudo losetup --set-capacity sysvol instead of losetup --set-capacity /dev/loop0 and if you mount sysvol you should see 600G free space – Maxiko May 7 '15 at 7:57
  • As the manpage says, you specify the loop device, and it looks at the associated file. You can see the associated file with losetup -a: you don't specify the file, losetup knows the association. Giving the file as parameter results in Inappropriate ioctl for device. I see that I'm off track with stat though. It reports 0 size for my other devices like sdb1 as well. I need to operate on the device, not on a filesystem. If I format the device and mount it, the mounted fs has the correct size. But if I try to operate on the device, insufficient size is reported. – Jean Jordaan May 7 '15 at 8:23
  • i've updated answer. I think stat command is misused against block devices. – Maxiko May 7 '15 at 8:44
  • Yes, I also saw that stat is the wrong tool for looking at block devices. Thanks for the detail! blockdev shows the correct size, so the issue is not with losetup. – Jean Jordaan May 7 '15 at 12:07

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.