2 minutes
Expanding Partition on Linux [en]
Expanding a partition on Linux (Virtualization) typically involves a few steps. Here’s a guide on how to do it using the parted utility. Before proceeding, make sure you have backups of important data, as resizing partitions carries some risk.
For LVM
-
Rescan Disk without restart machine
sudo echo 1>/sys/class/block/sda/device/rescan
-
Check Disk space after expanding partition on same disk
sudo fdisk -l #used for list all disk
if there are red text on the list, just type
w
for rewrite block, there are no affected to file inside partition. -
Use parted to Resize Partitions
-
Check Partition Layout
sudo parted /dev/sdX print
Replace /dev/sdX with the appropriate device name for your disk (for example, /dev/sda).
-
Resize the Partition
sudo parted resizepart X 100%
this command resizes partition X (we can just change X with partition number ex: 1 or 2 etc) to use 100% of the available space.
-
-
Check Physical Volume Status (PVS) on LVM
sudo pvs
-
Resize the Physical Volume
sudo pvresize /dev/sdXY sudo pvdisplay /dev/sdXY
this first command used for resize the physical volume and the second one used for show PV data size
Replace /dev/sdXY with the appropriate device name for your disk (for example, /dev/sda3).
-
Check Logical Volume Status (LVS)
sudo lvs
-
Expand the Logical Volume
sudo lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Replace /dev/mapper/ubuntu–vg-ubuntu–lv with your LVM name.
-
Resize the the volume
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Replace /dev/mapper/ubuntu–vg-ubuntu–lv with your LVM name.
For Dedicated Mounted Drive
-
Rescan Disk without restart machine
sudo echo 1>/sys/class/block/sda/device/rescan
-
Check Disk space after expanding partition on same disk
sudo fdisk -l #used for list all disk
if there are red text on the list, just type
w
for rewrite block, there are no affected to file inside partition. -
Use parted to Resize Partitions
-
Check Partition Layout
sudo parted /dev/sdX print
Replace /dev/sdX with the appropriate device name for your disk (for example, /dev/sda).
-
Resize the Partition
sudo parted resizepart X 100%
this command resizes partition X (we can just change X with partition number ex: 1 or 2 etc) to use 100% of the available space.
-
-
Resize the the volume
sudo resize2fs /dev/sdXY
Replace /dev/sdXY with your LVM name.