How to expand the ubuntu LVM partition of the VirtualBox virtual machine

I got an error message when installing Cloud Foundry in ubuntu with VirtualBox, not enough disk space:

 
 

After cleaning up with these three commands, the results are still not ideal:

(1) sudo apt-get autoclean (installation package of uninstalled software)

(2) sudo apt-get clean (installation packages that do not uninstall software)

(3) Clean up orphaned packages that are no longer needed by the system. sudo apt-get autoremove

 

So I decided to resize Ubuntu's virtual machine disk to 30G.

The current disk space can be viewed through the command line VBoxManage.exe list hdds.

 

Use the command VBoxManage.exe modifyhd <disk guid> --resize <new size> to change the size. After I changed it to 30G,

 

In VirtualBox I have seen that the size takes effect.

 

The ubuntu command sudo fdisk -l can see that the new disk size has taken effect.

 

But the filesystem size as viewed by df -H remains unchanged.

 

Use the command sudo fdisk /dev/sda, then select n to create a new partition, type p, and select 3 for the number. Note here that the start position of the new partition should be next to the end position of the existing Linux LVM partition, as shown in the following figure. As for the end position, I simply specified to add 15G, so the end position is calculated dynamically.

 

The following information shows that the partition has been created successfully.

 

Change the type of the newly created partition to 8e:Linux LVM

 
 
 

The next step is to create a new Physical volume: sudo pvcreate /dev/sda3

 

sudo pvscan shows that the physical volume has not been assigned to the volume group ubuntu-vg

 

Assign using the command sudo vgextend ubuntu-vg /dev/sda3:

 

Assignment complete.

 

Then modify the size of the volume group: sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-root

 

last step:

sudo resize2fs /dev/mapper/ubuntu--vg-root

 

现在/目录的大小已经成功扩容了:

 

 

要获取更多Jerry的原创技术文章,请关注公众号"汪子熙"或者扫描下面二维码:

 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326044717&siteId=291194637