Use the loop device and losetup commands to create a hard disk image

Source: Internet
Author: User

1. Create an image file

Use the following command to create the image file SDB. IMG, BS to specify the block size, and the image file size is Bs * count

Dd If =/dev/Zero of = SDB. img bs = 512 COUNT = 16384

2. Use the losetup command to associate the generated image file with the loop device.

Run the following command to associate the SDB. IMG image file with the/dev/loop0 device:

Losetup/dev/loop0 SDB. img

3. Use the fdisk command to partition the newly associated loop device.

Run the following command to partition the/dev/loop0 device:

Fdisk/dev/loop0

4. Create a file system for each partition

1) associate each partition with a new loop device

Use the following command to associate the loop1 device with the first shard of the loop0 device. xxxx specifies the starting position (in bytes) of the First shard in the loop0 device ):

Losetup-O xxxx/dev/loop1/dev/loop0

Connect the loop2 device to the second partition.

Losetup-O yyyy/dev/loop2/dev/loop0

2) run the mkfsxxx command to create a file system for the loop1 and loop2 devices.

For example, mkfs. ext4/dev/loop1

5. Mount two shards in the loop0 Device

Run the following command to mount two partitions:

Mount/dev/loop1/mnt/sdc1

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.