Linux Virtualization Adding Storage to Guests: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(22 intermediate revisions by the same user not shown)
Line 5: Line 5:
=Internal=
=Internal=


* [[Linux_Virtualization_Operations#Adding_Storage_to_Guests|Linux Virtualization Operations]]
* [[Linux_Virtualization_Operations#Guest_Operations|Linux Virtualization Operations]]
* [[Linux_KVM_Virtualization_Guest_Operations#Add_Storage_to_Guests|Guest Operations]]
* [[Virt-install#Storage_Post-Configuration|virt-install | Storage Post-Configuration]]


=Add a Logical Volume as Block Device to Guest=
=Add a Storage Volume as Block Device to Guest=


==Provision the Logical Volume==
==Provision the Storage Volume==


==Configure the Guest to Mount the Logical Volume at Boot==
Create the storage volume with:
 
    [[virsh vol-create-as|virsh vol-create-as --pool <pool-name> --name <volume-name> --capacity <capacity> --format <fomat>]]
 
==Shut Down the Guest==
 
    virsh shutdown <guest-name>
 
Note that is also possible to add the device while the guest is running, see virsh man page for more details.
 
==Configure the Guest to Mount the Storage Volume at Boot==
 
===With  virsh attach-disk===
 
Use [[virsh attach-disk]] as shown in the example, by specifying the file-based storage volume path, as shown by the [[virsh vol-list]] command, and the device name under which the disk is exposed to guest, typically "vdX", where X is "a", "b", etc:
 
{{Internal|Virsh_attach-disk#Attaching_a_File-Based_Storage_Volume|Attaching a File-Based Storage Volume with virsh attach-disk}}
 
===Edit Guest Configuration===
 
Alternatively, the guest configuration can be edited manually with [[virsh edit]] and the following sequence added after the last declared <disk>. Adjust accordingly the driver type, the source file and the target dev:
 
<syntaxhighlight lang='xml'>
<disk type='file' device='disk'>
  <driver name='qemu' type='raw'/>
  <source file='/main-storage-pool/test.raw'/>
  <target dev='vdc' bus='virtio'/>
</disk>
</syntaxhighlight>
 
==Start the Guest==
 
    virsh start <guest-name>
 
Upon startup, the new disk should be available as /dev/vdX.
 
[[lsblk]]
 
==Partition the New Disk==
 
Optionally, if you want to break the block device into several smaller parts, partition the new disk with:
 
<syntaxhighlight lang='bash'>
fdisk /dev/vdX
</syntaxhighlight>
 
More details about fdisk are available here:
 
{{Internal|fdisk|fdisk}}
 
==Build a File System==
 
{{Internal|Create Filesystems|Create Filesystems}}
 
==Mount at Boot==
 
{{Internal|/etc/fstab|/etc/fstab}}

Latest revision as of 03:13, 7 December 2020

External

Internal

Add a Storage Volume as Block Device to Guest

Provision the Storage Volume

Create the storage volume with:

   virsh vol-create-as --pool <pool-name> --name <volume-name> --capacity <capacity> --format <fomat>

Shut Down the Guest

   virsh shutdown <guest-name>

Note that is also possible to add the device while the guest is running, see virsh man page for more details.

Configure the Guest to Mount the Storage Volume at Boot

With virsh attach-disk

Use virsh attach-disk as shown in the example, by specifying the file-based storage volume path, as shown by the virsh vol-list command, and the device name under which the disk is exposed to guest, typically "vdX", where X is "a", "b", etc:

Attaching a File-Based Storage Volume with virsh attach-disk

Edit Guest Configuration

Alternatively, the guest configuration can be edited manually with virsh edit and the following sequence added after the last declared <disk>. Adjust accordingly the driver type, the source file and the target dev:

<disk type='file' device='disk'>
   <driver name='qemu' type='raw'/>
   <source file='/main-storage-pool/test.raw'/>
   <target dev='vdc' bus='virtio'/>
</disk>

Start the Guest

   virsh start <guest-name>

Upon startup, the new disk should be available as /dev/vdX.

lsblk

Partition the New Disk

Optionally, if you want to break the block device into several smaller parts, partition the new disk with:

fdisk /dev/vdX

More details about fdisk are available here:

fdisk

Build a File System

Create Filesystems

Mount at Boot

/etc/fstab