4

I have a windows server inside of which there's an Ubuntu 22.10 server, more space was given to VM of Ubuntu. But inside of Ubuntu, when I connect through SSH, it shows that it's still the same size. So I guess it's because I need to manually add this new space to root partition. How do I do it using terminal? Since I connect through SSH, I don't have access to gui. My disks look like this now:

sda                         8:0    0    50G  0 disk 
├─sda1                      8:1    0     1M  0 part 
├─sda2                      8:2    0     2G  0 part /boot
└─sda3                      8:3    0    48G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0  11.5G  0 lvm  /

How do I add more space to sda3? Or it's impossible to do through ssh and should be done through Windows Server somehow? I tried this command but it didn't work:

$ sudo resize2fs /sda3 4G
resize2fs 1.46.5 (30-Dec-2021)
open: No such file or directory while opening /sda3

I tried this command, it also didn't work:

$ sudo lvresize --verbose --resizefs -L +2G "/dev/sda3/ubuntu--vg-ubuntu--lv"
  VG name on command line not found in list of VGs: sda3
  Volume group "sda3" not found
  Cannot process volume group sda3
sudo lvresize --verbose --resizefs -L +2G /dev/sda3
  "/dev/sda3": Invalid path for Logical Volume.
  Run `lvresize --help' for more information.

3 Answers 3

10

Okay, this helped me: To add more space to the Ubuntu partition (/) inside the LVM volume group (ubuntu-vg) on Ubuntu VM running within a Windows Server host, you need to follow these steps:

  1. Resize the Partition: Once the virtual disk is larger, you need to resize the partition (sda3) to occupy the additional space. You can use the fdisk or parted utility to do this:

    • If you're using fdisk, run:

      sudo fdisk /dev/sda
      

      Then, delete and recreate partition 3 (sda3) with the new size, making sure it covers the entire available space. After making the changes, save and exit.

    • If you're using parted, run:

      sudo parted /dev/sda
      (parted) resizepart 3
      

      Follow the prompts to resize the partition to occupy the entire available space.

  2. Resize the LVM Physical Volume: Now that the partition is resized, you need to resize the LVM Physical Volume (PV) to recognize the increased space. Run the following command:

    sudo pvresize /dev/sda3
    
  3. Extend the Logical Volume (LV): After resizing the PV, you can extend the LV (/dev/ubuntu-vg/ubuntu-lv) to use the newly available space. Use the lvextend command:

    sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
    

    This command extends the LV to use 100% of the available free space in the VG.

  4. Resize the Filesystem: Finally, you should resize the filesystem to utilize the newly allocated space:

    sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
    

    This command resizes the filesystem to match the size of the LV.

After completing these steps, your Ubuntu partition should have been successfully resized to utilize the additional space.

0

You cannot shrink/edit a partition if any of the partitions on the disk are mounted.

The simplest method might be to specify as the DVD of the VM an ISO containing a bootable partition editor, perhaps GParted. Boot the VM from this DVD and resize the partition to fill up the allocated additional space. Shutdown the VM, remove the ISO and reboot.

I would suggest taking a backup copy of the VM itself before doing this procedure.

For more information see the post
How do I resize partitions using command line without using a GUI on a server?

Note that there are some file-systems that allow resize when the partition is mounted, such as LVM and btrfs. If this is your case, you will find the required commands in the above post.

1
  • I added more details
    – Arzybek
    Commented Sep 27, 2023 at 10:46
0

In the first step, you can simply write sudo parted -s -a opt /dev/sda "resizepart 3 100%"

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 7 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .