0

I'm having some problems trying to extend a Disk. I'm using a VMware Debian 9 virtual machine on an ESXi host.

After extending the virtual disk-size by 32 GB and rebooting the VM I see:

bob@apollo:~$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0   64G  0 disk 
├─sdb1   8:17   0   16G  0 part /var/lib/jenkins
└─sdb2   8:18   0   16G  0 part /var/www

bob@apollo:~$ mount | grep sdb
/dev/sdb2 on /var/www type ext4 (rw,relatime,data=ordered)
/dev/sdb1 on /var/lib/jenkins type ext4 (rw,relatime,data=ordered)

bob@apollo:~$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).

Command (m for help): p

Disk /dev/sdb: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 513133B6-1030-427A-8950-E43374665229

Device        Start      End  Sectors Size Type
/dev/sdb1      2048 33554431 33552384  16G Linux filesystem
/dev/sdb2  33554432 67106815 33552384  16G Linux filesystem

The technique that I've learned about from lurking on this site is to use fdisk to delete the partition and create a new, bigger one. I'm hoping the necessary write will also solve the GPT PMBR size mismatch that I see with fdisk.

bob@apollo:~$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition number (2-128, default 2): 2
First sector (33554432-67108830, default 33554432): 
Last sector, +sectors or +size{K,M,G,T,P} (33554432-67108830, default 67108830): 134217728
Value out of range.
Last sector, +sectors or +size{K,M,G,T,P} (33554432-67108830, default 67108830): 

Created a new partition 2 of type 'Linux filesystem' and of size 16 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): w
GPT PMBR size mismatch (67108863 != 134217727) will be corrected by w(rite).
fdisk: failed to write disklabel: Invalid argument
bob@apollo:~$ 

So a lot of things happened here

  1. /dev/sdb now has 134,217,728 sectors. But the "valid range" only goes up to the old 67,108,830.
  2. When I do 'recreate' partition 2 with its original size and try to write the changes, fdisk crashes with 'Invalid argument'.

How can I extend the volume

0

fdisk isn't good at working with GPT tables. First repair the GPT table with parted:

bob@apollo:~$ sudo parted -l

Warning: Not all of the space available to /dev/sdb appears to be used, you can
fix the GPT to use all of the space (an extra 67108864 blocks) or continue with
the current setting? 
Fix/Ignore? F                                                             
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  17.2GB  17.2GB  ext4         primary
 2      17.2GB  34.4GB  17.2GB  ext4         primary

Second, stop any services which access these disks and unmount the disk:

bob@apollo:~$ sudo systemctl stop jenkins.service
bob@apollo:~$ sudo systemctl stop apache2.service
bob@apollo:~$ sudo umount /dev/sdb1
bob@apollo:~$ sudo umount /dev/sdb2

Third, extend the partition like you originally intended:

bob@apollo:~$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sdb: 64 GiB, 68719476736 bytes, 134217728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 513133B6-1030-427A-8950-E43374665229

Device        Start       End   Sectors Size Type
/dev/sdb1      2048  33554431  33552384  16G Linux filesystem
/dev/sdb2  33554432 134217694 100663263  48G Linux filesystem

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): n
Partition number (2-128, default 2): 2
First sector (33554432-134217694, default 33554432): 
Last sector, +sectors or +size{K,M,G,T,P} (33554432-134217694, default 134217694): 

Created a new partition 2 of type 'Linux filesystem' and of size 48 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Surprisingly, you don't need to remount anything from /dev/sdb, it is done after writing to /dev/sdb. If you review the mount-points, the data should still be there. Start up your services again to get everything working like it was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.