Vhd-util
From Christoph's Personal Wiki
vhd-util
is a utility for working with virtual hard drives (VHDs) in a XenServer environment.
Examples
$ vhd-util snapshot -n my_new_snapshot.vhd -p vm_to_backup.vhd
$ VHD_ID=5057243c-a40f-429c-bc39-3e88882e6711 $ SR_ID=d87d85d7-2de0-417b-9057-ec530f26ea10 $ vhd-util check -n ${VHD_ID}.vhd $ vhd-util scan -f -p -m /var/run/sr-mount/${SR_ID}/${VHD_ID}.vhd $ vhd-util read -p -n /var/run/sr-mount/${SR_ID}/${VHD_ID}.vhd $ vhd-util coalesce -p -n ${VHD_ID}.vhd && watch -n 4 'ps afux|grep vhd-util' $ vhd-util repair -n /var/run/sr-mount/${SR_ID}/${VHD_ID}.vhd
- List of VDIs on host w/specs + calcs:
$ (echo -e "VDI label\tDev\tChain Size\tCoal. %\tSnapshot\tUUID"; \ vhd-util scan -f -p -m /var/run/sr-mount/*/*.vhd | \ awk '{uuid=substr($1,5,36); size=substr($3,6); parent=substr($NF,8,36); if(parent=="none") { \ bob[uuid]=0; bs[uuid]=size}else{bob[uuid]=bob[parent]+1;bs[uuid]=bs[parent]+size}; \ ("/opt/xensource/bin/xe vdi-list params=name-label minimal=true uuid="uuid) |& getline name; if(name=="") name="unknown"; \ ("/opt/xensource/bin/xe vdi-list params=is-a-snapshot minimal=true uuid="uuid) |& getline snapshot; if(snapshot=="") snapshot="?????"; \ ("/opt/xensource/bin/xe vbd-list params=device minimal=true vdi-uuid="uuid) |& getline device; if(device=="") device="----"; \ if(bob[uuid]>0) t=" |"; else t=""; for(i=0;i<bob[uuid];i++) t=t"--"; \ if(bob[parent]=="" && bob[uuid]!=0) print "Orphan below!"; \ if(bob[uuid]==1 && bs[uuid]/2^20>160000) {cp=int((167772160000-bs[parent])/(bs[uuid]-bs[parent])*100+0.5); \ if(cp>100) cp=100; if(cp<0) cp=0; cp=cp"%"}else{cp="-"}; \ printf "%s%s\t%s\t%6.1f GiB\t% s\t%s\t%s\n",t,name,device,int(bs[uuid]/2^30*10+0.5)/10,cp,snapshot,uuid }') | \ column -ts "$(echo -e "\t")"