There’s no secret about my love for Proxmox. I am going to write an article in the future about why I think it’s great, but for now, just know that it is my favorite hypervisor out! With that said, because it is not as well known as some other hypervisors, the documentation to tell you how to solve a problem can be…lacking. Now fortunately, this particular problem was encountered and was addressed on the Proxmox forum, however, I wanted to dive a bit more into the actual problem and the solution to solve it.
I first encountered this issue while trying to import the FortiAuthenticator VM image from Fortinet into Proxmox. I recently wrote an article on Adding a FortiGate VM into Proxmox and I thought I could just replace the FortiGate qcow2 file with a FortiAuthenticator qcow2 file and “wash, rinse, repeat”. I was in for a shock once I started encountering issues just trying to get the FortiAuthenticator to boot.
Importing a FortiAuthenticator into Proxmox is out of the scope for this post. I will follow up with those instructions in a later article.
The main issue to overcome was being greeted with the error “volume size must be a multiple of volume block size” when trying to move the FortiAuthenticator VM boot disk to the ZFS block device. Here is a snapshot of the error I got when attempting to do this:
I am not going to pretend to try and explain how ZFS works but I do know two things about ZFS in relation to Proxmox:
- The block size of the VM hard drive file has to be a multiple of the block size assigned to the ZFS pool it is running on
- The file format of the VM hard disk has to be RAW (instead of the default qcow2)
The cause of the error is due to #1. According to the output of the following command, the block size of the volume is 8K:
zfs list -o volblocksize
To try to explain this in more detail, let me provide an example via screenshots:
The VM hard drive file for the FortiAuthenticator is 112,640,512 Bytes. The ZFS block size is 8192 Bytes. Doing some simple math, we see the following:
112,640,512 / 8192 = 13,750.0625
The problem with this file size is that the remainder (.0625) is no good because this file does not evenly fit into the 8K block. To address this issue, we simply need to make the file a multiple that can fit into the block cleanly. Before we can manipulate this file, we first need to convert the VM hard drive into a format that will allow us to modify the storage size without any kind of vm disk magic (similar to what qcow2 uses). To do this, we need to convert the qcow2 image to a raw image using the built in “qemu-img” in Proxmox:
qemu-img convert -f qcow2 -O raw fackvm.qcow2 fackvm.raw
In a nutshell, you are calling the above command to take in (input) a “qcow2” formatted VM disk and create out (output) a “raw” formatted VM disk with the same contents. Upon doing this, you will find that the “raw” version of this file is a lot larger than the qcow2 version (this is the “black magic” I referred to earlier).
Now that we have the “raw” image of the file, we need to figure out how much we need to pad this file so we can make it a multiple of 8K. To do this, we follow this simple formula to make this calculation:
<vm_drive_size>/(64 * 1024) = <resultant.decmimal>
round_up(<resultant.decimal>) * (64 * 1024) = <new_resultant>
<new_resultant> – <vm_drive_size> = <amount_to_pad>
So in our example the math looks like the following:
112640512 / (64 * 1024) = 1718.7578
1719 * 64 * 1024 = 112656384
112656384 – 112640512 = 15872
Once we know the amount to pad the file, we can use tools in linux like “dd” to add zeros to the end of the file and make it a multiple of the 8K block size. An example of this is shown in the command below:
dd if=/dev/zero bs=1 count=15872 >> fackvm.raw
Before I do the last step of copying this file to overwrite the previous VM disk so I can successfully move it to the ZFS block device, I want to provide confirmation that this new filesize will divide into 8K evenly with no decimal.
112656384 / 8192 = 13752
This is exactly what I needed to see. Now I can move on to the last step of copying the file and moving it to the ZFS device in Proxmox:
1.Copy the file to the correct location within Proxmox
2.Use “Move Disk” function to move file to the ZFS Block device
As the “TASK OK” indicates at the end, this image was able to successfully be transferred to the ZFS block storage.