OS - Linux
Loopback device
bailey..
2018. 4. 24. 07:36
Create an image file
This is an example of creating an image file whose block size is 1MB and total size is 5GB.
# dd if=/dev/zero of=./disk1.img bs=1M count=5120 5120+0 records in 5120+0 records out 5368709120 bytes (5.4 GB) copied, 222.903 s, 24.1 MB/s | cs |
Attach the image file as a loopback device
# losetup -f /app/work/glusterfs/disk/disk1.img # losetup -l NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE /dev/loop0 0 0 0 0 /app/work/glusterfs/disk/disk1.img | cs |
Format
# mkfs.xfs /dev/loop0 meta-data=/dev/loop0 isize=512 agcount=4, agsize=327680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=1310720, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 | cs |
Mount
# mkdir /mnt/disk1 # mount /dev/loop0 /mnt/disk1 | cs |
Unmount & Detach
# umount /mnt/disk1 # losetup -d /dev/loop0 | cs |