KVM - Add Disk
I run my virtual machines on SSD storage which is expensive compared to traditional HDD storage. Thus if a virtual machine needs a lot of storage, such as for a mirror, then I will give it an HDD disk to put the data on. Here's how to do just that.
Create the Disk
qemu-img create -f qcow2 -o preallocation=metadata \ [filepath] [size]G
Attach the Disk
virsh attach-disk [vm ID] \ --source /path/to/disk.qcow2 \ --target vd[x] \ --persistent
At this point the disk should show up in your VM if you run the command:
To use the disk we need to create a filesystem on it.
sudo mkfs -t ext4 /dev/vd[x]
Now we need a place to mount the disk and add it to our
/etc/fstab so that it will mount on boot.
sudo mkdir /media/data
Then add the following to your fstab
/dev/vdb /media/data ext4 defaults 0 2
Now you can mount everything
sudo mount -a