Ceci est une ancienne révision du document !
Table des matières
Redimensionner une Image RAW QEMU Comportant un Système de Fichiers NTFS
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.
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
Utiliser ntfsresize pour redimensionner la partition NTFS
Monter la partition NTFS en mode loop pour la redimensionner; calculez l'offset d'après les valeurs sector size et start sector.
losetup -o$((512*63)) /dev/loop0 Windows_XP_Professional_SP_3.img
Faites un test.
ntfsresize -n -s 6G /dev/loop0
Si tout est OK, faites le pour de vrai.
ntfsresize -s 6G /dev/loop0
Supprimer le 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.