How to create a virtual disk in linux

1. The qemu command and nbd driver are completed (additional dependencies need to be installed)

Dependencies: Download the kernel corresponding to nbd source code compilation, and insmod loads the nbd driver. yum install -y qemu** downloads the corresponding qemu tool.

process:

  • qemu-img create -f qcow2 ***.qcow2 1G
  • qemu-nbd -c /dev/nbd0 ***.qcow2
  • lsblk sees an extra nbd0 block device (you can also use the nbd device number after 1 depending on the situation)
  • mkfs.xfs /dev/nbd0
  • mount /dev/nbd0 ***
  • After mounting, you can use the disk normally...
  • umount -l ***
  • qemu-nbd -d /dev/nbd0

2. The dd command and loop driver are completed (the system comes with its own instructions, no need to install additional dependencies)

process:

  • dd if=/dev/zero of=./virt_disk bs=1M count=1024
  • losetup -Pf --show ./virt_disk
  • lsblk (find one more /dev/loop0 device, it can also be a larger value)
  • mkfs.xfs /dev/loop0
  • mount /dev/loop0 ***
  • After mounting, you can use the disk normally...
  • umount -l ***
  • losetup -d /dev/loop0

Guess you like

Origin blog.csdn.net/jiujiederoushan/article/details/129952218