- Red Hat Enterprise Linux Server Cookbook
- William Leemans
- 371字
- 2021-07-30 09:54:21
Adding disks on the fly
This recipe includes instructions on how to create different types of storage volumes. Storage volumes are dedicated storage sets aside for use by guests.
Getting ready
There is not a lot of preparation to be done in order to add disks to your guest, which is in contrast to adding CPUs and RAM.
You only need to ensure that the storage pool has enough free disk space to accommodate the new disk.
How to do it…
Similar to the recipe for creating guests, you'll need to create a disk first. This can be done as follows:
- Let's create a raw disk in the
localfs-vm
pool that is30
GB big through the following command:~]# virsh vol-create-as --pool localfs-vm --name rhel7_guest-vdb.raw --format raw --capacity 30G
- Look up the path of the newly created volume, as follows:
~]# virsh vol-list --pool localfs-vm |awk '$1 ~ /^rhel7_guest-vdb.raw$/ {print $2}'
This will result in the path of your volume; here's an example:
/vm/rhel7_guest-vdb.raw
- Attach the disk to the guest, as follows:
~]# virsh attach-disk --domain <guestname> --source <the above path> --target vdb --cache none --persistent –live
How it works…
Creating a disk using vol-create-as
may take some time depending on the speed of your host's disks and the size of the guest's disks.
We will look up the path of the newly created volume as it is a required argument for the command that attaches the disk to the guest. In most cases, you won't need to do this as you'll know how your host is configured, but when you script this kind of functionality, you will require this step.
Adding a disk in this way will attach a disk using the virtio
driver, which, as specified earlier, is optimized for use with KVMs.
There's more…
If, for some reason, the original guest doesn't support virtio
drivers or you do not have the virtio
controller, you can create this yourself. Store the XML configuration file as /tmp/controller.xml
with the following contents:
<controller type='scsi' model='virtio' />
You can find this out by checking the host's XML file for the preceding statement.
Then, import the XML configuration file, as follows:
~]# virsh attach-device –domain <guestname> /tmp/controller.xml
This will allow you to create disks using virtio
.
- jQuery Mobile Web Development Essentials(Third Edition)
- Getting Started with Gulp(Second Edition)
- Apache ZooKeeper Essentials
- The React Workshop
- 營銷數據科學:用R和Python進行預測分析的建模技術
- UI智能化與前端智能化:工程技術、實現方法與編程思想
- concrete5 Cookbook
- Python機器學習基礎教程
- Arduino家居安全系統構建實戰
- Unity&VR游戲美術設計實戰
- Mastering Apache Storm
- 深入實踐DDD:以DSL驅動復雜軟件開發
- Julia High Performance(Second Edition)
- Spring Data JPA從入門到精通
- Python編程:從入門到實踐(第2版)