Skip to content

Resize VM Disk

To increase the harddisk of a VM, go to vcenter.psi.ch, select the machine, right click, and select Edit Settings ...

Increase the harddisk size to the value you need to have:

Now connect to the system and change to root.

List block devices:

# lsblk
NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                      8:0    0  100G  0 disk 
├─sda1                   8:1    0  600M  0 part /boot/efi
├─sda2                   8:2    0    1G  0 part /boot
├─sda3                   8:3    0    4G  0 part [SWAP]
└─sda4                   8:4    0 94.4G  0 part 
  ├─vg_root-lv_root    253:0    0   16G  0 lvm  /
  ├─vg_root-lv_var_log 253:1    0    4G  0 lvm  /var/log
  ├─vg_root-lv_var     253:2    0   70G  0 lvm  /var
  ├─vg_root-lv_tmp     253:3    0    2G  0 lvm  /tmp
  └─vg_root-lv_home    253:4    0    2G  0 lvm  /home
sr0                     11:0    1 1024M  0 rom  
# 

The command will probably not show the correct disk size. For this the VM either needs to be rebooted or you can trigger a re-read of the disksize without a reboot with this command (replace sda with the correct diskname you resized):

echo 1 > /sys/block/sda/device/rescan

Extend partition:

# parted /dev/sda
GNU Parted 3.5
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(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 209715200 blocks) or continue with the current setting? 
Fix/Ignore? fix                                                           
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name                  Flags
 1      1049kB  630MB   629MB   fat32           EFI System Partition  boot, esp
 2      630MB   1704MB  1074MB  ext4
 3      1704MB  5999MB  4295MB  linux-swap(v1)                        swap
 4      5999MB  107GB   101GB                                         lvm

(parted) resizepart 4                                                     
End?  [107GB]? -0                                                         
(parted) print                                                            
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name                  Flags
 1      1049kB  630MB   629MB   fat32           EFI System Partition  boot, esp
 2      630MB   1704MB  1074MB  ext4
 3      1704MB  5999MB  4295MB  linux-swap(v1)                        swap
 4      5999MB  215GB   209GB                                         lvm

(parted) quit                                                             
Information: You may need to update /etc/fstab.

#

Resize physical volume:

# pvresize /dev/sda4
  Physical volume "/dev/sda4" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized
#

Now the effective volumes of the machine can be extended as documented Partitioning