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