Skip to content

Commit a2ba063

Browse files
committed
created new dociment for os disk
1 parent 8bad4e8 commit a2ba063

File tree

2 files changed

+290
-0
lines changed

2 files changed

+290
-0
lines changed
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
---
2+
title: Resize OS Disk having GPT Partition.
3+
description: This article provides instructions to resize the OS Disk having GPT Partition.
4+
author: kailashmsft
5+
ms.service: security
6+
ms.topic: article
7+
ms.author: kaib
8+
ms.date: 05/03/2020
9+
10+
ms.custom: seodec18
11+
12+
---
13+
14+
15+
# Resize OS Disk having GPT Partition.
16+
17+
**This scenario applies only for OS Disk having GPT Partition.**
18+
This article describes how to increase the OS Disk having GPT partition in linux.
19+
20+
## How to identify if OS Disk is having GPT (or) GPT Partition.
21+
22+
There are many ways in which you can Identify if the Disk is partitioned using MBR (or) GPT partitions.
23+
24+
**parted** command is used to identify if the disk partition has been created using MBR (or) GPT partition.
25+
26+
Example for **MBR** Partition:
27+
28+
```
29+
[root@rhel6 ~]# parted -l /dev/sda
30+
Model: Msft Virtual Disk (scsi)
31+
Disk /dev/sda: 107GB
32+
Sector size (logical/physical): 512B/512B
33+
Partition Table: msdos
34+
Number Start End Size Type File system Flags
35+
1 1049kB 525MB 524MB primary ext4 boot
36+
2 525MB 34.4GB 33.8GB primary ext4
37+
[root@rhel6 ~]#
38+
```
39+
In the above output, we have to look for "Partition Table".
40+
We could see that the value is **msdos**, which means the disk is having "MBR" Partition.
41+
42+
Example for **GPT** Partition.
43+
44+
```
45+
[root@rhel7lvm ~]# parted -l /dev/sda
46+
Model: Msft Virtual Disk (scsi)
47+
Disk /dev/sda: 68.7GB
48+
Sector size (logical/physical): 512B/512B
49+
Partition Table: gpt
50+
Disk Flags:
51+
52+
Number Start End Size File system Name Flags
53+
1 1049kB 525MB 524MB fat16 EFI System Partition boot
54+
2 525MB 1050MB 524MB xfs
55+
3 1050MB 1052MB 2097kB bios_grub
56+
4 1052MB 68.7GB 67.7GB lvm
57+
```
58+
In the above output, we have to look for "Partition Table".
59+
We could see that the value is **gpt**, which means the disk is having "GPT" partition.
60+
61+
After validating your VM is having GPT Partition On OS Disk,
62+
Proceed forward for increasing the OS Disk.
63+
64+
## Environment
65+
66+
- Linux Endorsed distributions
67+
68+
## Procedure
69+
70+
>[!NOTE]
71+
>Please a take a backup of the VM (or) snapshot of OS Disk before procedding further.
72+
73+
### Ubuntu 16.x && 18.x
74+
75+
1. Stop the VM.
76+
2. Increase the size of the OSDisk from the portal.
77+
3. Start the VM && Login to the VM && become a **root** user.
78+
4. The OSDisk will have increased file system size.
79+
80+
Here the OS Disk is resized to 100 GB from portal.
81+
82+
```
83+
root@ubuntu:~# df -Th
84+
Filesystem Type Size Used Avail Use% Mounted on
85+
udev devtmpfs 314M 0 314M 0% /dev
86+
tmpfs tmpfs 65M 2.3M 63M 4% /run
87+
/dev/sda1 ext4 97G 1.8G 95G 2% /
88+
tmpfs tmpfs 324M 0 324M 0% /dev/shm
89+
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
90+
tmpfs tmpfs 324M 0 324M 0% /sys/fs/cgroup
91+
/dev/sda15 vfat 105M 3.6M 101M 4% /boot/efi
92+
/dev/sdb1 ext4 20G 44M 19G 1% /mnt
93+
tmpfs tmpfs 65M 0 65M 0% /run/user/1000
94+
root@ubuntu1604:~#
95+
96+
```
97+
From the above output, we could see that "/dev/sda1 mounted on /" is having 97 GB now.
98+
99+
### SUSE 12 SP4 && SUSE SLES 15 && SUSE SLES 15 For SAP
100+
101+
1. Stop the VM.
102+
2. Increase the size of the OSDisk from the portal.
103+
3. Start the VM.
104+
4. Perform the below steps to increase the size of the OS Disk.
105+
106+
4.1 Access your VM and become root user using below command.
107+
108+
#sudo su -
109+
110+
4.2 Install the "gptfdisk" package, which is required for increasing the OS Disk.
111+
112+
#zypper install gptfdisk -y
113+
114+
4.3 To be able to see the largest sector available on the disk, run the below command.
115+
116+
#sgdisk -e /dev/sda
117+
118+
4.4 Resize the partition without deleting it, using below command.
119+
Parted has an option named "resizepart" to resize the partition without deleting it.
120+
The number 4 after resizepart, means resize the 4TH partition.
121+
122+
#parted -s /dev/sda "resizepart 4 -1" quit
123+
124+
4.5 Check using below command if the partition is increased.
125+
126+
#lsblk
127+
128+
susesels15serialconsole:~ # lsblk
129+
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
130+
sda 8:0 0 100G 0 disk
131+
├─sda1 8:1 0 2M 0 part
132+
├─sda2 8:2 0 512M 0 part /boot/efi
133+
├─sda3 8:3 0 1G 0 part /boot
134+
└─sda4 8:4 0 98.5G 0 part /
135+
sdb 8:16 0 20G 0 disk
136+
└─sdb1 8:17 0 20G 0 part /mnt/resource
137+
138+
From the above output we could see that "/dev/sda4 partition is now having 98.5 GB.
139+
140+
4.6 Identify the type of file system on the OSDisk using "blkid" command
141+
142+
#blkid
143+
144+
susesels15serialconsole:~ # blkid
145+
/dev/sda1: PARTLABEL="p.legacy" PARTUUID="0122fd4c-0069-4a45-bfd4-98b97ccb6e8c"
146+
/dev/sda2: SEC_TYPE="msdos" LABEL_FATBOOT="EFI" LABEL="EFI" UUID="00A9-D170" TYPE="vfat" PARTLABEL="p.UEFI" PARTUUID="abac3cd8-949b-4e83-81b1-9636493388c7"
147+
/dev/sda3: LABEL="BOOT" UUID="aa2492db-f9ed-4f5a-822a-1233c06d57cc" TYPE="xfs" PARTLABEL="p.lxboot" PARTUUID="dfb36c61-b15f-4505-8e06-552cf1589cf7"
148+
/dev/sda4: LABEL="ROOT" UUID="26104965-251c-4e8d-b069-5f5323d2a9ba" TYPE="xfs" PARTLABEL="p.lxroot" PARTUUID="50fecee0-f22b-4406-94c3-622507e2dbce"
149+
/dev/sdb1: UUID="95239fce-ca97-4f03-a077-4e291588afc9" TYPE="ext4" PARTUUID="953afef3-01"
150+
151+
4.7 Based on the file system type use the appropriate commands to resize the file system.
152+
153+
For xfs:
154+
#xfs_growfs /
155+
156+
susesels15serialconsole:~ # xfs_growfs /
157+
meta-data=/dev/sda4 isize=512 agcount=4, agsize=1867583 blks
158+
= sectsz=512 attr=2, projid32bit=1
159+
= crc=1 finobt=1 spinodes=0 rmapbt=0
160+
= reflink=0
161+
data = bsize=4096 blocks=7470331, imaxpct=25
162+
= sunit=0 swidth=0 blks
163+
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
164+
log =internal bsize=4096 blocks=3647, version=2
165+
= sectsz=512 sunit=0 blks, lazy-count=1
166+
realtime =none extsz=4096 blocks=0, rtextents=0
167+
data blocks changed from 7470331 to 25820172
168+
169+
For ext4
170+
#resize2fs /dev/sda4
171+
172+
4.8 Verify the increased file system size "df -Th"
173+
174+
175+
#df -Th
176+
177+
susesels15serialconsole:~ # df -Th
178+
Filesystem Type Size Used Avail Use% Mounted on
179+
devtmpfs devtmpfs 306M 4.0K 306M 1% /dev
180+
tmpfs tmpfs 320M 0 320M 0% /dev/shm
181+
tmpfs tmpfs 320M 8.8M 311M 3% /run
182+
tmpfs tmpfs 320M 0 320M 0% /sys/fs/cgroup
183+
/dev/sda4 xfs 99G 1.8G 97G 2% /
184+
/dev/sda3 xfs 1014M 88M 927M 9% /boot
185+
/dev/sda2 vfat 512M 1.1M 511M 1% /boot/efi
186+
/dev/sdb1 ext4 20G 45M 19G 1% /mnt/resource
187+
tmpfs tmpfs 64M 0 64M 0% /run/user/1000
188+
susesels15serialconsole:~ #
189+
190+
We can see the increased the file system size for the OSDisk
191+
192+
### RHEL 7.x with LVM
193+
194+
1. Stop the VM.
195+
2. Increase the size of the OSDisk from the portal.
196+
3. Start the VM.
197+
4. Perform the below steps to increase the size of the OS Disk.
198+
199+
4.1 Access your VM and become root user using below command.
200+
201+
#sudo su -
202+
203+
4.2 Install the "gptfdisk" package, which is required for increasing the OS Disk.
204+
205+
#yum install gdisk -y
206+
207+
4.3 To be able to see the largest sector available on the disk, run the below command.
208+
209+
#sgdisk -e /dev/sda
210+
211+
4.4 Resize the partition without deleting it, using below command.
212+
Parted has an option named "resizepart" to resize the partition without deleting it.
213+
The number 4 after resize part, means resize the 4TH partition.
214+
215+
#parted -s /dev/sda "resizepart 4 -1" quit
216+
217+
4.5 Check using below command if the partition is increased.
218+
219+
#lsblk
220+
[root@rhel7lvm ~]# lsblk
221+
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
222+
fd0 2:0 1 4K 0 disk
223+
sda 8:0 0 100G 0 disk
224+
├─sda1 8:1 0 500M 0 part /boot/efi
225+
├─sda2 8:2 0 500M 0 part /boot
226+
├─sda3 8:3 0 2M 0 part
227+
└─sda4 8:4 0 99G 0 part
228+
├─rootvg-tmplv 253:0 0 2G 0 lvm /tmp
229+
├─rootvg-usrlv 253:1 0 10G 0 lvm /usr
230+
├─rootvg-optlv 253:2 0 2G 0 lvm /opt
231+
├─rootvg-homelv 253:3 0 1G 0 lvm /home
232+
├─rootvg-varlv 253:4 0 8G 0 lvm /var
233+
└─rootvg-rootlv 253:5 0 2G 0 lvm /
234+
sdb 8:16 0 50G 0 disk
235+
└─sdb1 8:17 0 50G 0 part /mnt/resource
236+
237+
From the above output we could see that "/dev/sda4 partition is now having 98.5 GB.
238+
239+
4.7 use the below command to resize the Physical Volume (pv)
240+
241+
#pvresize /dev/sda4
242+
243+
[root@rhel7lvm ~]# pvresize /dev/sda4
244+
Physical volume "/dev/sda4" changed
245+
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
246+
247+
[root@rhel7lvm ~]# pvs
248+
PV VG Fmt Attr PSize PFree
249+
/dev/sda4 rootvg lvm2 a-- <99.02g <74.02g
250+
251+
From the above output we could see that the PV is resized to 99.02 GB.
252+
253+
4.8 In this case, we are resizing the /dev/mapper/rootvg-rootlv by 10 GB using the below command, which would also resize the file system.
254+
255+
#lvresize -r -L +10G /dev/mapper/rootvg-rootlv
256+
257+
[root@rhel7lvm ~]# lvresize -r -L +10G /dev/mapper/rootvg-rootlv
258+
Size of logical volume rootvg/rootlv changed from 2.00 GiB (512 extents) to 12.00 GiB (3072 extents).
259+
Logical volume rootvg/rootlv successfully resized.
260+
meta-data=/dev/mapper/rootvg-rootlv isize=512 agcount=4, agsize=131072 blks
261+
= sectsz=4096 attr=2, projid32bit=1
262+
= crc=1 finobt=0 spinodes=0
263+
data = bsize=4096 blocks=524288, imaxpct=25
264+
= sunit=0 swidth=0 blks
265+
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
266+
log =internal bsize=4096 blocks=2560, version=2
267+
= sectsz=4096 sunit=1 blks, lazy-count=1
268+
realtime =none extsz=4096 blocks=0, rtextents=0
269+
data blocks changed from 524288 to 3145728
270+
271+
4.9 Verify whether the /dev/mapper/rootvg-rootlv has increased file system or not using below command.
272+
273+
#df -Th /
274+
[root@rhel7lvm ~]# df -Th /
275+
Filesystem Type Size Used Avail Use% Mounted on
276+
/dev/mapper/rootvg-rootlv xfs 12G 71M 12G 1% /
277+
[root@rhel7lvm ~]#
278+
279+
>[!NOTE]
280+
281+
>we can use the same procedure to resize any other logical volume.
282+
>We just need to change the lv name in the step 4.8
283+
284+
285+
286+
## Next Steps
287+
288+
- [Resize Disk](expand-disks.md)

articles/virtual-machines/linux/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@
644644
href: disks-shared-enable.md
645645
- name: Upload a vhd to a disk - CLI
646646
href: disks-upload-vhd-to-managed-disk-cli.md
647+
- name: Resize OS Disk having GPT Partition
648+
href: resize-os-disk-having-gpt-partition.md
647649
- name: Resize a disk
648650
href: expand-disks.md
649651
- name: Use Storage Explorer to manage disks

0 commit comments

Comments
 (0)