Turning a file into a partition or a block device:

The loop device is a virtual device, that is used to "turn" a regular file into a block device.

We can make a file in our system look and behave like a disk partition using the below commands.

We start by creating a 2GB file and, we "zero" it out using the below command:

  • if : the input file.
  • of : the output file.
  • bs : the block size.
  • count : the number of block sizes.
Then we create an ext4 filesystem on our file block-file using the below command:


 Then we mount our file, in order to be able to use it:


- "/mnt" is the mount point for our file block-file.
- The system uses the first free loop device it finds

When we are done using our block-file, we can unmount it using the below command:



Remark:

We could also use the below command to associate our file block-file with a loop device:


To avoid using a busy loop device, we use the below command to list the first "free" loop device in the system:


Brando Sabatini and Ikbal C ©. Powered by Blogger.