- You have a VM with small disk
- You have GPT partition table
- You NOT USE LVM (you should)
- You need to extend a partition on the main drive
- You use Debian 8.x aka Jessie
- Open your VM hypervisor config and resize the disk
- The VM main disk will now be 40G in place of 20G
- Your partition is still based on the 20G disk
- You need to reboot to notify the VM of the change of disk size ( lsblk or fidsk you will still see 20G without rebooting )
- Maybe you can hot reload the disk metadata in kernel with
partprobe
- fdisk or cfdisk WILL NOT WORK FOR THIS, and FAIL with
Value out of range
during creation on partition exciding the original disk size ( on Debian 8 ) - Use parted it will fix the GPT partition table
- Unmount swap if this is your last partition
swapoff /dev/sda3
parted /dev/sda
(parted) print
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 41943040 blocks) or continue with the
current setting?
Fix/Ignore? Fix
And then you will have something like that
Model: ATA BHYVE SATA DISK (scsi)
Disk /dev/sda: 42,9GB
Sector size (logical/physical): 512B/16384B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 538MB 537MB fat32 boot, esp
2 538MB 20,9GB 20,4GB ext4
3 20,9GB 21,5GB 535MB linux-swap(v1)
- Optionnaly delete your swap partition
(parted) rm 3
(parted) resizepart 2
Warning: Partition /dev/sda2 is being used. Are you sure you want to continue?
Yes/No? Yes
(parted) End? [20,9GB]? 37GB
- Optionnaly recreate the swap partition at the end of disk with
(parted) mkpart
Partition name? []? swap
File system type? [ext2]? swap
parted: invalid token: swap
File system type? [ext2]? linux-swap
Start? 37GB
End? 42,9GB
(parted) print
Number Start End Size File system Name Flags
1 1049kB 538MB 537MB fat32 boot, esp
2 538MB 37,0GB 36,5GB ext4
3 37,0GB 42,9GB 5949MB linux-swap(v1) swap
- You can
(parted) quit
- Launch
mkswap /dev/sda3
- Launch
resize2fs /dev/sda2
- Then
blkid /dev/sda3
- Report the new UUID in
/etc/fstab
- Remount your swap with
swapon /dev/sda3
- You are ALL GOOD TO GO (or not)