first, i create a disk image use dd:
> dd if=/dev/zero of=disk bs=512 count=2097152 > du -h disk 1.1G disk second, fdisk disk create a partion:
Command (m for help): p Disk disk: 1 GiB, 1073741824 bytes, 2097152 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x40c73f2f Device Boot Start End Blocks Id System disk1 2048 2097151 1047552 83 Linux blocks column: 1047552, so sectors is : 1024(can fdisk set sector size?).
third, losetup:
losetup /dev/loop0 -o 2097152 --sizelimit=1072693248 disk 2048*1024 = 2097152 1047552*1024 = 1072693248.
at this time the size of disk is 1G:
> du -h disk 1.1G disk forth, mkfs.ext2:
> mkfs.ext2 /dev/loop0 mke2fs 1.42.8 (20-Jun-2013) Discarding device blocks: done Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65408 inodes, 261632 blocks 13081 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8176 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done and disk image size is decreased:
> du -h disk 19M disk You know filesystem block size is 4096, and have 8 block groups, 32768 blocks per group.
4096 * 8 * 32768 = 1G.
ls -l disknot by any multiplication of sectors and size and then rounding to the nearest 1G (or have a program do that). Please give the exact values ofls -l diskafterddand aftermkfs.ext2on the loop device.