losetup - Unix, Linux Command



NAME

losetup: set up and control loop devices.

SYNOPSIS

  • losetup loopdev losetup -l [-a] losetup -j file [-o offset]
  • Detach a loop device: losetup -d loopdev...
  • Detach all associated loop devices: losetup -D
  • Print the name of the first unused loop device: losetup -f
  • Set up a loop device: losetup [-o offset] [--sizelimit size] [-Pr] [--show] -f|loopdev file
  • Resize a loop device: losetup -c loopdev
  • DESCRIPTION

    losetup is used to associate loop devices with regular files or block devices, to detach loop devices and to query the status of a loop device. If only the loop_device argument is given, the status of the corresponding loop deviceis shown.

    Options

    Tag Description
    -a, --all show status of all loop devices.
    -c, --set-capacity loopdev force loop driver to reread size of the file associated with the specified loop device.
    -d, --detach loopdev... detach the file or device associated with the specified loop devices.
    -e, -E, --encryption encryption_type enable data encryption with specified name or number.
    -f, --find find the first unused loop device. If a file argument is present, use this device. Otherwise, print its name.
    -h, --help print help.
    -j, --associated file show status of all loop devices associated with given file.
    -o, --offset offset the data start is moved offset bytes into the specified file or device.
    --sizelimit limit the data end is set to no more than sizelimit bytes after the data start.
    -p, --pass-fd num read the passphrase from file descriptor with number num instead of from the terminal.
    -r, --read-only setup read-only loop device.
    --show print device name if the -f option and a file argument are present.The short form of this option (-s) is deprecated. This short form could be in collision with Loop-AES implementation where the same option is used for --sizelimit..
    -v, --verbose verbose mode.

    EXAMPLES

    Example-1:

    To detach file or device associated with loop device :

    # losetup -e des /dev/loop0 /file

    OR

    # losetup -d /dev/loop0

    Example-2:

    The following commands can be used as an example of using the loop device.

     # dd if=/dev/zero of=~/file.img bs=1MiB count=10
     # losetup --find --show ~/file.img /dev/loop0
     # mkfs -t ext2 /dev/loop0
     # mount /dev/loop0 /mnt
     ...
     # umount /dev/loop0
     # losetup --detach /dev/loop0 
    	  
    Advertisements