{"id":112,"date":"2015-03-16T21:33:23","date_gmt":"2015-03-16T21:33:23","guid":{"rendered":"https:\/\/www.nonamehosts.com\/blog\/?p=112"},"modified":"2015-03-16T21:33:23","modified_gmt":"2015-03-16T21:33:23","slug":"how-to-extend-ext4-root-partition-without-reboot","status":"publish","type":"post","link":"https:\/\/www.nonamehosts.com\/blog\/tutorials\/how-to-extend-ext4-root-partition-without-reboot\/","title":{"rendered":"How to extend ext4 root partition without reboot"},"content":{"rendered":"<p>Let&#8217;s say you want to extend existing disk on your already installed VM. Usually to extend the existing ext4 partition where system is running you would use some Live CD, to edit partition while it&#8217;s unmounted. However it&#8217;s possible to extend the partition without booting from Live CD. Here are some simple steps to do so:<\/p>\n<p><!--more--><\/p>\n<p>Here we see that we have disk bigger than already existing partition:<\/p>\n<pre class=\"lang:sh decode:true \">root@test:~# df -h \/\nFilesystem Size Used Avail Use% Mounted on\n\/dev\/vda1 24G 1008M 22G 5% \/\n\nroot@test:~#\u00a0fdisk -l \/dev\/vda\n\nDisk \/dev\/vda: 53.7 GB, 53687091200 bytes\n255 heads, 63 sectors\/track, 6527 cylinders, total 104857600 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x0009256d\n\n Device Boot Start End Blocks Id System\n\/dev\/vda1 * 2048 50329215 25163584 83 Linux\n\/dev\/vda2 50329216 52426367 1048576 82 Linux swap \/ Solaris\n\n<\/pre>\n<figure id=\"attachment_310\" aria-describedby=\"caption-attachment-310\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.nonamehosts.com\/shared-hosting\/\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-310 size-full\" src=\"https:\/\/www.nonamehosts.com\/blog\/wp-content\/uploads\/2015\/03\/web-offer12.png\" alt=\"web-offer\" width=\"800\" height=\"215\" \/><\/a><figcaption id=\"caption-attachment-310\" class=\"wp-caption-text\">Web hosting offer &#8211; \u20ac12\/year<\/figcaption><\/figure>\n<p>First of all you have to make sure to turn off swap:<\/p>\n<pre class=\"lang:sh decode:true\">root@test:~# swapoff -a\nroot@test:~# free -m\n             total       used       free     shared    buffers     cached\nMem:           994        189        804          0         11        140\n-\/+ buffers\/cache:         38        955\nSwap:            0          0          0\n\n#Make sure that you see zeroes in \"Swap:\" row<\/pre>\n<p>And now let&#8217;s remove swap partition and extend root partition. From previous fdisk command we can see that our swap partition is second one (\/dev\/vda2).<\/p>\n<p>In following steps we&#8217;re going to remove swap partition and root partition, create root partition with new size (size should be = [last sector] &#8211; [swap partition sector count]) and finally new swap partition with same size.<\/p>\n<pre class=\"lang:sh decode:true\">root@test:~# fdisk \/dev\/vda\n\nCommand (m for help): p\n\nDisk \/dev\/vda: 53.7 GB, 53687091200 bytes\n255 heads, 63 sectors\/track, 6527 cylinders, total 104857600 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x0009256d\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/vda1   *        2048    50329215    25163584   83  Linux\n\/dev\/vda2        50329216    52426367     1048576   82  Linux swap \/ Solaris\n\nCommand (m for help): d\nPartition number (1-4): 2\n\nCommand (m for help): d\nSelected partition 1\n\nCommand (m for help): n\nPartition type:\n   p   primary (0 primary, 0 extended, 4 free)\n   e   extended\nSelect (default p):\nUsing default response p\nPartition number (1-4, default 1):\nUsing default value 1\nFirst sector (2048-104857599, default 2048):\nUsing default value 2048\nLast sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +103809023\n\nCommand (m for help): n\nPartition type:\n   p   primary (1 primary, 0 extended, 3 free)\n   e   extended\nSelect (default p):\nUsing default response p\nPartition number (1-4, default 2):\nUsing default value 2\nFirst sector (103811072-104857599, default 103811072):\nUsing default value 103811072\nLast sector, +sectors or +size{K,M,G} (103811072-104857599, default 104857599):\nUsing default value 104857599\n\nCommand (m for help): p\n\nDisk \/dev\/vda: 53.7 GB, 53687091200 bytes\n255 heads, 63 sectors\/track, 6527 cylinders, total 104857600 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x0009256d\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/vda1            2048   103811071    51904512   83  Linux\n\/dev\/vda2       103811072   104857599      523264   83  Linux\n<\/pre>\n<p>Before writing changes to disk we have to set proper partition types and make root partition bootable:<\/p>\n<pre class=\"lang:sh decode:true \">Command (m for help): t\nPartition number (1-4): 1\nHex code (type L to list codes): 83\n\nCommand (m for help): t\nPartition number (1-4): 2\nHex code (type L to list codes): 82\nChanged system type of partition 2 to 82 (Linux swap \/ Solaris)\n\nCommand (m for help): a\nPartition number (1-4): 1\n\nCommand (m for help): p\n\nDisk \/dev\/vda: 53.7 GB, 53687091200 bytes\n255 heads, 63 sectors\/track, 6527 cylinders, total 104857600 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x0009256d\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/vda1   *        2048   103811071    51904512   83  Linux\n\/dev\/vda2       103811072   104857599      523264   82  Linux swap \/ Solaris<\/pre>\n<p>Now let&#8217;s write changes to disk and re-read partition table (to re-read partition table you can also reboot the VM) so the system could see new size:<\/p>\n<pre class=\"lang:sh decode:true \">Command (m for help): w\nThe partition table has been altered!\n\nCalling ioctl() to re-read partition table.\n\nWARNING: Re-reading the partition table failed with error 16: Device or resource busy.\nThe kernel still uses the old table. The new table will be used at\nthe next reboot or after you run partprobe(8) or kpartx(8)\nSyncing disks.\nroot@test:~# partprobe\nroot@test:~# fdisk -l\n\nDisk \/dev\/vda: 53.7 GB, 53687091200 bytes\n16 heads, 63 sectors\/track, 104025 cylinders, total 104857600 sectors\nUnits = sectors of 1 * 512 = 512 bytes\nSector size (logical\/physical): 512 bytes \/ 512 bytes\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\nDisk identifier: 0x0009256d\n\n   Device Boot      Start         End      Blocks   Id  System\n\/dev\/vda1   *        2048   103811071    51904512   83  Linux\n\/dev\/vda2       103811072   104857599      523264   82  Linux swap \/ Solaris<\/pre>\n<p>Now we can see that we have new partition table with resized partitions, however root partition&#8217;s filesystem has to be resized as well. It&#8217;s one simple step left:<\/p>\n<pre class=\"lang:sh decode:true \">root@test:~# resize2fs \/dev\/vda1\nresize2fs 1.42.9 (4-Feb-2014)\nFilesystem at \/dev\/vda1 is mounted on \/; on-line resizing required\nold_desc_blocks = 2, new_desc_blocks = 4\nThe filesystem on \/dev\/vda1 is now 12976128 blocks long.\n\nroot@test:~# df -h \/\nFilesystem      Size  Used Avail Use% Mounted on\n\/dev\/vda1        49G 1009M   46G   3% \/<\/pre>\n<p>Resize2fs did the trick and you can see that we have 49G partition now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say you want to extend existing disk on your already installed VM. Usually to extend the existing ext4 partition where system is running you would use some Live CD, to edit partition while it&#8217;s unmounted. However it&#8217;s possible to extend the partition without booting from Live CD. Here are some simple steps to do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[38,39,57,68,88,92,93,109,110,111,115],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-extend","tag-fdisk","tag-howto","tag-linux","tag-online","tag-partition","tag-partprobe","tag-resize","tag-resize2fs","tag-root","tag-server"],"_links":{"self":[{"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":0,"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nonamehosts.com\/blog\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}