A
loop device allows to use a regular file as a
block device. «Within» that regular file, a
filesystem can then
mounted just as any other block device (such as hart drive partitions).
If the file does not contain a file system, one can also be created with the usual tools.
Mounting a copy of a Windows partition
A loop device can for example be used to mount a copy of a Windows partition.
First, we need to prepare a directory into which we copy the partition:
$ sudo mkdir /backup-windows
$ cd /backup-windows
The Windows partition is on
/dev/nvme0n1p3
(the 3rd partition of the 1st namespace of the
NVMe device):
$ sudo dd if=/dev/nvme0n1p3 bs=1M of=nvme0n1p3
Find an unused loop device, …
$ /usr/sbin/losetup -f
/dev/loop0
… create the loop device …
$ sudo /usr/sbin/losetup /dev/loop0 /backup-windows/nvme0n1p3
… and mount it:
$ sudo mkdir /backup-windows/mnt
$ sudo mount /dev/loop0 /backup-windows/mnt
The mounted files have 777 (rwxrwxrwx
) permissions, so I, as ordinary user, can access them:
$ cd /backup-windows/mnt/
$ ls
$ mount | grep /dev/loop0
/dev/loop0 on /backup-windows/mnt type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)
Note that I also found a (smaller) version of losetup
under /usr/lib/klibc/bin
.