[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Ceci est une ancienne révision du document !


Redimensionner une Image RAW QEMU Comportant un Système de Fichiers NTFS

TRADUCTION en cours — Cedric M. 2015/09/11 00:54

C'est un guide rapide pour augmenter l'espace disponible de votre machine virtuelle Windows munie d'un système de fichiers NTFS. L'exemple s'appuie sur le redimensionnement d'une partition de 5Go à 6Go.

Sauvegardez votre fichier original au cas où quelque chose ne se déroulerait pas bien.

Utiliser qemu-img pour redimensionner l'image disque RAW de QEMU

Cette commande augmente la taille de l'image-disque du fichier Windows_XP_Professional_SP_3.img d'1Go.

qemu-img resize Windows_XP_Professional_SP_3.img +1G

Après cette commande, si vous démarrez votre machine virtuelle, vous verrez 1Go d'espace libre supplémentaire.

Trouver l'offset dans l'image

Monter l'image en mode loop.

losetup /dev/loop0 Windows_XP_Professional_SP_3.img

Regarder la table de partition (ici parted est utilisé mais fdisk ou cfdisk peuvent également être utilisés).

parted /dev/loop0

Dans parted, sélectionnez l'unité sur secteurs puis afficher la table de partition actuelle.

(parted) unit s                                                           
(parted) print 

La sortie devrait ressembler à quelque chose comme ça:

Model: Loopback device (loopback)
Disk /dev/loop0: 12582912s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start  End        Size       Type     File system  Flags
 1      63s    11718798s  11718736s  primary  ntfs         boot

Notez les valeurs du début (Start) et de la taille (Size) du secteur.

Puis quittez parted.

(parted) quit

Supprimer le device loop.

losetup -d /dev/loop0

Use ntfsresize to resize the NTFS partition

Loop mount the NTFS partition to be resized, using an offset calculated from the sector size and start sector.

losetup -o$((512*63)) /dev/loop0 Windows_XP_Professional_SP_3.img

First do a dry run.

 ntfsresize -n -s 6G /dev/loop0

If all is OK, do it for real.

ntfsresize -s 6G /dev/loop0

Delete the loop device.

losetup -d /dev/loop0

Update the partition table

Loop mount the image.

losetup  /dev/loop0 Windows_XP_Professional_SP_3.img

Update the partition table using parted (both fdisk and cfdisk appear to fail here).

parted /dev/loop0

This seems like a backward step, but now use parted to remove the existing partition.

(parted) rm 1

Use the parted rescue command to find the partition again, with the END option set to the size of the partition in MB.

(parted) rescue 1 6000                                                    
Information: A ntfs primary partition was found at 32.3kB -> 6000MB.  Do you want to add it to the partition table?
Yes/No/Cancel? Yes

Set the boot flag on the rescued partition.

(parted) set 1 boot on

The partition table is written when you quit parted.

(parted) quit

Delete the loop device.

losetup -d /dev/loop0

Finish up

Boot the virtual machine and allow the Windows chkdsk program to run.

Sources

 fr:howtos:general_admin:resize_a_qemu_raw_image_with_an_ntfs_filesytem ()