{"id":2378,"date":"2024-01-12T00:11:41","date_gmt":"2024-01-11T18:41:41","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=2378"},"modified":"2025-03-12T11:31:43","modified_gmt":"2025-03-12T06:01:43","slug":"how-to-extend-a-kvm-vps-root-partition-after-disk-upgrade","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-extend-a-kvm-vps-root-partition-after-disk-upgrade\/","title":{"rendered":"How to Extend a KVM VPS Root Partition After Disk Upgrade"},"content":{"rendered":"\n<p>For many Linux users, one common requirement after boosting disk space on a <a href=\"https:\/\/www.veeble.org\/blog\/kvm-vps-explained-with-pros-and-cons\/\" target=\"_blank\" rel=\"noopener\">KVM (Kernel-based Virtual Machine) VPS<\/a> is to expand a partition. This comprehensive manual offers a methodical strategy to effectively utilize the additional disk space in a KVM virtual environment.<\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"understanding-the-context\">Understanding the Context<\/h4>\n\n\n<p>In a KVM VPS setup, disk space extension might be necessary after a virtual disk upgrade. Sometimes extension of this disk space will be impossible because the swap partition is in between the old root partition and the newly added disk space which may create a barrier for extending the disk due to sector discontinuity. This guide covers the steps to extend the root partition (OS partition) without much risk.<\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"preparing-for-partition-extension\">Preparing for Partition Extension<\/h4>\n\n\n<p><strong>Secure Your Data<\/strong>: Before any partition modification, back up crucial data. This step is vital in a virtual environment to prevent data loss.<\/p>\n\n\n\n<p><strong>Review Current Disk Configuration<\/strong>: Utilize tools like <code>lsblk<\/code> or <code>fdisk -l<\/code> within your KVM VPS to understand the current partition structure, guiding your resizing approach.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-184751.png\" target=\"_blank\" rel=\"noopener\"><img fetchpriority=\"high\" decoding=\"async\" width=\"802\" height=\"130\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-184751.png\" alt=\"\" class=\"wp-image-2379\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-184751.png 802w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-184751-300x49.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-184751-768x124.png 768w\" sizes=\"(max-width: 802px) 100vw, 802px\" \/><\/a><\/figure>\n\n\n\n<p>In the image above, you can see a representation of disk space, including a newly added 10GB of unallocated space. Unfortunately, allocating this space to vda1 is not possible due to the SWAP partition being positioned immediately after the current ROOT partition. This configuration hinders the expansion of the disk into the available unallocated space. Such a scenario is common when attempting to extend the ROOT partition after deploying an operating system on a VPS.<\/p>\n\n\n\n<pre class=\"wp-block-verse has-ast-global-color-5-color has-black-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-f3a39f78aacecbd1dbe29760669f6bf1\" style=\"font-style:normal;font-weight:300\">The procedures outlined in this knowledge base are based on the assumption that the disk is designated as \/dev\/vda. Please replace this reference with the appropriate disk identifier as indicated in the output of the <code>lsblk<\/code> command.<\/pre>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"proceeding-with-the-partition-extension\">Proceeding with the Partition Extension<\/h4>\n\n\n<p><strong>Disable and Remove Swap Partition<\/strong>:<br>First, disable the swap with <code>swapoff \/dev\/vda2<\/code>. Then, using <code>fdisk<\/code> or another partitioning tool, delete <code>vda2<\/code> to clear the pathway for extending <code>vda1<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>swapoff \/dev\/vda2<\/code><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>fdisk \/dev\/vda<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list has-small-font-size\">\n<li>Type &#8220;d&#8221; to delete a partition. Choose the partition associated with SWAP.<\/li>\n\n\n\n<li>Execute the changes and write them to the disk by executing &#8220;w&#8221;<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/swap-delete.gif\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"710\" height=\"494\" data-id=\"2380\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/swap-delete.gif\" alt=\"Disable and Remove Swap Partition\" class=\"wp-image-2380\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><br><strong>Create a SWAP Partition in the Last Sector:<\/strong><br>After deleting vda2, it is essential to create a new swap partition that is positioned at the terminal sector of the disk. This strategic placement ensures that unallocated space exists between the newly established SWAP partition and the vda1 (ROOT Partition). This configuration is crucial for maintaining contiguous disk sectors, which becomes instrumental when attempting to extend the \/vda1 partition in subsequent steps.<\/p>\n\n\n\n<p>Open the fdisk utility for the specified device:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fdisk \/dev\/vda<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"has-small-font-size\">Type &#8220;n&#8221; to create a new partition. Choose the default option, which is usually &#8220;Primary.&#8221;<\/li>\n\n\n\n<li class=\"has-small-font-size\">Accept the default partition number suggested by fdisk.<\/li>\n\n\n\n<li class=\"has-small-font-size\">Set the First sector to a value that is 1GB less than the last sector suggested on the screen. To calculate this, you may need to subtract the size of the partition you want (in this case, 1GB) from the last sector value displayed.<\/li>\n\n\n\n<li class=\"has-small-font-size\">Set the Last sector to the default value suggested by fdisk.<\/li>\n\n\n\n<li class=\"has-small-font-size\">Type &#8220;t&#8221; to change the partition type.<\/li>\n\n\n\n<li class=\"has-small-font-size\">Enter &#8220;82&#8221; as the value for the Hex code, as it was the ID of Linux Swap.<\/li>\n\n\n\n<li class=\"has-small-font-size\">Execute the changes and write them to the disk by executing &#8220;w&#8221;<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-221917.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" width=\"862\" height=\"666\" data-id=\"2382\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-221917.png\" alt=\"creating linux swap partition\" class=\"wp-image-2382\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-221917.png 862w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-221917-300x232.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-221917-768x593.png 768w\" sizes=\"(max-width: 862px) 100vw, 862px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Restart the VPS now!<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Format and Enable Swap:<\/strong><br>Format the new swap space with <code>mkswap \/dev\/vda2<\/code> and then enable it with <code>swapon \/dev\/vda2<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>mkswap \/dev\/vda2<\/code><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><code>swapon \/dev\/vda2<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-233610.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"543\" height=\"126\" data-id=\"2383\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-233610.png\" alt=\"formatting swap partition and enabling it\" class=\"wp-image-2383\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-233610.png 543w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-233610-300x70.png 300w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Resize the Filesystem<\/strong>:<br>Now to extend <code>vda1<\/code> , use <code>growpart \/dev\/vda 1<\/code> to grow the file system and then  <code>resize2fs \/dev\/vda1<\/code> to resize the filesystem to fill the extended partition.<\/p>\n\n\n\n<p>If the growpart utility is not installed on your VPS, install it with the installation commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get update\napt-get install cloud-guest-utils<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center\">OR<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum install cloud-utils-growpart<\/code><\/pre>\n\n\n\n<p>Followed by:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>growpart \/dev\/vda 1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-verse has-ast-global-color-5-color has-black-background-color has-text-color has-background has-link-color has-small-font-size wp-elements-4edbb18b0bb31ecdb64399658b96cf28\" style=\"font-style:normal;font-weight:300\">If any error occurs during executing the growpart command, reboot the server and try again!<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><code>resize2fs \/dev\/vda1<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-235202.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"810\" height=\"164\" data-id=\"2386\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-235202.png\" alt=\"Resizing the linux partition\" class=\"wp-image-2386\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-235202.png 810w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-235202-300x61.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-11-235202-768x155.png 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Reboot and Verify:<\/strong><br>Reboot your VPS and use <code><a href=\"https:\/\/www.scaler.com\/topics\/lsblk-command-in-linux\/\" target=\"_blank\" rel=\"noopener\">lsblk<\/a><\/code> or <code>df -Th<\/code> to verify that the changes have been applied correctly. Ensure that the swap is active using <code>swapon -s<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df -Th<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/2.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"637\" height=\"167\" data-id=\"2387\" src=\"https:\/\/www.veeble.org\/kb\/wp-content\/uploads\/2024\/01\/2.png\" alt=\"Check disk size in linux os\" class=\"wp-image-2387\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/2.png 637w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/2-300x79.png 300w\" sizes=\"(max-width: 637px) 100vw, 637px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>You have now successfully expanded your root disk!  Congrats \ud83c\udf89<\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-e226e73d wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Blazing Fast Hosting<\/h3><p class=\"uagb-cta__desc\">Experience lightning-fast speeds and rock-solid reliability with our cPanel hosting. Get your website online today!<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/cpanel-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Get Started Now<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>For many Linux users, one common requirement after boosting disk space on a KVM (Kernel-based Virtual Machine) VPS is to expand a partition. This [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":7784,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-2378","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/How-to-Extend-a-KVM-VPS-Root-Partition-After-Disk-Upgrade.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/How-to-Extend-a-KVM-VPS-Root-Partition-After-Disk-Upgrade-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/How-to-Extend-a-KVM-VPS-Root-Partition-After-Disk-Upgrade-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/How-to-Extend-a-KVM-VPS-Root-Partition-After-Disk-Upgrade-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/How-to-Extend-a-KVM-VPS-Root-Partition-After-Disk-Upgrade-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/How-to-Extend-a-KVM-VPS-Root-Partition-After-Disk-Upgrade.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2024\/01\/How-to-Extend-a-KVM-VPS-Root-Partition-After-Disk-Upgrade.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Adrian Antony","author_link":"https:\/\/www.veeble.com\/kb\/author\/adrian\/"},"uagb_comment_info":0,"uagb_excerpt":"For many Linux users, one common requirement after boosting disk space on a KVM (Kernel-based Virtual Machine) VPS is to expand a partition. This [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/2378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=2378"}],"version-history":[{"count":7,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/2378\/revisions"}],"predecessor-version":[{"id":8016,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/2378\/revisions\/8016"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/7784"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=2378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=2378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=2378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}