Skip to content

Instantly share code, notes, and snippets.

@0xbadfca11
Created January 5, 2016 09:38
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xbadfca11/70f1020ceb69655801ef to your computer and use it in GitHub Desktop.
Save 0xbadfca11/70f1020ceb69655801ef to your computer and use it in GitHub Desktop.
お前らの Optimize-VHD の使い方は間違っている
  • ゲストでsdelete -z→シャットダウンして→Optimize-VHD -Mode Prezeroed
  • ホストでMount-VHDsdelete -zDismount-VHDOptimize-VHD -Mode Prezeroed

これらは時間と書き込み量を浪費しているだけだから今すぐ止めて
Mount-VHD <VHD> [-NoDriveLetter] -ReadOnly -Passthru | Optimize-VHD [-Mode {Quick|Full}] -Passthru | Dismount-VHD
を使うべき。

なんで?

読み取り専用でマウントしている時に Optimize-VHD をすればディスクイメージ内の NTFS から得られる空き領域情報を利用するから。

ヘルプから抜粋。

For a VHDX disk, the default mode is Quick.

意訳 VHDX に対する規定動作は Quick モード。

--Pretrimmed performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The detection of unused space is less effective than Quick mode (in which the virtual hard disk had been mounted read-only) because the scan cannot query information about free space in the NTFS file system within the virtual hard disk. Useful when the VHDX-format file has been used by operating system instances that are at least Windows 8 or Windows Server 2012, or when this cmdlet has already been run on a .vhdx file in Retrim mode.

意訳 Pretrimmed モードは Quick モードのように動くが読み取り専用でマウントしている必要はない。 読み取り専用でマウントしている時の Quick モードが可能な NTFS の空き領域情報を使えないためディスクイメージの空き領域の検出は Quick モードよりも非効率的。 VHDX 形式を Windows 8/Windows Server 2012 以降の仮想マシンで使用している場合、または既にOptimize-VHD -Mode Retrimを行っている場合に有用。

--Prezeroed performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The unused space detection will be less effective than if the virtual hard disk had been mounted read-only as the scan will be unable to query information about free space in the NTFS file system within the virtual hard disk. Useful if a tool was run previously to zero all the free space on the virtual disk as this mode of compaction can then reclaim that space for subsequent block allocations. This form of compaction can also be useful in handling virtual hard disk containing file systems other than NTFS.

意訳 Prezeroed モードは Quick モードのように動くが読み取り専用でマウントしている必要はない。 読み取り専用でマウントしている時には可能な NTFS の空き領域情報を使えないためディスクイメージの空き領域の検出は非効率的。 事前にツールでゼロ埋めしている場合にこのモードが有用。 NTFS 以外を使っているディスクイメージに有用。

--Quick reclaims unused blocks, but does not scan for zero blocks. (Allowable only if the virtual hard disk is mounted read-only.)

意訳 Quick モードは空き領域を回収するがブロック内がすべてゼロになっているブロックを探さない。(読み取り専用でマウントしている時だけ使用可能)

Example 3 Runs the compact operation in Quick mode. (If the VHDX-format file is not attached as read-only prior to the operation, it defaults to Pretrimmed mode.

意訳 読み取り専用でマウントしていない VHDX ファイルに Quick モードで実行すると Pretrimmed モードにデフォルトする。

Linux は?

ファイルシステム情報を使えないからマウントする意味はないけどその場合もゼロ埋めよりも fstrim(8) を使うべき。

see also

http://blogs.technet.com/b/askcore/archive/2012/09/20/compacting-a-dynamically-expanding-virtual-hard-disk-in-windows-server-2012.aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment