Expand Drive with Command Line Parted

Mindwatering Incorporated

Author: Tripp W Black

Created: 06/01 at 05:45 PM



Expand disk/drive using the parted command line tool.

Expand "data" drive of a running VM where the disk was just extended via the vSphere Web Client.
In our case, we are expanding the second disk, /dev/sdb from 32 GB to 40 GB.

1. Expand the disk, from 32 GB to 40 GB using the vSphere Web Client
vSphere Web Client
--> Locate VM --> Right-click, choose Edit Settings
In the Edit Settings dialog:
- - Hard disk 2 --> 40 GB
- - Click OK

2. Using local client Terminal or Remote SSH Terminal, expand the partition with parted.
- Rescan the drive:
$ sudo echo 1>/sys/class/block/sdb/device/rescan
$ fdisk -l
Disk /dev/sdb: 40 GiB, 42949672960 bytes, 83886080 sectors

- Expand the disk:
$ sudo parted
(parted) select /dev/sdb
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 42.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 34.4GB 34.4GB primary ext4

(parted) resizepart
Partition number? 1
Warning: Partition /dev/sdb1 is being used. Are you sure you want to continue?
Yes/No? Yes
End? [42.0GB]? 42.9GB

(parted) print
Number Start End Size Type File system Flags
1 1049kB 42.9GB 42.9GB primary ext4

(parted) quit

- Expand the formatted OS
$ sudo resize2fs /dev/sdb1
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/sdb1 is mounted on /local/share; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/sdb1 is now 10473376 (4k) blocks long.

- Confirm the new size:
$ sudo df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 41104320 32465012 8287396 80% /local/share

Free space has increased. Use% was 98% and is now 80%.

previous page