The following article will show you how to increase disk space in GPT standard on Linux operating system
Note: This article only works on standard GPT partitions
FIRST NEED TO DETERMINATE WHAT THE DISTRIBUTION IS GPT OR MBR
Use command parted
to determine if the partition created is GPT or MBR
MBR partition
After typing the command parted
and press Enter, the drive partition table will appear as below and tell us if the partition is currently MBR
[user@myvm ~]# parted -l /dev/sda
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 525MB 524MB primary ext4 boot
2 525MB 34.4GB 33.8GB primary ext4
[user@myvm ~]#
GPT partition
After typing the command parted
and press Enter, the drive partition table will appear as below and tell us if the partition is GPT
[user@myvm ~]# parted -l /dev/sda
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 525MB 524MB fat16 EFI System Partition boot
2 525MB 1050MB 524MB xfs
3 1050MB 1052MB 2097kB bios_grub
4 1052MB 68.7GB 67.7GB lvm
If the machine partition is GPT, we can proceed to resize the virtual machine drive. Resize partition drive
Resize partition drive
Note: Backup all data, VM or create snapshot before doing resize
UBUNTU
To increase disk space on Ubuntu operating system:
- Shutdown VM
- increase capacity through server management such as esxi, proxmox.vcenter ....
- Restart VM, login as root
- Check whether the disk space parameter has been increased or not
As the example below, the drive partition has been increased to 100GB at /dev/sda1
user@myvm:~# df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 314M 0 314M 0% /dev
tmpfs tmpfs 65M 2.3M 63M 4% /run
/dev/sda1 ext4 97G 1.8G 95G 2% /
tmpfs tmpfs 324M 0 324M 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs tmpfs 324M 0 324M 0% /sys/fs/cgroup
/dev/sda15 vfat 105M 3.6M 101M 4% /boot/efi
/dev/sdb1 ext4 20G 44M 19G 1% /mnt
tmpfs tmpfs 65M 0 65M 0% /run/user/1000
user@myvm:~#
SUSE
To increase disk space on SUSE 12 SP4, SUSE SLES 12 for SAP, SUSE SLES 15, and SUSE SLES 15 for SAP:
- Shutdown VM
- increase capacity via server manager
- Restart VM
Once the VM has been restarted, follow these steps:
- Access the VM as root with the following command:
# sudo -i
- Use the following command to install the package growpart, which will be needed to resize the partition:
# zypper install growpart
- Use command
lsblk
to find the mounted partition on the root of the file system, in this case the partition sda4 being mounted with :/
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 48G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 512M 0 part /boot/efi
├─sda3 8:3 0 1G 0 part /boot
└─sda4 8:4 0 28.5G 0 part /
sdb 8:16 0 4G 0 disk
└─sdb1 8:17 0 4G 0 part /mnt/resource
- Resize the partition specified in the previous step with the command
growpart
:
# growpart /dev/sda 4
CHANGED: partition=4 start=3151872 old: size=59762655 end=62914527 new: size=97511391 end=100663263
- Run command
lsblk
to check if the partition has been increased or not. As the example below, partition /dev/sda4 has been increased to 46.5 GB:
linux:~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 48G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 512M 0 part /boot/efi
├─sda3 8:3 0 1G 0 part /boot
└─sda4 8:4 0 46.5G 0 part /
sdb 8:16 0 4G 0 disk
└─sdb1 8:17 0 4G 0 part /mnt/resource
- Specify the disk format type using the command
lsblk
with option-f
linux:~ # lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1
├─sda2 vfat EFI AC67-D22D /boot/efi
├─sda3 xfs BOOT 5731a128-db36-4899-b3d2-eb5ae8126188 /boot
└─sda4 xfs ROOT 70f83359-c7f2-4409-bba5-37b07534af96 /
sdb
└─sdb1 ext4 8c4ca904-cd93-4939-b240-fb45401e2ec6 /mnt/resource
According to the disk format, use the appropriate command to resize the system partition:
- With xfs, use the following command:
#xfs_growfs /
linux:~ # xfs_growfs /
meta-data=/dev/sda4 isize=512 agcount=4, agsize=1867583 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0 rmapbt=0
= reflink=0
data = bsize=4096 blocks=7470331, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3647, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7470331 to 12188923
- With ext4, use the following command:
#resize2fs /dev/sda4
- Check the disk space parameter has been increased with the command
df -Th
#df -Thl
linux:~ # df -Thl
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 445M 4.0K 445M 1% /dev
tmpfs tmpfs 458M 0 458M 0% /dev/shm
tmpfs tmpfs 458M 14M 445M 3% /run
tmpfs tmpfs 458M 0 458M 0% /sys/fs/cgroup
/dev/sda4 xfs 47G 2.2G 45G 5% /
/dev/sda3 xfs 1014M 86M 929M 9% /boot
/dev/sda2 vfat 512M 1.1M 511M 1% /boot/efi
/dev/sdb1 ext4 3.9G 16M 3.7G 1% /mnt/resource
tmpfs tmpfs 92M 0 92M 0% /run/user/1000
tmpfs tmpfs 92M 0 92M 0% /run/user/490
RHEL with LVM
- Access the VM as root with the following command:
- Use the lsblk command to determine which partition is currently mounted with root (/) in the system. In this case, we can see rootvg-rootlv is being mounted with /. If you want to mount with another file, you can replace the partition and mount point with another in the following way:
- Check if there is an empty partition in the LVM group containing the root partition. If so, you can skip to step 12.
- To add disk space on RHEL 7.x with LVM:
[root@dd-rhel7vm ~]# sudo -i
[root@dd-rhel7vm ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
fd0
sda
├─sda1 vfat C13D-C339 /boot/efi
├─sda2 xfs 8cc4c23c-fa7b-4a4d-bba8-4108b7ac0135 /boot
├─sda3
└─sda4 LVM2_member zx0Lio-2YsN-ukmz-BvAY-LCKb-kRU0-ReRBzh
├─rootvg-tmplv xfs 174c3c3a-9e65-409a-af59-5204a5c00550 /tmp
├─rootvg-usrlv xfs a48dbaac-75d4-4cf6-a5e6-dcd3ffed9af1 /usr
├─rootvg-optlv xfs 85fe8660-9acb-48b8-98aa-bf16f14b9587 /opt
├─rootvg-homelv xfs b22432b1-c905-492b-a27f-199c1a6497e7 /home
├─rootvg-varlv xfs 24ad0b4e-1b6b-45e7-9605-8aca02d20d22 /var
└─rootvg-rootlv xfs 4f3e6f40-61bf-4866-a7ae-5c6a94675193 /
[root@dd-rhel7vm ~]# vgdisplay rootvg
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 6
Open LV 6
Max PV 0
Cur PV 1
Act PV 1
VG Size <63.02 GiB
PE Size 4.00 MiB
Total PE 16132
Alloc PE / Size 6400 / 25.00 GiB
Free PE / Size 9732 / <38.02 GiB
VG UUID lPUfnV-3aYT-zDJJ-JaPX-L2d7-n8sL-A9AgJb
In this case, the line Free PE / Size shows 38.02GB free in partition. You do not need to resize the disk before adding space to the partition
- shutdown VM
- Increase disk space through server manager
- Re-enable the VM
Install the package cloud-utils-growpart to run the growpart command. This command is used to increase the OS disk size and the gdisk handler for GPT.
[root@dd-rhel7vm ~]# yum install cloud-utils-growpart gdisk
pvscan
. Note that the disk size and the free disk are enclosed in [ ][root@dd-rhel7vm ~]# pvscan
PV /dev/sda4 VG rootvg lvm2 [<63.02 GiB / <38.02 GiB free]
lsblk
[root@dd-rhel7vm ~]# lsblk /dev/sda4
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda4 8:4 0 63G 0 part
├─rootvg-tmplv 253:1 0 2G 0 lvm /tmp
├─rootvg-usrlv 253:2 0 10G 0 lvm /usr
├─rootvg-optlv 253:3 0 2G 0 lvm /opt
├─rootvg-homelv 253:4 0 1G 0 lvm /home
├─rootvg-varlv 253:5 0 8G 0 lvm /var
└─rootvg-rootlv 253:6 0 2G 0 lvm /
[root@dd-rhel7vm ~]# growpart /dev/sda 4
CHANGED: partition=4 start=2054144 old: size=132161536 end=134215680 new: size=199272414 end=201326558
lsblk
to check if the partition has been increased or not. As the example below, partition sda4 has been increased from 63GB to 95GB:[root@dd-rhel7vm ~]# lsblk /dev/sda4
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda4 8:4 0 95G 0 part
├─rootvg-tmplv 253:1 0 2G 0 lvm /tmp
├─rootvg-usrlv 253:2 0 10G 0 lvm /usr
├─rootvg-optlv 253:3 0 2G 0 lvm /opt
├─rootvg-homelv 253:4 0 1G 0 lvm /home
├─rootvg-varlv 253:5 0 8G 0 lvm /var
└─rootvg-rootlv 253:6 0 2G 0 lvm /
[root@dd-rhel7vm ~]# pvresize /dev/sda4
Physical volume "/dev/sda4" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@dd-rhel7vm ~]# pvscan
PV /dev/sda4 VG rootvg lvm2 [<95.02 GiB / <70.02 GiB free]
[root@dd-rhel7vm ~]# lvresize -r -L +10G /dev/mapper/rootvg-rootlv
Eg:
[root@dd-rhel7vm ~]# lvresize -r -L +10G /dev/mapper/rootvg-rootlv
Size of logical volume rootvg/rootlv changed from 2.00 GiB (512 extents) to 12.00 GiB (3072 extents).
Logical volume rootvg/rootlv successfully resized.
meta-data=/dev/mapper/rootvg-rootlv isize=512 agcount=4, agsize=131072 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 524288 to 3145728
lvresize
will automatically invoke the appropriate resize command for the system file in the partition (LV). Give it a check /dev/mapper/rootvg-rootlv mounted on / whether or not to increase the system file size with the following command:[root@dd-rhel7vm ~]# df -Th /
Eg:
[root@dd-rhel7vm ~]# df -Th /
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv xfs 12G 71M 12G 1% /
[root@dd-rhel7vm ~]#
RHEL RAW
To increase disk space on RHEL RAW:
- shutdown VM
- Increase disk space through server manager
- Re-enable the VM
Once the VM has been turned on, proceed as follows:
- Access the VM as root with the command below:
- When the VM has finished rebooting, follow the steps below:
[root@dd-rhel7vm ~]# sudo -i
- Install the package cloud-utils-growpart to run the growpart command. This command is used to increase the OS disk size and the gdisk handler for GPT.
[root@dd-rhel7vm ~]# yum install cloud-utils-growpart gdisk
[root@vm-dd-cent7 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs 2a7bb59d-6a71-4841-a3c6-cba23413a5d2 /boot
├─sda2 xfs 148be922-e3ec-43b5-8705-69786b522b05 /
├─sda14
└─sda15 vfat 788D-DC65 /boot/efi
sdb
└─sdb1 ext4 923f51ff-acbd-4b91-b01b-c56140920098 /mnt/resource
gdisk
. In this example, we see a 48GB disk with 2 29GB partitions. Disk has been raised from 30 to 48GB using Azure manager[root@vm-dd-cent7 ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 100663296 sectors, 48.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 78CDF84D-9C8E-4B9F-8978-8C496A1BEC83
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 62914526
Partitions will be aligned on 2048-sector boundaries
Total free space is 6076 sectors (3.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 1026048 2050047 500.0 MiB 0700
2 2050048 62912511 29.0 GiB 0700
14 2048 10239 4.0 MiB EF02
15 10240 1024000 495.0 MiB EF00 EFI System Partition
growpart
. Doing so will extend the specified partition and use all the space on the drive.[root@vm-dd-cent7 ~]# growpart /dev/sda 2
CHANGED: partition=2 start=2050048 old: size=60862464 end=62912512 new: size=98613214 end=100663262
gdisk
, we can see partition 2 has been raised to 47GB [root@vm-dd-cent7 ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 100663296 sectors, 48.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 78CDF84D-9C8E-4B9F-8978-8C496A1BEC83
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 100663262
Partitions will be aligned on 2048-sector boundaries
Total free space is 4062 sectors (2.0 MiB)
Number Start (sector) End (sector) Size Code Name
1 1026048 2050047 500.0 MiB 0700
2 2050048 100663261 47.0 GiB 0700
14 2048 10239 4.0 MiB EF02
15 10240 1024000 495.0 MiB EF00 EFI System Partition
xfs_growfs
[root@vm-dd-cent7 ~]# xfs_growfs /
meta-data=/dev/sda2 isize=512 agcount=4, agsize=1901952 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=7607808, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3714, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7607808 to 12326651
df
[root@vm-dd-cent7 ~]# df -hl
Filesystem Size Used Avail Use% Mounted on
devtmpfs 452M 0 452M 0% /dev
tmpfs 464M 0 464M 0% /dev/shm
tmpfs 464M 6.8M 457M 2% /run
tmpfs 464M 0 464M 0% /sys/fs/cgroup
/dev/sda2 48G 2.1G 46G 5% /
/dev/sda1 494M 65M 430M 13% /boot
/dev/sda15 495M 12M 484M 3% /boot/efi
/dev/sdb1 3.9G 16M 3.7G 1% /mnt/resource
tmpfs 93M 0 93M 0% /run/user/1000
Cao Thang – BKNS Technical
Post a Comment
Post a Comment