>_ IzzyLab

Hands-on task

This task is step 18 of the course “Disks, links and free space”

A filesystem in an image file

medium~5 min

There's no spare partition on hand — a filesystem can be created right inside an ordinary image file. Create a file /root/disk.img 30 MiB in size and format it as ext4. There's no need to mount it (under gVisor it wouldn't work anyway) — it's enough for the image to hold a filesystem.

What you'll practise:
  • FS image
  • mkfs.ext4
  • image file
  • formatting
  • ext4

Topic breakdown

A filesystem doesn't have to be created on a separate partition — it can be written right into an ordinary image file: to the FS it's just a set of service structures in bytes, and it needs no block device. First you prepare a file of the right size (by extending it to length with truncate), then format it with the mkfs.ext4 command. Since the target is a file, not a device, mkfs may ask for confirmation, and you force it with a flag. Such an image can't be mounted under gVisor, but the tools read the FS metadata even without mounting.

What's checked

  1. the image is exactly 30 MiB
  2. a valid ext4 is inside

What it looks like