How to change the size of swap file for single partition KVM templates?

Applicable to:

  • SolusVM

Question

How to change the size of swap file for single partition KVM templates?

Answer

Starting from version 1.20.09 SolusVM uses swap size set via web interface.

For the older version of SolusVM it is required to set swap size in the template file

Note: Steps below describe how to increase the size of a swap file for the single partition template on the SolusVM Master node. To apply the changes for the templates on the slave nodes, it is required synchronizing template with the slave nodes (steps 6-8 from this article)

  1. Connect to the SolusVM Master server via SSH
  2. Create a temporary directory for mount point:

    # mkdir /mnt_tmp

  3. Mount a single-partition template image on this mount point, in this example it is Ubuntu 16 x64 single partition template:

    # guestmount -a /home/solusvm/kvm/template/linux-ubuntu-16.04-x86_64-minimal-latest.gz -i --rw /mnt_tmp

  4. first-boot.sh script located in the following directory /mnt_tmp/root/scripts/

    # ls -l /mnt_tmp/root/scripts/
    total 4
    -rwxr-xr-x 1 root root 697 May 4 16:49 first-boot.sh

  5. Open this file in the text editor like vi and update the script, change the value for count option of the dd utiity up to 1024MB:

    # vi  /mnt_tmp/root/scripts/first-boot.sh

    Before

    # cat /mnt_tmp/root/scripts/first-boot.sh | grep dd
    dd if=/dev/zero of=/swapfile bs=1024 count=262144 >> /var/log/first-boot.log 2>&1 

    After

    # cat /mnt_tmp/root/scripts/first-boot.sh | grep dd
    dd if=/dev/zero of=/swapfile bs=1024 count=1048576 >> /var/log/first-boot.log 2>&1 

    count parameter changed from 262144 to 1048576, it is set in Kilobytes  

  6. Unmount the image:

    # fusermount -u /mnt_tmp/

  7. Do not forget to synchronize the template with slave KVM nodes

 Once the changes are applied, swap file on the VPS created using this template will have 1024 MB

Articles in this section

Was this article helpful?
0 out of 0 found this helpful
Share

Comments

0 comments

Please sign in to leave a comment.