The following article will describe a procedure on how to create a file based filesystems using dd command on Linux.
First, create a zero filled file with a specific size using dd
command. Below are few examples on how to create a such file of specific size:
1GB: $ dd if=/dev/zero of=file.fs bs=1024 count=1024000 100MB: $ dd if=/dev/zero of=file.fs bs=1024 count=102400 10MB: $ dd if=/dev/zero of=file.fs bs=1024 count=10240 1MB: $ dd if=/dev/zero of=file.fs bs=1024 count=1024
After execution of any of the above command you will now have file.fs
file available in your current working directory. For example to create 10MB file execute:
$ dd if=/dev/zero of=file.fs bs=1024 count=10240 10240+0 records in 10240+0 records out 10485760 bytes (10 MB) copied, 0.0338773 s, 310 MB/s $ ls file.fs
Next, create a filesystem of your choice using mkfs
command:
- mkfs.bfs
- mkfs.cramfs
- mkfs.ext2
- mkfs.ext3
- mkfs.ext4
- mkfs.ext4dev
- mkfs.fat
- mkfs.minix
- mkfs.msdos
- mkfs.ntfs
- mkfs.vfat
The below command will create vfat filesystem:
# mkfs.fat file.fs mkfs.fat 3.0.27 (2014-11-12)
Depending on what you need, now we are ready to create a mount point eg./mnt/tmp
and mount our new filesystem:
# mkdir /mnt/tmp # mount file.fs /mnt/tmp/
Confirm that the file system is mounted:
# mount | grep file.fs /home/lubos/filefs/file.fs on /mnt/tmp type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro) # cd /mnt/tmp/ # df -h . Filesystem Size Used Avail Use% Mounted on /dev/loop0 10M 0 10M 0% /mnt/tmp