{"id":1223,"date":"2021-08-11T02:45:43","date_gmt":"2021-08-11T05:45:43","guid":{"rendered":"https:\/\/blog.abratel.com.br\/?p=1223"},"modified":"2021-08-11T02:48:56","modified_gmt":"2021-08-11T05:48:56","slug":"how-to-increase-extend-the-root-partition-in-linux-using-the-fdisk-utility","status":"publish","type":"post","link":"https:\/\/blog.abratel.com.br\/?p=1223","title":{"rendered":"How To Increase \/ Extend The Root (\/) Partition In Linux Using The fdisk Utility"},"content":{"rendered":"<p>================= phpvirtualbox side =================<\/p>\n<p>For phpvirtualbox you should use the command line commands:<br \/>\nRoot or use sudo<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nVBoxManage clonehd [old.vmdk] [newVDI]\nor\nVBoxManage clonehd [old.vdi] [newVDI]\n\nVBoxManage modifyhd [VDI] --resize [60000]\n#60000 = 60gb\n\nVBoxManage clonehd [new-VDI] [newnew-VDI] --variant Fixed\n<\/pre>\n<p>After that return to the phpvirtualbox. You have to go to virtualbox-&gt;VM settings-&gt;storage-&gt;click on VM.vdi and remove, than add the newVDI.<\/p>\n<p>On right side, you will get disk icon, just click on it and browse your new VDI that has been created after resizing(new-VDI or newnew-VDI in above case)<\/p>\n<p>================= Linux Side =================<\/p>\n<p>NOTE 1: Take a backup of your system if you can. If it a VM on Azure or any other cloud services provider, take the snapshot of the OS disk<\/p>\n<p>NOTE 2: The reason for the backup is to roll back if anything goes wrong. If your filesystem is healthy, it is very rare for an issue to occur. These steps are the steps I usually take and have used in a production environment before and was successful. So, no worries.<\/p>\n<p>NOTE 3: When you use the \u201cd\u201d option to delete the partition and use the \u201cn\u201d option afterward, what you are doing is actually creating a partition table and remains in memory and not deleting the whole partition, so no worries.<\/p>\n<p>Step By Step Process<br \/>\n1. verify the root (\/) filesystem size<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndf -h\n\n[root@~]# lsblk\n\nNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\nsda      8:0    0   15G  0 disk\n\u251c\u2500sda1   8:1    0  238M  0 part \/boot\n\u251c\u2500sda2   8:2    0  200M  0 part [SWAP]\n\u2514\u2500sda3   8:3    0  6.5G  0 part \/\nsr0     11:0    1  7.3G  0 rom  \/run\/media\/root\/RHEL-8-1-0-BaseOS-x86_64\n\n<\/pre>\n<p>2. verify the root(\/) filesystem type<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n[root@~]# lsblk -fs \/dev\/sda3\n\nNAME  FSTYPE LABEL UUID                                 MOUNTPOINT\nsda3  xfs          0ba4bfe5-9f93-4725-bea2-b0d9c5175bbf \/\n\u2514\u2500sda\nYou can see that the root filesystem type is \u201cxfs\u201d\n<\/pre>\n<p>3. Initialize \/dev\/sda using the fdisk utility<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n[root@~]# fdisk \/dev\/sda\n\nWelcome to fdisk (util-linux 2.32.1).\nChanges will remain in memory only, until you decide to write them.\nBe careful before using the write command.\nenter the letter \u201cp\u201d to print all the partitions on sda\n\nCommand (m for help): p\nDisk \/dev\/sda: 15 GiB, 16106127360 bytes, 31457280 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\nDisklabel type: dos\nDisk identifier: 0x9550a04d\n\nDevice     Boot  Start      End  Sectors  Size Id Type\n\/dev\/sda1  *      2048   489471   487424  238M 83 Linux\n\/dev\/sda2       489472   899071   409600  200M 82 Linux swap \/ Solaris\n\/dev\/sda3       899072 14569471 13670400  6.5G 83 Linux\n\nCommand (m for help):\nenter the letter \u201cd\u201dto delete a partition\n\nCommand (m for help): d\nPartition number (1-3, default 3):\nenter the partition number 3 or press enter to leave it at default which is 3\n\nPartition 3 has been deleted.\nNOW, ENTER THE LETTER \u201cn\u201d TO RECREATE THE PARTITION TO YOUR DESIRED SIZE\n\nCommand (m for help): n\nPartition type\np   primary (2 primary, 0 extended, 2 free)\ne   extended (container for logical partitions)\nSelect (default p):\nenter the letter \u201cp\u201d to make it a primary partition, yours might be secondary depending on the number of partitions you have. A disk can have only four partitions as primary partitions\n\nSelect (default p): p\nPartition number (3,4, default 3):\nenter the partition number which is 3 or press enter to leave at default which is 3\n\nPartition number (3,4, default 3):\nFirst sector (899072-31457279, default 899072):\npress the enter key again to get to the last sector\n\nLast sector, +sectors or +size{K,M,G,T,P} (899072-31457279, default 31457279):\nenter the new partition size or press the enter key to use the whole available space on sda. In this scenario, we are using the whole available space\n\nLast sector, +sectors or +size{K,M,G,T,P} (899072-31457279, default 31457279):\n\nCreated a new partition 3 of type 'Linux' and of size 14.6 GiB.\nPartition #3 contains a xfs signature.\n\nDo you want to remove the signature? [Y]es\/[N]o:\nenter \u201cno\u201d not to remove the signature\n\nDo you want to remove the signature? [Y]es\/[N]o: no\n\nCommand (m for help):\nenter the letter \u201cw\u201d to write or save the changes and press enter\n\nCommand (m for help): w\nThe partition table has been altered.\nSyncing disks.\n\nAdditional Article : How To Protect A Disk\/Filesystem In Linux\n<\/pre>\n<p>4. verify the partition increment<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n[root@~]# reboot\n\n[root@~]# lsblk\n\nNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\nsda      8:0    0   15G  0 disk\n\u251c\u2500sda1   8:1    0  238M  0 part \/boot\n\u251c\u2500sda2   8:2    0  200M  0 part [SWAP]\n\u2514\u2500sda3   8:3    0 14.6G  0 part \/\nsr0     11:0    1  7.3G  0 rom  \/run\/media\/root\/RHEL-8-1-0-BaseOS-x86_64\n[root@~]#\n<\/pre>\n<p>5. resize the filesystem,<br \/>\nIf the filesystem is xfs, use the command,<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n[root@~]# xfs_growfs \/dev\/sda3\n\nxfs_growfs: \/dev\/sda3 is not a mounted XFS filesystem\n<\/pre>\n<p>If you get the error above, use the command,<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n[root@ ~]# xfs_growfs \/\n\nmeta-data=\/dev\/sda3              isize=512    agcount=9, agsize=427200 blks\n=                       sectsz=512   attr=2, projid32bit=1\n=                       crc=1        finobt=1, sparse=1,\n.........\nIf the filesystem is ext (2,3,4), use \u201cresize2fs\u201d instead\n\n[root@Tekneed ~]# resize2fs \/dev\/sda3\n[root@Tekneed ~]# resize2fs \/\n<\/pre>\n<p>6. you may also run the command below to make immediate changes to the kernel<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n[root@~]# partprobe\n<\/pre>\n<p>7. verify the filesystem new size<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n[root@~]# df -h\n\nFilesystem      Size  Used Avail Use% Mounted on\ndevtmpfs        887M     0  887M   0% \/dev\ntmpfs           904M     0  904M   0% \/dev\/shm\ntmpfs           904M  9.7M  894M   2% \/run\ntmpfs           904M     0  904M   0% \/sys\/fs\/cgroup\n\/dev\/sda3        15G  4.2G   11G  29% \/\n\/dev\/sda1       233M  150M   84M  65% \/boot\ntmpfs           181M  1.2M  180M   1% \/run\/user\/42\ntmpfs           181M  4.6M  177M   3% \/run\/user\/0\n\/dev\/sr0        7.4G  7.4G     0 100% \/run\/media\/root\/RHEL-8-1-0-BaseOS-x86_64\n\n<\/pre>\n<p>extend root partition using fdisk<br \/>\nYou can see that the size has increased.<\/p>\n<p>After that I remove the other ones .vdi that I was not using more.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>================= phpvirtualbox side ================= For phpvirtualbox you should use the command line commands: Root or use sudo After that return to the phpvirtualbox. You have to go to virtualbox-&gt;VM settings-&gt;storage-&gt;click on VM.vdi and remove, than add the newVDI. On right side, you will get disk&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1228,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1223"}],"collection":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1223"}],"version-history":[{"count":3,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1223\/revisions"}],"predecessor-version":[{"id":1230,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1223\/revisions\/1230"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/media\/1228"}],"wp:attachment":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}