Hello,
J’ai une VM avec une image disque qcow2 de 20G, tout est dans le /.
J’ai voulu faire un shrink pour diviser passer à 10G la taille de ma VM.
Au final, le résultat est le suivant quand je boot dessus :
Begin: Will now check root file system … fsck from util-linux 2.33.1
[/sbin/fsck.ext4 (1) – /dev/vda1] fsck.ext4 -a -C0 /dev/vda1
/dev/vda1: The filesystem size (according to the superblock) is 2621440 blocks
The physical size of the device is 2621184 blocks
Either the superblock or the partition table is likely to be corrupt!/dev/vda1: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
(i.e., without -a or -p options)
fsck exited with status code 4
done.
Failure: File system check of the root filesystem failed
The root filesystem on /dev/vda1 requires a manual fsckBusyBox v1.30.1 (Debian 1:1.30.1-4) built-in shell (ash)
Enter ‹ help › for a list of built-in commands.
Je me suis écris une procédure pour détailler ma démarche, pourriez-vous me dire où est-ce que je me suis planté ?
Nous avons une VM avec un disque de 20G et nous voulons lui affecter un disque de 10G.
Arrêter la VM :
virsh shutdown app3.mavm.org
:!: On fait une sauvegarde du disque ! :!:
cp -arp /stockage/disques_systemes/app3.mavm.org.qcowstockage/disques_systemes/app3.mavm.org.qcow.BAK
Démarrer la VM avec le disque de recue de libvirt, en mode RW :
virt-rescue -d app3.mavm.org –rw
Vérifier l'état de la table des partitions pour bien identifier la cible :
<rescue> fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: QEMU HARDDISK
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: 0x8b60bc22
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 41943039 41940992 20G 83 Linux
Démonter la cible (normalement elle n'est pas montée, en mode rescue) :
<rescue> umount /dev/sda1
Faire un check de l'intégrité du fs :
<rescue> e2fsck -f /dev/sda1
e2fsck 1.44.5 (15-Dec-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda1: 52906/655360 files (0.2% non-contiguous), 590221/2621440 blocks
Procéder au resize :
<rescue> resize2fs /dev/sda1 10G
resize2fs 1.44.5 (15-Dec-2018)
Resizing the filesystem on /dev/sda1 to 2621440 (4k) blocks.
The filesystem on /dev/sda1 is now 2621440 (4k) blocks long.
Détruire et recréer la partition à la bonne taille :
<rescue> fdisk /dev/sda
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: QEMU HARDDISK
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: 0x8b60bc22
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 41943039 41940992 20G 83 Linux
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): -10G
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: Y
The signature will be removed by a write command.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
On quitte l'environnement de rescue
<rescue> exit
Côté hyperviseur, on recréé l'image à la bonne taille :
qemu-img create -f qcow2 -o preallocation=metadata newimage.qcow2 11G
virt-resize app3.mavm.org.qcow newimage.qcow2
mv newimage.qcow2 app3.mavm.org.qcow