Voir : https://wiki.archlinux.org/index.php/Sparse_file
Sparse, fichiers à trous
Voir du dh “ls -s” fallocate truncate
Notes :
du -sh /var/lib/libvirt/images/dic01-disk0 2,0G /var/lib/libvirt/images/dic01-disk0 ls -lh /var/lib/libvirt/images/dic01-disk0 -rw-r--r-- 1 qemu qemu 120G 20 juin 14:53 /var/lib/libvirt/images/dic01-disk0
$ ls -lsh total 22G 16K drwx------ 2 root root 16K août 9 10:42 lost+found 7,7G -rw-r--r-- 1 jibe jibe 120G août 9 11:18 VM152-SUPPMSM-V-clone.img 14G -rw-r--r-- 1 jibe jibe 14G févr. 24 09:15 VM152-SUPPMSM-V-clone.qcow2
$ du -h VM152-SUPPMSM-V-clone.* 7,7G VM152-SUPPMSM-V-clone.img 14G VM152-SUPPMSM-V-clone.qcow2
Unsparse
cp --sparse=never VM152-SUPPMSM-V-clone.raw VM152-SUPPMSM-V-clone_copy.raw
Ou
truncate -c -s $(( 1024 * 1024 + 1024 * $(ls -s VM152-SUPPMSM-V-clone.raw |awk '{print $1}') )) VM152-SUPPMSM-V-clone.raw
Source : https://softwarebakery.com/shrinking-images-on-linux
fdisk -l myimage.img
Disk myimage.img: 6144 MB, 6144000000 bytes, 12000000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ea37d
Device Boot Start End Blocks Id System
myimage.img1 2048 9181183 4589568 b W95 FAT32
Note two things in the output:
truncate --size=$[(9181183+1)*512] myimage.img
rsync : Voir l'option --sparse
-S, --sparse traite les fichiers à trous efficacement
cp --sparse=always et --sparse=never