Create images
raw
qcow2
Modify partitions on raw partitions
Mount
raw images
Information about the partitions
Useful for size in sectors and start sector.
sudo fdisk -lu windows10.raw
----------------------------
Sector size (logical/physical): 512 bytes / 512 bytes
Device Start End Sectors Size Type
windows10.raw1 2048 1023999 1021952 499M Windows recovery environ
windows10.raw2 1024000 1228799 204800 100M EFI System
windows10.raw3 1228800 1261567 32768 16M Microsoft reserved
windows10.raw4 1261568 125829086 124567519 19.4G Microsoft basic data
Mount
# Partition 1
mount -o loop,offset=$((2048*512)) windows10.raw /mnt/hdisk/1/
# Partition 2
mount -o loop,offset=$((1024000*512)) windows10.raw /mnt/hdisk/2/
# Partition 3
mount -o loop,offset=$((1228800*512)) windows10.raw /mnt/hdisk/3/
# Partition 4
mount -o loop,offset=$((1261568*512)) windows10.raw /mnt/hdisk/4/
Mount as loop device
List all used devices
List mounted devices
Dettach all
qcow2
Install libguestfs-tools
. libguestfs
in Arch.
Find the partitions in the image
Mount the partition
Shrink an image file
- Mount file
- Write zeros
- Convert
Install libguestfs-tools
.
Find the partitions in the image
Mount the partition
Write zeros to it
Convert
mv /path/to/image.qcow2 /path/to/image.qcow2.original
qemu-img convert -O qcow2 /path/to/image.qcow2.original /path/to/image.qcow2