wiki/resize.md

80 lines
2.3 KiB
Markdown
Raw Normal View History

2021-08-12 10:56:03 +00:00
---
title: Resize a guest disk image
description: Resize a a guest disk image using qemu-img and virt-resize
published: true
2021-11-01 23:40:58 +00:00
date: 2021-11-01T23:40:55.146Z
2021-08-12 10:56:03 +00:00
tags:
editor: markdown
dateCreated: 2021-08-12T10:55:58.877Z
---
2021-08-12 10:56:37 +00:00
# qemu-img and virt-resize
2021-08-12 10:56:03 +00:00
## Introduction
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.*"
Expanding a new disk implies creating a new blank image of the desired size and "copy" the existing disk into this new bigger image using virt-resize.
2021-11-01 23:40:58 +00:00
> In-place expansion is not supported, which mean than a copy of the disk to be expanded has to be created
2021-09-10 09:35:00 +00:00
{.is-info}
2021-09-12 08:28:22 +00:00
## Installation
* On Fedora-related distributions, `virt-resize` is provided by the `guestfs-tools` package :
```
# dnf install guestfs-tools
```
2021-09-10 09:35:00 +00:00
2021-08-12 10:56:03 +00:00
## Usage
2021-09-10 09:35:00 +00:00
* **Create a new disk image**
In-place expansion is not supported. A new disk of the desired size has to be created.
Use the following command to create `phyllome_but_bigger.img`, a disk of 15 GiB
2021-08-12 10:56:03 +00:00
```
2021-09-10 09:35:00 +00:00
$ qemu-img create -f raw phyllome-bigger.img 15G
2021-08-12 10:56:03 +00:00
```
2021-09-10 09:35:00 +00:00
* **Expand the root partition**
2021-08-12 10:56:03 +00:00
> This command only works if the root partition is located on vda3 and if the disk image filesystem uses EXT4.
{.is-warning}
2021-09-10 09:35:00 +00:00
This command bellow requires root privileges.
2021-08-12 10:56:03 +00:00
```
# virt-resize --expand /dev/vda3 phyllome.img phyllome_but_bigger.img
[ 0.0] Examining phyllome.img
**********
Summary of changes:
2021-08-12 12:17:12 +00:00
/dev/vda1: This partition will be left alone.
2021-08-12 10:56:03 +00:00
2021-08-12 12:17:12 +00:00
/dev/vda2: This partition will be left alone.
2021-08-12 10:56:03 +00:00
2021-08-12 12:17:12 +00:00
/dev/vda3: This partition will be resized from 5G to 15G. The
filesystem ext4 on /dev/vda3 will be expanded using the resize2fs
2021-08-12 10:56:03 +00:00
method.
**********
2021-08-12 12:17:12 +00:00
[ 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
2021-08-12 10:56:03 +00:00
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
2021-08-12 12:17:12 +00:00
[ 38.3] Expanding /dev/vda3 using the resize2fs method
2021-08-12 10:56:03 +00:00
Resize operation completed with no errors. Before deleting the old disk,
carefully check that the resized disk boots and works correctly.
```
2021-09-10 09:35:00 +00:00
* **Inform your virtual machine to use the new disk**
*To-do*