wiki/gofurther/resize.md

97 lines
2.4 KiB
Markdown
Raw Normal View History

2021-11-13 11:41:32 +00:00
---
title: Resize an existing virtual disk
description:
published: true
2022-01-31 13:20:53 +00:00
date: 2022-01-31T13:20:51.295Z
2021-11-13 11:41:32 +00:00
tags:
editor: markdown
dateCreated: 2021-11-13T11:41:29.087Z
---
2021-11-13 17:49:14 +00:00
# Resize a disk
2022-01-25 14:07:20 +00:00
> *Instructions only applies to Linux guests.*
{.is-info}
## Background
2021-11-13 17:49:14 +00:00
2022-01-25 14:07:20 +00:00
A virtual machine's disk may have to be resized, typically due to lack of space. This page explains how to do so.
2021-11-13 17:49:14 +00:00
2022-01-25 14:07:20 +00:00
The process involves creating a new blank virtual disk of the desired size and grow the former disk into the new one.
2021-11-13 17:49:14 +00:00
2022-01-25 14:07:20 +00:00
## Usage
> *In-place expansion is not supported. A new disk of the desired size has to be created.*
2021-11-13 17:49:14 +00:00
{.is-info}
2022-01-25 14:07:20 +00:00
* *Move to the location that contains the existing image*
2021-11-13 17:49:14 +00:00
```
2022-01-25 14:07:20 +00:00
cd /var/lib/libvirt/images
2021-11-13 17:49:14 +00:00
```
2022-01-25 14:07:20 +00:00
* *Create a new disk image*
2021-11-13 17:49:14 +00:00
2022-01-25 14:07:20 +00:00
Use the following command to create a disk of 15 GB called `phyllome-bigger.img`.
2021-11-13 17:49:14 +00:00
```
2022-01-25 14:07:20 +00:00
qemu-img create -f raw phyllome-bigger.img 15G
2021-11-13 17:49:14 +00:00
```
2022-01-25 14:07:20 +00:00
* *Expand the root partition*
2021-11-13 17:49:14 +00:00
2022-01-25 14:07:20 +00:00
> *This command expects the root partition to be located on the vda3 partition. It has only been tested against the `ext4`filesystem.*
2021-11-13 17:49:14 +00:00
{.is-warning}
```
2022-01-25 14:07:20 +00:00
virt-resize --expand /dev/vda3 phyllome.img phyllome-bigger.img
```
2021-11-13 17:49:14 +00:00
2022-01-25 14:07:20 +00:00
* *The following should appear*
```
2021-11-13 17:49:14 +00:00
[ 0.0] Examining phyllome.img
**********
Summary of changes:
/dev/vda1: This partition will be left alone.
/dev/vda2: This partition will be left alone.
/dev/vda3: This partition will be resized from 5G to 15G. The
filesystem ext4 on /dev/vda3 will be expanded using the resize2fs
method.
**********
[ 2.1] Setting up initial partition table on phyllome-bigger.img
[ 12.9] Copying /dev/vda1
[ 13.1] Copying /dev/vda2
[ 13.4] Copying /dev/vda3
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[ 38.3] Expanding /dev/vda3 using the resize2fs method
Resize operation completed with no errors. Before deleting the old disk,
carefully check that the resized disk boots and works correctly.
```
2022-01-25 14:07:20 +00:00
* *Switch to the new disk for your virtual machine*
2021-11-13 17:49:14 +00:00
*To-do*
2022-01-25 14:07:20 +00:00
## Resources
As per the software description : "*qemu-img allows you to create, convert and modify images offline. It can handle all image formats supported by QEMU.*"
* *Installation*
On Fedora-related distributions, `virt-resize` is provided by the `guestfs-tools` package :
```
# dnf install guestfs-tools
```
2022-01-25 14:42:56 +00:00
2022-01-31 13:20:53 +00:00
---
*[**Go to parent page**](https://wiki.phyllo.me/)*