0

I know I used to be able to do it, and its frustrating I cant recall. I want to write an ext4 filesystem to a disk image in a folder. I don't want to re-partition my drive, I just need the filesystem to build an OS in. I tried $mkdir foo then sudo mkfs.ext4 foo 70000 mke2fs 1.45.5 (07-Jan-2020) warning: Unable to get device geometry for foo foo: Is a directory while setting up superblock

so i think Im missing arguments. I tried reading the man page, and the ol google, but I did not see and example of using mkfs.ext4 to create a new disk image.

1 Answer 1

3

If you're creating a disk image, you need to operate on a file, not on a directory:

# Create a file of some specific size for the new image
truncate -s 10g disk.img

# Format the image with a new filesystem
mkfs -t ext4 disk.img

You can mount the image using the loop mount option:

mount -o loop disk.img /mnt

Note that the above instructions are for creating a filesystem image. If you want to create a bootable image, you will probably want to partition the file, install a bootloader, etc, which is a slightly more involved process.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .