Use losetup to virtualize a block device (File System)

Source: Internet
Author: User

Using losetup to virtualize Block devices (file systems) in Linux, SCSI disks support up to 15 partitions (3 primary partition sda1-sda3 + 1 Extension
Partition sda4 + 11 logical partition sda5-sda15), and The IDE disk only supports 63 partitions [root @ rhel6 ~] # Fdisk-l/dev/sda Disk/dev/sda: 6442 MB, 6442450944 bytes 16 heads, 63 sectors/track, 12483 cylinders Units = cylinders of 1008*512 = 516096 bytes Sector size (logical/physical): 512 bytes/512 bytes I/O size (minimum/optimal ): 512 bytes/512 bytes Disk identifier: 0x00053d18 Device Boot Start End Blocks Id System/dev/sda1 * 1 104 51200 83 Linux/dev/sda2 104 11076 5529600 8e Linux LVM/dev /Sda3 11076 12116 524288 82 Linux swap/Solaris/dev/sda4 12116 12483 185320 5 Extended/dev/sda5 12116 12136 10400 + 83 Linux/dev/sda6 12137 12157 10552 + 83 Linux/ dev/sda7 12158 12178 10552 + 83 Linux/dev/sda8 12179 12199 10552 + 83 Linux/dev/sda9 12200 12220 10552 + 83 Linux/dev/sda10 12221 12241 10552 + 83 Linux/ dev/sda11 12242 12262 10552 + 83 Linux/dev/sda12 12263 12283 10552 + 83 Linux/dev /Sda13 12284 12304 10552 + 83 Linux/dev/sda14 12305 12325 10552 + 83 Linux/dev/sda15 12326 12346 10552 + 83 Linux/dev/sda16 12347 12367 10552 + 83 Linux [root @ rhel6 ~] # Mkfs. ext4/dev/sda16 // although more than 15 partitions can be drawn, mke2fs 1.41.12 (17-May-2010) cannot be formatted) cocould not stat/dev/sda16 --- No such file or directory The device apparently does not exist; did you specify it correctly? [Root @ rhel6 ~] # Ls/dev/sda16 ls: cannot access/dev/sda16: No such file or directory loopback device can Virtualize files into block devices to simulate the entire file system, in this way, users can regard it as a hard drive, optical drive, and other devices, and mount it as a file system for use. As a result, the system can add more partitions (only loop0-loop7 by default) losetup-a displays the status of all used loopback devices-d disconnects loopback devices-f searches for the first unused loopback device-e <encryption Options> Start the encryption code [root @ rhel6 ~] # Losetup-f // find the first unused loopback device/dev/loop0 [root @ rhel6 ~] # Losetup-a // display the status of all used loopback devices [root @ rhel6 ~] # Dd if =/dev/zero of = loop. img bs = 10 M count = 10 10 + 0 records in 10 + 0 records out 104857600 bytes (105 MB) copied, 0.794912 s, 132 MB/s [root @ rhel6 ~] # Losetup-f loop. img // Virtualize loop. img into the first unused loop device [root @ rhel6 ~] # Losetup-a/dev/loop0: [fd00]: 26524 (/root/loop. img) [root @ rhel6 ~] # Losetup-f/dev/loop1 [root @ rhel6 ~] # Mkfs. ext4/dev/loop0 [root @ rhel6 ~] # Mount/dev/loop0/mnt/[root @ rhel6 ~] # Df-h Filesystem Size Used Avail Use % Mounted on/dev/mapper/Lrhel6-root 3.9G 2.4G 1.4G 64%/tmpfs 499 M 0 499 M 0%/dev/shm/dev/ sda1 49 M 27 M 20 M 59%/boot/dev/loop0 97 M 5.6 M 87 M 7%/mnt [root @ rhel6 ~] # Umount/mnt/[root @ rhel6 ~] # Losetup-d/dev/loop0 // The loop0 unmounts the loopback 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.