Losetup
Losetup, short for loop setup, is a command-line utility in Linux used to manage loop devices. A loop device is a virtual block device that maps to a regular file, allowing the file to be accessed as if it were a physical disk. This enables mounting and interacting with disk images, ISO files, or other filesystem images without dedicated hardware.
Loop devices are provided by the kernel’s loop device driver and are commonly used for testing, virtualization,
- -f to find an unused loop device, often with --show to print the device name after assignment
- -a to display all active loop devices
- -o to specify an offset within the file
- --sizelimit to limit the mapped portion of the file
- -P to scan for partitions inside the mapped image, exposing devices like /dev/loop0p1
- -r to map the image read-only
These options enable mapping of whole images or specific portions, and partitioned images can provide access
Example workflow: sudo losetup --find --show image.img creates /dev/loop0; sudo mount /dev/loop0 /mnt mounts it; after
See also: mount, partition tables, and the loopback device concept.