1

I've got a virtual Ubuntu 18.04 server which is running low on disk space. As this is a virtual server I increased the hard disk size in vSphere. I can see the free space in cfdisk but am unsure how to expand the filesystem partition to take advantage of the new space. I can see there is a resize option for the partition but I'm unclear on whether or not that will also format the partitions and lose my data... Bit of a linux n00b, any help would be greatly appreciated.

cfdisk output:

Device         Start        End       Sectors    Size  Type

/dev/sda1       2048       4095          2048      1M  BIOS boot
/dev/sda2       4096   41940991      41936896     20G  Linux filesystem
Free space  41940992  104857566      62916575     30G  

Thanks!

3 Answers 3

4

For the n00b: Connect with X forwarding enabled (ssh -X yourserver), install gparted and use the user-friendly GUI to resize /dev/sda2.

A more advanced user would probably fire up parted /dev/sda, then enter resizepart 2. The end of the partition will automatically be selected to match the end of the disk. This will only resize the partition, though. The file-system can be resized to span the whole partition with the appropriate tool, like resize2fs /dev/sda2 for ext2/3/4.

0

As an additional note: In this case (free space after the end of the partition which will be resized) it should be possible to resize the partition by:

growpart /dev/sda 2

You can install growpart by installing the package: cloud-guest-utils.

Just as a note: There is always a risk of losing data when performing this kind of operations on disks/partitions.

1
  • Good point. Yet I want to add that data-loss during online growing is so very unlikely, I consider it safe.
    – Hermann
    Feb 1, 2020 at 15:44
0

I was seeking to do the same as the OP. My only difference is that I am using Ubuntu 20.04 LTS server.

I had not tried cfdisk yet to see such info (I tried df and lsblk), so I went ahead and ran cfdisk.

I was surprised that cfdisk itself had an option to [Resize] my disk right there. No need to use other tools, I just went and navigated to my sda, and selected the [Resize] Option. Including a screenshot for reference:

enter image description here

Of course now one has to resize the actual filesystem, etc.. I didn't recall exactly how to do it, but I did remember that I wrote an answer here a month ago where I summed up such steps (sharing it in case it helps someone else) https://askubuntu.com/a/1393329/658154

Basically resize the Physical Volume (pvresize), and then resize the Logical Volume (lvextend) to finally resize the filesystem (resize2fs).

4
  • 1
    If you use lvresize -r -l 100%FREE /dev/mapper/... after the pvresize the file system will be extended without any further commands.
    – doneal24
    Mar 29 at 21:17
  • @doneal24 thanks for the tip :) will try it next time I have to resize a machine
    – DarkCygnus
    Mar 29 at 21:24
  • 1
    If you do it right you can resize the disk in vSphere and expand the lv from the command line with no downtime. Very useful for production servers.
    – doneal24
    Mar 29 at 21:27
  • @doneal24 I have ESXI, but not the vSphere suite (yet?). I've heard that vSphere is quite useful, and your comment confirmed that to me. Thus why I have to do it more manually: edit the machine, expand the vdisk, and then the steps mentioned inside the machine... Thanks for that observation, as it makes me realize vSphere is something we should get :)
    – DarkCygnus
    Mar 29 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.