Skip to main content

How to resize KVM virtual machine disk file

 

In KVM when you create a new virtual machine,  you have to specify the initial size of the disk that the machine is going to use. If later, you realize that initial size is not enough,  you can resize disk image with qemu-img command:

$ qemu-img resize vm-101-disk-1.raw +10G

In the example we have resized the disk image with 10Gb more. The new size can be specified in K for kilobyte, M for megabyte and G for gigabyte.

Inside virtual machine you are going to see new unassigned free space in the disk. If we have partitioned the guest machine with LVM we can easily extend the logical volumes  with the new space we have newly created in the disk. To do that we only have to create a new LVM partition and assign the new partition to the existing volume group.

Davfs: mounting https webdav resource

 

Here is a simple guide to automaticaly mount a webdav resource in linux.  In this case we are going to use davfs2 to mount our webdav resource. Davfs is able to mount a WebDAV resource as a regular file system and access it in the same way as others directories in your system. In Ubuntu you have to install davfs2 package:


$ sudo apt-get install davfs2

Usually,   you access to your webdav resource with a username and password. In davfs you can do it automatically putting the username and password in  .davfs/secrets file in your home directory. Davfs gets this data and does login for you.

Here is an example of .davfs/secrets file,  “/home/user/webdav” is the mount point of your webdav resource:


/home/user/webdav username password

You can put this configuration in  /etc/fstab file:


https://myserver.org/webdav /home/user/webdav/ davfs user,noauto 0 0

Now,  you can see this new resource in nautilus file browser and you can mount it automatically.

If you are trying to mount a https resource you have another problem to deal with:   the server certificate. If server certificate you are using is sefsigned or from a CA cert that is not known for your system,   you are going to see these message when you are trying to mount the webdav resource:

You only should accept this certificate, if you can
verify the fingerprint! The server might be faked
or there might be a man-in-the-middle-attack.
Accept certificate for this session? [y,N]

You can’t accept the certificate permanently,  so you can’t mount the resource trough the fstab to be accesible from nautilus,  because davfs is going to be waiting until you enter the answer. What you have to do is configure the CA certificate in PEM format on davfs to always be trusted. To do that edit .davfs2/davfs2.conf in your home directory or /etc/davfs2.conf for system wide and insert this line:


servercert      ca-cert.pem

You have to put your CA cert file (ca-cert.pem) on .davfs/certs directory.
Now you can mount webdav resource from nautilus without problems.