Resize disks: Difference between revisions

From Proxmox VE
Jump to navigation Jump to search
No edit summary
Line 3: Line 3:
==== 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 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.


==== qm command ====
==== qm command ====
Line 53: Line 53:


=== Linux guests - online resizing  ===
=== Linux guests - online resizing  ===
'''It is likely this is the process you need if you are using LVM in your guests (such as the latest releases of Ubuntu Server).'''


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  
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  


Install gnu-cfdisk on the virtual master
Install gnu-cfdisk on the virtual master (Yes, the package name is gnu-fdisk)
<pre>apt-get install gnu-cfdisk
<pre>apt-get install gnu-fdisk
</pre>
</pre>
Mount the disk and open CFDISK:<br>  
Mount the disk and open CFDISK:<br>  
Line 63: Line 65:
In case of a QCOW2 image<br>  
In case of a QCOW2 image<br>  
<pre>apt-get install nbd-client
<pre>apt-get install nbd-client
qemu-nbd --connnect /dev/nbd0 diskimage
qemu-nbd --connect /dev/nbd0 diskimage
cfdisk /dev/nbd0
cfdisk /dev/nbd0
</pre>  
</pre>  
Line 72: Line 74:
<pre>cfdisk /dev/xxxxx/diskimage
<pre>cfdisk /dev/xxxxx/diskimage
</pre>  
</pre>  
'''Enlarge the partion in CFDISK'''<br> Unfortunaly gnu-cfdisk can not resize most filesystems, only partitons - in general<br>  
'''Enlarge the partition in CFDISK'''<br> Unfortunately gnu-cfdisk can not resize most filesystems, only partitions - in general<br>  
 
'''When you attempt to choose "resize," cfdisk will tell you it cannot, and ask you if you want to "change size," warning you that this operation is "only for advanced users." The answer is yes. You are an advanced user. :)'''


*Use “fixed start” to avoid long moving time<br>  
*Use “fixed start” to avoid long moving time<br>  
*Use “change size” to only enlarge partion, not file system.<br>
*Use “change size” to only enlarge the partition, not the 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
If the virtual guest is a Linux machine with a swap disk as the last partition 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 the case of LVM guest, simple enlarge the LVM physical partition and the extended partition as well.


<br>In case of QCOW2 - disconnect the NBD mount:<br>  
<br>In case of QCOW2 - disconnect the NBD mount:<br>  
Line 93: Line 97:
</pre>  
</pre>  
Enlarge the logical volume (in this case root)<br>  
Enlarge the logical volume (in this case root)<br>  
<pre>lvresize -L+1G /dev/xxxx/root
<pre>lvresize -L+1G /dev/xxxx/root (This command will size the partition up by 1GB -- not too helpful in most cases.
</pre>  
</pre>  
<pre>lvresize -l100%PVS /dev/xxxx/root (This command tells LVM to use 100% of the remaining space. It will probably "fail" the first couple times you try it, telling you it needs more space than it has. Try sizing down to 99%, 98% etc. until you are inside the limit. This appears to happen because of a disparity between how much space is "available" and how much can actually be used for the filesystem when you account for housekeeping, etc.)
Enlarge the filesystem<br>  
Enlarge the filesystem<br>  
<pre>resize2fs /dev/xxxx/root
<pre>resize2fs /dev/xxxx/root
Line 103: Line 108:
<pre>resize2fs /dev/vda1</pre>
<pre>resize2fs /dev/vda1</pre>


== 4. Optionally with linux Guests - activate the swap again  ==
== 4. 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  
If you have deleted the swap partion with gparted or cfdisk, you need to activate it again  

Revision as of 05:01, 15 December 2014

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 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.

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

Windows Guests

Other 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.

Linux guests - online resizing

It is likely this is the process you need if you are using LVM in your guests (such as the latest releases of Ubuntu Server).

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.
AFAIK only reasonable option with guests using LVM

Install gnu-cfdisk on the virtual master (Yes, the package name is gnu-fdisk)

apt-get install gnu-fdisk

Mount the disk and open CFDISK:

In case of a QCOW2 image

apt-get install nbd-client
qemu-nbd --connect /dev/nbd0 diskimage
cfdisk /dev/nbd0

In case of a “RAW” image

cfdisk diskimage

In case of a LVM image

cfdisk /dev/xxxxx/diskimage

Enlarge the partition in CFDISK
Unfortunately gnu-cfdisk can not resize most filesystems, only partitions - in general

When you attempt to choose "resize," cfdisk will tell you it cannot, and ask you if you want to "change size," warning you that this operation is "only for advanced users." The answer is yes. You are an advanced user. :)

  • Use “fixed start” to avoid long moving time
  • Use “change size” to only enlarge the partition, not the file system.

If the virtual guest is a Linux machine with a swap disk as the last partition 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).
In the case of LVM guest, simple enlarge the LVM physical partition and the extended partition as well.


In case of QCOW2 - disconnect the NBD mount:

qemu-nbd -d /dev/nbd0

3. 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.

Linux client with LVM

Enlarge the physical volume (in this case on vda5)

pvresize /dev/vda5

Enlarge the logical volume (in this case root)

lvresize -L+1G /dev/xxxx/root (This command will size the partition up by 1GB -- not too helpful in most cases.
lvresize -l100%PVS /dev/xxxx/root (This command tells LVM to use 100% of the remaining space. It will probably "fail" the first couple times you try it, telling you it needs more space than it has. Try sizing down to 99%, 98% etc. until you are inside the limit. This appears to happen because of a disparity between how much space is "available" and how much can actually be used for the filesystem when you account for housekeeping, etc.)
Enlarge the filesystem<br> 
<pre>resize2fs /dev/xxxx/root

Linux client

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

resize2fs /dev/vda1

4. 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

mkswap /dev/vdxy

where vdxy is the swap partition

Notice the UUID and maybe change it in /etc/fstab (depending on distribution)

swapon -a

check with “free” that the swap is activated