Lampros - Weird Bricks

Creating a loop device on Linux

18 April, 2017 | CentOS

Just a quick note so I don't forget in 2 minutes from now.

1. Create a file and specify the size for it - in this example the filename will be moosefs01.img and the size 800GB:

cd /root
truncate -s 800G moosefs01.img

2. Create a filesystem inside the file - in this case we're creating an ext4 type filesystem:

mkfs.ext4 moosefs01.img

The above will give you a warning like this:

mke2fs 1.42.9 (28-Dec-2013)
moosefs01.img is not a block special device.
Proceed anyway? (y,n)

That's fine - type 'y' and press 'Enter'

3. Create a mountpoint:

mkdir /media/moosefs01

4. Mount the filesystem to the mountpoint:

mount /root/moosefs01.img /media/moosefs01

5. And here's the mount:

df -hT /media/moosefs01
Filesystem Type Size Used Avail Use% Mounted on
/dev/loop0 ext4 20G 45M 19G 1% /media/moosefs01