HostOnNet Blog

Creating Virtual Flesystem

Looking for Linux Server Admin or WordPress Expert? We can help.

First create a file with 2 GB size using command

fallocate -l 2G my_drive.img

Lets format the file with

mkfs.ext4 my_drive.img

Example

root@backup:~# mkfs.ext4 my_drive.img
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: done                            
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 820ea230-6fad-4072-b8b6-028cc552d07f
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

root@backup:~# 

To see the partition, run

parted /root/my_drive.img print

Example

root@backup:~# parted /root/my_drive.img print
Model:  (file)
Disk /root/my_drive.img: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  2147MB  2147MB  ext4

root@backup:~# 

Before we can mount the file, we need to create a mount point

mkdir /mnt/my_drive/

Mount the virtual file system with command

mount -t auto -o loop /root/my_drive.img /mnt/my_drive/

Now you can see the file system mounted using “df -h” command.

root@backup:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            981M     0  981M   0% /dev
tmpfs           201M   21M  180M  11% /run
/dev/sda1        97G   28G   64G  31% /
tmpfs          1001M     0 1001M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs          1001M     0 1001M   0% /sys/fs/cgroup
/dev/sdb1       689G  420G  235G  65% /backup
tmpfs           201M     0  201M   0% /run/user/0
/dev/loop0      2.0G  3.0M  1.8G   1% /mnt/my_drive
root@backup:~# 

Posted in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

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