Simulate a hard disk with file

Simulate a hard disk with file

  1. Create a file:

    1
    $ dd if=/dev/zero of=fake_disk bs=4M count=1024
  2. Associate the file with /dev/loop1:

    1
    $ sudo losetup /dev/loop1 fake_disk
  3. Create a filesystem on this device:

    1
    $ mkfs.ext4 /dev/loop1
  4. Detach /dev/loop1 and fake_disk:

    1
    $ sudo losetup -d /dev/loop1
  5. Mount this file:

    1
    $ sudo mount -o loop fake_disk /mnt/fake_disk/
  6. Verify using df:

    1
    2
    3
    $ df -a
    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/loop0 3997376 8184 3763096 1% /mnt/fake_disk