Skip to content

Instantly share code, notes, and snippets.

@wideglide
Created April 4, 2018 15:26
Show Gist options
  • Save wideglide/365b0abd04b9b78257e43e47e96b7135 to your computer and use it in GitHub Desktop.
Save wideglide/365b0abd04b9b78257e43e47e96b7135 to your computer and use it in GitHub Desktop.
Creating filesystems
  • Create 10MB file filled with NULL bytes
$ dd if=/dev/zero of=/tmp/blank_ext2.img bs=512 count=20480
20480+0 records in
20480+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.132602 s, 79.1 MB/s
  • Create a EXT2 filesystem inside the blank file (default options).
$ mkfs.ext2 /tmp/blank_ext2.img
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done
Creating filesystem with 10240 1k blocks and 2560 inodes
Filesystem UUID: 7312a100-61bf-46ca-9f22-929c43bb2656
Superblock backups stored on blocks:
        8193

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
  • Check ext2 filesystem with file.
$ file -k /tmp/blank_ext2.img
/tmp/blank_ext2.img: Linux rev 1.0 ext2 filesystem data, UUID=7312a100-61bf-46ca-9f22-929c43bb2656 (large files)\012- data
  • Check ext2 filesystem wiht fsstat.
$ fsstat /tmp/blank_ext2.img
FILE SYSTEM INFORMATION
--------------------------------------------
File System Type: Ext2
Volume Name:
Volume ID: 5626bb439c92229fca46bf6100a11273

Last Written at: 2018-04-04 11:21:43 (EDT)
Last Checked at: 2018-04-04 11:21:43 (EDT)

Last Mounted at: empty
Unmounted properly

Source OS: Linux
Dynamic Structure
Compat Features: Ext Attributes, Resize Inode, Dir Index
InCompat Features: Filetype,
Read Only Compat Features: Sparse Super, Large File,

METADATA INFORMATION
--------------------------------------------
Inode Range: 1 - 2561
Root Directory: 2
Free Inodes: 2549

CONTENT INFORMATION
--------------------------------------------
Block Range: 0 - 10239
Block Size: 1024
Reserved Blocks Before Block Groups: 1
Free Blocks: 9819

BLOCK GROUP INFORMATION
--------------------------------------------
Number of Block Groups: 2
Inodes per group: 1280
Blocks per group: 8192

Group: 0:
  Inode Range: 1 - 1280
  Block Range: 1 - 8192
  Layout:
    Super Block: 1 - 1
    Group Descriptor Table: 2 - 2
    Data bitmap: 42 - 42
    Inode bitmap: 43 - 43
    Inode Table: 44 - 203
    Data Blocks: 204 - 8192
  Free Inodes: 1269 (99%)
  Free Blocks: 7975 (97%)
  Total Directories: 2

Group: 1:
  Inode Range: 1281 - 2560
  Block Range: 8193 - 10239
  Layout:
    Super Block: 8193 - 8193
    Group Descriptor Table: 8194 - 8194
    Data bitmap: 8234 - 8234
    Inode bitmap: 8235 - 8235
    Inode Table: 8236 - 8395
    Data Blocks: 8396 - 10239
  Free Inodes: 1280 (100%)
  Free Blocks: 1844 (90%)
  Total Directories: 0
  • Create a 10MB file filled with NULL bytes
$ dd if=/dev/zero of=/tmp/blank_fat.img bs=512 count=20480
20480+0 records in
20480+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.100005 s, 105 MB/s
  • Create a FAT16 filesystem inside that blank file (other options could be specified).
$ mkfs.fat -F 16 /tmp/blank_fat.img
mkfs.fat 3.0.28 (2015-05-16)
  • Check with file.
$ file -k /tmp/blank_fat.img
/tmp/blank_fat.img: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 20480 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 20, sectors/track 32, heads 64, serial number 0xc48dae45, unlabeled, FAT (16 bit)\012- DOS/MBR boot sector, mkdosfs boot message display "This is not a bootable disk.  Please insert a bootable floppy a" DOS/MBR boot sector DOS executable (COM), boot code\012- data
  • Check with fsstat.
$ fsstat /tmp/blank_fat.img
FILE SYSTEM INFORMATION
--------------------------------------------
File System Type: FAT16

OEM Name: mkfs.fat
Volume ID: 0xc48dae45
Volume Label (Boot Sector): NO NAME
Volume Label (Root Directory):
File System Type Label: FAT16

Sectors before file system: 0

File System Layout (in sectors)
Total Range: 0 - 20479
* Reserved: 0 - 0
** Boot Sector: 0
* FAT 0: 1 - 20
* FAT 1: 21 - 40
* Data Area: 41 - 20479
** Root Directory: 41 - 72
** Cluster Area: 73 - 20476
** Non-clustered: 20477 - 20479

METADATA INFORMATION
--------------------------------------------
Range: 2 - 327030
Root Directory: 2

CONTENT INFORMATION
--------------------------------------------
Sector Size: 512
Cluster Size: 2048
Total Cluster Range: 2 - 5102

FAT CONTENTS (in sectors)
--------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment