Difference between revisions of "Resize disks"

From Proxmox VE
Jump to navigation Jump to search
m
(17 intermediate revisions by 8 users not shown)
Line 1: Line 1:
== Resizing guest disk  ==
+
== 1. Resizing guest disk  ==
  
 
==== General considerations ====
 
==== General considerations ====
  
When you resize the disk of a VM, to avoid confusion and disasters think the process like adding or removing a disk plattern.
+
When you resize the disk of a VM, to avoid confusion and disasters think the process like adding or removing a disk platter.
  
If you '''enlarge''' the hard disk, once you have added the disk plate your partition table and file system knows nothing about the new size, so you have to act inside the VM to fix it.
+
If you '''enlarge''' the hard disk, once you have added the disk plate, your partition table and file system knows nothing about the new size, so you have to act inside the VM to fix it.
  
If you '''reduce''' (shrink) the hard disk, of course removing the last disk plate will probably '''destroy''' your file system and remove the data in it! So in this case is paramount to act in the VM in '''advance''', reducing the file system and the partition size. SystemRescueCD comes very handy for it, just add it's iso as cdrom of your VM and set boot priority to CD-ROM.
+
If you '''reduce''' (shrink) the hard disk, of course removing the last disk plate will probably '''destroy''' your file system and remove the data in it! So in this case it is paramount to act in the VM in '''advance''', reducing the file system and the partition size. SystemRescueCD comes very handy for it, just add its iso as cdrom of your VM and set boot priority to CD-ROM.
 +
 
 +
Shrinking disks is not supported by the PVE API and has to be done manually.
 +
 
 +
Another page (deleted) with overlapping content was [[Resizing disks]] | [http://web.archive.org/web/20150914170505/http://pve.proxmox.com/wiki/Resize_disks Archive]
  
 
==== qm command ====
 
==== qm command ====
Line 36: Line 40:
 
Windows should see the new size online without reboot with last virtio drivers.
 
Windows should see the new size online without reboot with last virtio drivers.
  
== Enlarge the partition(s) in the virtual disk<br> ==
+
== 2. Enlarge the partition(s) in the virtual disk  ==
  
 
Depending on the installed guest there is several diffent ways to resize the partions  
 
Depending on the installed guest there is several diffent ways to resize the partions  
  
=== Windows Guests<br>  ===
+
=== Offline for all guests  ===
 +
 
 +
Use '''gparted''' or similar tool (recommended)<br> In gparted and possibly most other tools, '''LVM and Windows dynamic disc is not supported'''
 +
 
 +
Boot the virtual machine with gparted or similar tool, enlarge the partion and optionally the file system. With som linux clients you often need to enlarge the extended partion, move the swappartion, shrink the extended partion and enlarge the root partion. (or simple delete the swap and partion andre create it again - but remember to activwate the swap agin (last step).<br> Gparted have some warnings about some specific operations not well supported with windows guest - outside the scope of this document but read the warnings in gparted.<br>
 +
 
 +
 
 +
=== Online for Windows Guests  ===
 +
 
 +
*Guest is Windows 7, Windows Vista or Windows Server 2008
 +
*logon as administrator and extend the disk and filesystem (Using Disk manager)
 +
*For more info [http://www.petri.co.il/extend-disk-partition-vista-windows-server-2008.htm www.petri.co.il/extend-disk-partition-vista-windows-server-2008.htm]
 +
*Guest is Windows 10: logon as administrator and extend the disk and filesystem (Using Disk manager). If you do not see the ability to extend the disk (i.e. nothing seems to have happened as a result of using the resize command), go to the Windows command prompt and do a: shutdown -s -t 0 (This is a "normal" shutdown, as opposed to the "fast" shutdown that's the default for Win 8 and onwards.) After a reboot, you'll now see the ability to expand the disk.
 +
 
 +
=== Online for Linux Guests ===
 +
 
 +
Here we will enlarge a LVM PV partition, but the procedure is the same for every kind of partitions.
 +
Note that the partition you want to enlarge should be at the end of the disk.
 +
If you want to enlarge a partition which is anywhere on the disk, use the offline method.
 +
 
 +
* Check that the kernel has detected the change of the hard drive size
 +
(here we use VirtIO so the hard drive is named vda)
  
*Guest is Windows 7, Windows Vista or Windows Server 2008<br>
+
dmesg | grep vda
*Boot the system, logon as administrator and extend the disk and filesystem (Using Disk manager)<br>
+
[ 3982.979046] vda: detected capacity change from 34359738368 to 171798691840
*For more info [http://www.petri.co.il/extend-disk-partition-vista-windows-server-2008.htm www.petri.co.il/extend-disk-partition-vista-windows-server-2008.htm]<br>
 
  
=== Other guests<br>  ===
+
* Print the current partition table
  
Use gparted or similar tool (recommended)<br> In gparted and possibly most other tools, LVM and Windows dynamic disc is not supported
+
fdisk -l /dev/vda | grep ^/dev
 +
GPT PMBR size mismatch (67108863 != 335544319) will be corrected by w(rite).
 +
/dev/vda1      34    2047    2014 1007K BIOS boot
 +
/dev/vda2    2048  262143  260096  127M EFI System
 +
/dev/vda3  262144 67108830 66846687 31.9G Linux LVM
  
Boot the virtual machine with gparted or similar tool, enlarge the partion and optionally the file system. With som linux clients you often need to enlarge the extended partion, move the swappartion, shrink the extended partion and enlarge the root partion. (or simple delete the swap and partion andre create it again - but remember to activwate the swap agin (last step).<br> Gparted have some warnings about some specific operations not well supported with windows guest - outside the scope of this document but read the warnings in gparted.<br>
 
  
=== Linux guests - online resizing ===
+
* Resize the partition 3 (LVM PV) to occupy the whole remaining space of the hard drive)
  
Enlarge the partions with gnu-cfdisk on the virtual master server, then online resize the filesystem in the virtual machine. A bit more complicated but possible faster.<br> AFAIK only reasonable option with guests using LVM
+
parted /dev/vda
 +
(parted) print
 +
Warning: Not all of the space available to /dev/vda appears to be used, you can
 +
fix the GPT to use all of the space (an extra 268435456 blocks) or continue
 +
with the current setting?
 +
Fix/Ignore? F
  
Install gnu-cfdisk on the virtual master
+
(parted) resizepart 3 100%
<pre>apt-get install gnu-cfdisk
+
(parted) quit
</pre>
+
 
Mount the disk and open CFDISK:<br>
+
* Check the new partition table
 +
 
 +
fdisk -l /dev/vda | grep ^/dev
 +
/dev/vda1      34      2047      2014  1007K BIOS boot
 +
/dev/vda2    2048    262143    260096  127M EFI System
 +
/dev/vda3  262144 335544286 335282143 159.9G Linux LVM
 +
 
 +
== 3. Enlarge the filesystem(s) in the partitions on the virtual disk ==
  
In case of a QCOW2 image<br>
+
If you did not resize the filesystem in step 2
<pre>apt-get install nbd-client
 
qemu-nbd --connnect /dev/nbd0 diskimage
 
cfdisk /dev/nbd0
 
</pre>
 
In case of a “RAW” image<br>
 
<pre>cfdisk diskimage
 
</pre>
 
In case of a LVM image<br>
 
<pre>cfdisk /dev/xxxxx/diskimage
 
</pre>
 
'''Enlarge the partion in CFDISK'''<br> Unfortunaly gnu-cfdisk can not resize most filesystems, only partitons - in general<br>
 
  
*Use “fixed start” to avoid long moving time<br>
+
=== Online for Linux guests with LVM  ===
*Use “change size” to only enlarge partion, not file system.<br>
 
  
If the virtual guest is a linux machine with a swap disk as the last partion you can simply delete the swap, enlarge the first disk and create a new swap - but remember to “activate” the swap again (see last step)<br> In case of LVM guest, simple enlarge the LVM partion and mayby the extended partion
+
Enlarge the physical volume to occupy the whole available space in the partition:
  
<br>In case of QCOW2 - disconnect the NBD mount:<br>
+
pvresize /dev/vda3
<pre>qemu-nbd -d /dev/nbd0
 
</pre>
 
== Enlarge the filesystem(s) in the partions on the virtual disk  ==
 
  
If you did not resize the filesystem in step 2, you need to boot the system and online resize it.
+
Enlarge the logical volume and the filesystem (the file system can be mounted, works with ext4 and xfs)
  
=== Linux client with LVM<br> ===
+
  lvresize --size +20G --resizefs /dev/xxxx/root #This command will increase the partition up by 20GB
  
Enlarge the physical volume (in this case on vda5)<br>
+
lvresize --extents +100%FREE --resizefs /dev/xxxx/root #Use all the remaining space on the volume group
<pre>pvresize /dev/vda5
 
</pre>
 
Enlarge the logical volume (in this case root)<br>
 
<pre>lvresize -L+1G /dev/xxxx/root
 
</pre>
 
Enlarge the filesystem<br>
 
<pre>resize2fs /dev/xxxx/root
 
</pre>
 
=== Linux client<br>  ===
 
  
Enlarge the filesystem (in this case root is on vda1)
+
=== Online for Linux guests without LVM ===
<pre>resize2fs /dev/vda1</pre>
 
== Optionally with linux Guests - activate the swap again ==
 
  
If you have deleted the swap partion with gparted or cfdisk, you need to activate it again
+
Enlarge the filesystem (in this case root is on vda1)
<pre>mkswap /dev/vdxy
 
</pre>
 
where vdxy is the swap partition<br>
 
  
Notice the UUID and maybe change it in /etc/fstab (depending on distribution)
+
resize2fs /dev/vda1
<pre>swapon -a
 
</pre>
 
check with “free” that the swap is activated<br>
 
  
 
[[Category: HOWTO]]
 
[[Category: HOWTO]]

Revision as of 07:33, 28 September 2018

1. Resizing guest disk

General considerations

When you resize the disk of a VM, to avoid confusion and disasters think the process like adding or removing a disk platter.

If you enlarge the hard disk, once you have added the disk plate, your partition table and file system knows nothing about the new size, so you have to act inside the VM to fix it.

If you reduce (shrink) the hard disk, of course removing the last disk plate will probably destroy your file system and remove the data in it! So in this case it is paramount to act in the VM in advance, reducing the file system and the partition size. SystemRescueCD comes very handy for it, just add its iso as cdrom of your VM and set boot priority to CD-ROM.

Shrinking disks is not supported by the PVE API and has to be done manually.

Another page (deleted) with overlapping content was Resizing disks | Archive

qm command

You can resize your disks online or offline with command line:

qm resize <vmid> <disk> <size> 

exemple: to add 5G to your virtio0 disk on vmid100:

qm resize 100 virtio0 +5G

For virtio disks:

Linux should see the new size online without reboot with kernel >= 3.6

Windows should see the new size online without reboot with last virtio drivers.


for virtio-iscsi disk:

Linux should see the new size online without reboot with kernel >= 3.7

Windows should see the new size online without reboot with last virtio drivers.

2. Enlarge the partition(s) in the virtual disk

Depending on the installed guest there is several diffent ways to resize the partions

Offline for all guests

Use gparted or similar tool (recommended)
In gparted and possibly most other tools, LVM and Windows dynamic disc is not supported

Boot the virtual machine with gparted or similar tool, enlarge the partion and optionally the file system. With som linux clients you often need to enlarge the extended partion, move the swappartion, shrink the extended partion and enlarge the root partion. (or simple delete the swap and partion andre create it again - but remember to activwate the swap agin (last step).
Gparted have some warnings about some specific operations not well supported with windows guest - outside the scope of this document but read the warnings in gparted.


Online for Windows Guests

  • Guest is Windows 7, Windows Vista or Windows Server 2008
  • logon as administrator and extend the disk and filesystem (Using Disk manager)
  • For more info www.petri.co.il/extend-disk-partition-vista-windows-server-2008.htm
  • Guest is Windows 10: logon as administrator and extend the disk and filesystem (Using Disk manager). If you do not see the ability to extend the disk (i.e. nothing seems to have happened as a result of using the resize command), go to the Windows command prompt and do a: shutdown -s -t 0 (This is a "normal" shutdown, as opposed to the "fast" shutdown that's the default for Win 8 and onwards.) After a reboot, you'll now see the ability to expand the disk.

Online for Linux Guests

Here we will enlarge a LVM PV partition, but the procedure is the same for every kind of partitions. Note that the partition you want to enlarge should be at the end of the disk. If you want to enlarge a partition which is anywhere on the disk, use the offline method.

  • Check that the kernel has detected the change of the hard drive size

(here we use VirtIO so the hard drive is named vda)

dmesg | grep vda
[ 3982.979046] vda: detected capacity change from 34359738368 to 171798691840
  • Print the current partition table
fdisk -l /dev/vda | grep ^/dev
GPT PMBR size mismatch (67108863 != 335544319) will be corrected by w(rite).
/dev/vda1      34     2047     2014 1007K BIOS boot
/dev/vda2    2048   262143   260096  127M EFI System
/dev/vda3  262144 67108830 66846687 31.9G Linux LVM


  • Resize the partition 3 (LVM PV) to occupy the whole remaining space of the hard drive)
parted /dev/vda
(parted) print
Warning: Not all of the space available to /dev/vda appears to be used, you can
fix the GPT to use all of the space (an extra 268435456 blocks) or continue
with the current setting? 
Fix/Ignore? F 
(parted) resizepart 3 100%
(parted) quit
  • Check the new partition table
fdisk -l /dev/vda | grep ^/dev
/dev/vda1      34      2047      2014  1007K BIOS boot
/dev/vda2    2048    262143    260096   127M EFI System
/dev/vda3  262144 335544286 335282143 159.9G Linux LVM

3. Enlarge the filesystem(s) in the partitions on the virtual disk

If you did not resize the filesystem in step 2

Online for Linux guests with LVM

Enlarge the physical volume to occupy the whole available space in the partition:

pvresize /dev/vda3

Enlarge the logical volume and the filesystem (the file system can be mounted, works with ext4 and xfs)

lvresize --size +20G --resizefs /dev/xxxx/root #This command will increase the partition up by 20GB
lvresize --extents +100%FREE --resizefs /dev/xxxx/root #Use all the remaining space on the volume group

Online for Linux guests without LVM

Enlarge the filesystem (in this case root is on vda1)

resize2fs /dev/vda1