Linux 101 : Using loop device as hard drives



A loop device is a pseudo-device that can turn a computer file into a block device.

To be able to see all the "used" loop devices on a system, we use the below command:


To delete all the loop devices on a system, we use:


To delete a loop device using its name, we run the below command:


Using a loop device as storage:

We start our process by making a directory that is going to serve as a mountpoint for our device:


We then create a raw disk file of "1G" using the "dd" utility:


To see the first available loop device, we use the below command:


We use the below command to associate our loop device "/dev/loop1" with the raw disk file we have just created with the "dd" utility:



We could then partition it using the parted program.

We label our device with the "mbr" label using the below command:


Then we create two partitions  partitions "/dev/loop1p1" and "/dev/loop1p2":


To check is our "loop1" is showing on the system, we use the below command:


We might need to run so that the changes are reflected in the system:


The we create a filesystem on one of the partitions using the below command:


Then we mount it, on the "data" directory to be able to use it:


We can unmount our device once we have no use for it, using the command:

Comments

Leave as a comment:

Archive