File access as a block device

Source: Internet
Author: User

1. Loop Device Introduction

In UNIX-like systems, the loop device is a pseudo-device (pseudo-device), or it can be said to be a simulation device. It allows us to access a file like a piece of equipment.
Before use, a loop device must be connected to a file. This combination gives the user an interface to replace the block special file. Therefore, if the file contains a complete file system, the file can be mount like a disk device .
The file format mentioned above, we often see the CD or DVD of the ISO disc image file or floppy disk (hard disk) *.img image file. With this loop mount (loopback mount), these image files can be mount to a directory in the current file system.
Now, by the way, you can understand the meaning of loop: For a first-tier filesystem, it is installed directly on top of our computer's physical device, and for this mounted image file (which also contains a file system), it is built on top of the first file system, so it appears that It is like a file system that loops around the first filesystem, so called loop.

2. Losetup command

Losetup [-E encryption] [-o offset] Loop_device file
Losetup [-d] Loop_device

Description :
This command is used to set up a looping device. The loop device simulates the entire file system by virtualizing the file into a block device, allowing the user to see it as a hard drive, an optical drive or a floppy drive, and hang it as a directory for use.
Above, the options and parameter names in the command format:
-E means encryption
-O Set Data offset
-D Uninstalling the device
Loop_device cycle device name, under Linux such as/dev/loop0,/DEV/LOOP1 and so on.

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

3. Examples of Use

(1) Create an empty disk image file, create a 1.44M floppy disk here

$ dd If=/dev/zero of=floppy.img bs=512 count=2880

(2) using Losetup to virtual the disk image file into a fast device

$ LOSETUP/DEV/LOOP1 floppy.img

(3) Mounting block equipment

$ mount/dev/loop0/tmp

After three steps above, we can access the disk image file floppy.img through the/tmp directory, like accessing real fast devices.

(4) Uninstalling the loop device

$ umount/tmp

$ losetup-d/DEV/LOOP1

How do I mount an image file?

http://smilejay.com/2012/08/mount-an-image-file/

Or you can use one of the tools that QEMU comes with QEMU-NBD to mount a client.

http://smilejay.com/2012/11/how-to-mount-a-qcow2-image/

File access as a block device

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.