Commit a6590061 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

doc: reviewed resize linux drive

parent a7225ee8
How to extend a Ravada Linux guest's disk space
========================================================
=================================================
Here we will show how to extend the system partition of a Linux host by 10 GB.
Extending a Linux disk drive in a virtual machine is a straightforward
process. Follow this guide carefully.
1. Shutdown the virtual machine
The process requires execute a hardware change in the Ravada frontend and
then use the command line in the host to resize the partition.
2. Consult the hard drive name of the Virtual Machine you want resize:
Shutdown
--------
.. prompt:: bash #
The virtual machine must be down to resize the volumes. Press *Shutdown* button
in the *Admin Tools*.
virsh edit VirtualMachineName
Backup
------
Here is our image file:
Make a backup of the disk volumes. The easiest way is to
`compact <http://ravada.readthedocs.io/en/latest/docs/compact.html>`_
the virtual machine. After that you should have a copy of all the volumes
in the images directory. Usually located at /var/lib/libvirt/images.
::
Expand the volume
-----------------
<source file='/path_to_img_file/VirtualDiskImageName.img'/>
Go to the *Hardware* tab in the virtual machine settings. Select the
disk drive you want to extend and type the desired size of the volume.
.. figure:: images/resize_volume.jpg
3. Use qemu-resize to increase the image size by 10GB:
Remove and create the partition again
-------------------------------------
.. prompt:: bash #
This part of the process must be down in the command line. Connect to the
server console and go to the images directory:
qemu-img resize /path_to_img_file/VirtualDiskImageName.img +10G
.. prompt:: bash
4. IMPORTANT. Do a backup before continue.
sudo bash
cd /var/lib/libvirt/images
.. prompt:: bash #
cp VirtualDiskImageName.img ./VirtualDiskImageName.img.backup
Connect the disk volume as a device
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5. Now start the Virtual Machine. Open a terminal and type:
.. prompt:: bash root@telecos:/var/lib/libvirt/images#
.. prompt:: bash
modprobe nbd
qemu-nbd -c /dev/nbd1 /var/lib/libvirt/images/WindowsE10-hda.qcow2
Now the volume appears as an nbd device in the host system. You can use fdisk and other
tools to change the partitions.
sudo fdisk /dev/vda
Remove and create the partition
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First let's check what are the partitions with *fdisk*:
.. prompt:: bash root@telecos:/var/lib/libvirt/images#
fdisk /dev/nbd1
p
Delete the partition
::
d
Create a new partition
Disk /dev/nbd1: 110 GiB, 118111600640 bytes, 230686720 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: dos
Disk identifier: 0x88e082d8
Device Boot Start End Sectors Size Id Type
/dev/nbd1p1 * 2048 1126399 1124352 549M 7 HPFS/NTFS/exFAT
/dev/nbd1p2 1126400 62912511 61786112 29,5G 7 HPFS/NTFS/exFAT
The partition we want to change is the second one (nbd1p2). From fdisk:
::
n
Accept all by default and exit saving
# fdisk /dev/nbd1
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.
Now we create the partition again but using all the space we just added.
*Warning*: when asked about remove the signature, answer N.
::
w
6. Restart the Virtual Machine.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (1126400-230686719, default 1126400):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1126400-230686719, default 230686719):
Created a new partition 2 of type 'Linux' and of size 109,5 GiB.
Partition #2 contains an ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N
7. When it starts in a terminal:
Then save an exit fdisk:
::
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Fix the new partition
---------------------
The new partition must be checked and fixed before resize.
Fix it first in the host:
.. prompt:: bash #
resize2fs /dev/nbd1p2
e2fsck /dev/nbd1p2
Start
-----
Disconnect the nbd and start the virtual machine.
.. prompt:: bash #
qemu-nbd -d /dev/nbd1
rmmod nbd
.. prompt:: bash
sudo resize2fs /dev/vda1
Check the new size
------------------
You can check if the disk was increased with the 'df' command.
Boot the virtual machine again, in a terminal type df, it should show the new size.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment