Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the losetup command in Linux

Shulou Source: shulou.com Published: 2022-06-01 18:29:21 10月30日 Update

This article mainly introduces how to use the losetup command in Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

The Linux common command losetup command is used to set up looping devices. A circular device can virtualize files into block devices to simulate the entire file system, allowing users to treat them as devices such as hard drives, optical drives or floppy drives, and hang them as directories.

Losetup setting and Control cycle (loop) equipment

The syntax losetup [- e encryption] [- o offset] loop_device file losetup [- d] loop_device option-a shows the status of all looping devices. -d remove the equipment. -e start encryption coding. -f look for the first unused loop device. -o sets the data offset in bytes. Parameter loop_device: the loop device can be / dev/loop0, / dev/loop1... / dev/loop7 .

File: the file name to be associated with the circular device, which is often a disk mirror file, such as * .img

Loop device introduction in a UNIX-like system, a loop device is a pseudo device (pseudo-device), or can be said to be a simulation device. It enables us to access a file like a block device. A loop device must be connected to a file before it can be used. This combination provides users with an interface to replace block special files. Therefore, if the file contains a complete file system, the file can be mount like a disk device.

The file format mentioned above, what we often see is the ISO image of cd or DVD or the * .img image of floppy disk (hard disk). In this way of loop mount (mount), these images can be mount to a directory of the current file system.

At this point, by the way, we can understand the meaning of loop: for the first layer file system, it is installed directly on the physical device of our computer; and for this kind of image file which is mount (it also contains the file system), it is built on the first layer file system, so it looks like a file system that has circled again on the first layer file system, so it is called loop.

Instance to create an empty disk image file, and here create a 1.44m floppy disk:

Dd if=/dev/zero of=floppy.img bs=512 count=2880 uses losetup to virtualize disk image files into fast devices:

Losetup / dev/loop1 floppy.img mount block devices:

Mount / dev/loop0 / tmp after the above three steps, we can access the disk image file floppy.img through the / tmp directory as if we were accessing a real fast device.

Uninstall the loop device:

Umount / tmp losetup-d / dev/loop1 Thank you for reading this article carefully. I hope the article "how to use losetup commands in Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Files devices systems mirrors loops disks commands articles directories methods users hard drives floppy disks special value optical discs optical drives interests units parameters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Technology Shulou Information Redmi OPPO Reno