LinuxCommandLibrary

losetup

sets up and controls loop devices, which allow regular files to be

TLDR

List all loop devices

$ losetup -a
copy
Attach file to loop device
$ sudo losetup /dev/loop0 /path/to/file
copy
Attach to free device with partition scan
$ sudo losetup --show -P -f /path/to/file
copy
Attach read-only
$ sudo losetup -r /dev/loop0 /path/to/file
copy
Detach all loop devices
$ sudo losetup -D
copy
Detach specific loop device
$ sudo losetup -d /dev/loop0
copy

SYNOPSIS

losetup [OPTIONS] [loopdev] [file]

DESCRIPTION

losetup sets up and controls loop devices, which allow regular files to be accessed as block devices. This is commonly used for mounting disk images, ISO files, or encrypted containers.

PARAMETERS

-a, --all

Show status of all loop devices
-f, --find
Find the first unused loop device
-P, --partscan
Scan the partition table on the device
-r, --read-only
Set up a read-only loop device
-d, --detach
Detach specified loop device
-D, --detach-all
Detach all associated loop devices
--show
Print the loop device name after setup
-o, --offset bytes
Start at offset into the file
--sizelimit bytes
Limit the size of the loop device

CAVEATS

Loop devices require root privileges to create and detach. The kernel has a limited number of loop devices available (configurable). Always detach loop devices when finished to free resources.

HISTORY

losetup is part of the util-linux package, providing loop device management on Linux systems.

SEE ALSO

mount(8), cryptsetup(8), dd(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community