Posted: . At: 1:28 PM. This was 6 years ago. Post ID: 11848
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

How to create a loopback filesystem easily in your home folder. Good for storing files or creating a swapfile.

It is very easy to create a loopback filesystem in your home directory. This can be used to store files, or can be enabled as a swap partition.

Firstly, run this command to create a blank file-system image. This will be 524 megabytes.

jason@Yog-Sothoth:~/Documents$ dd if=/dev/zero of=myimage.img bs=1024 count=524288

Now we can create a filesystem on it and make it usable.

jason@Yog-Sothoth:~/Documents$ sudo mkfs.ext4 myimage.img 
[sudo] password for jason: 
mke2fs 1.43.5 (04-Aug-2017)
Discarding device blocks: done                            
Creating filesystem with 131072 4k blocks and 32768 inodes
Filesystem UUID: e7173517-d589-43df-a76a-31374f3377f4
Superblock backups stored on blocks: 
	32768, 98304
 
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This file-system is ready to be used, just mount it to a directory and then create a directory on the file-system that is owned by your user and you will be able to copy files to it and use it as just another directory on your system.

jason@Yog-Sothoth:/mnt/image$ sudo mount myimage.img /mnt/image/

This is a very useful Linux trick, it could be used for many things, but I think many of you will like to give this a try.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.