Creating RAID arrays on files instead of block devices

What you're looking for is called the loop device. It makes files appears as devices like /dev/loop0 etc. They can then be mounted as filesystems, and should work with md. From the man page loop(4):

The loop device is a block device that maps its data blocks not to a physical device such as a hard disk or optical disk drive, but to the blocks of a regular file in a filesystem or to another block device.

See e.g.


For testing things that need block devices, LVM might also be useful. It lets you make multiple logical volumes from a single physical partition (or the other way around) and destroying/recreating/resizing the volumes is also much simpler than with disk partitions.

You can do it. Just create a loop device from the file and use that device to create the array:

$ dd if=/dev/zero of=mydev count=80 bs=1M
$ sudo losetup -f mydev

You will have an 80M device ready and you can use it in any context where you would use a block device.

$ sudo losetup -l

Will tell you the current mapping.