VBoxManageで仮想OSディスクを圧縮 の支援ツール [作業中]

ツールの概要

仮想OSイメージファイル(VDI )を圧縮 するツールを提供します。

  1. VBoxManage コマンドを起動して、処理状況を監視する。
  2. 結果はログとしてテキストファイルで管理できる。

・サイズ変更の機能は初期バージョンでは提供しません。

  

詳細

仮想イメージのVDIファイルのメンテナンスでは、圧縮が一番時間が掛かり作業と感じています。

それを支援し、記録に残すツールを公開します。

  1. ツールはMicrosoft Excel + VBA で作成。
  2. VBoxManage コマンドを起動して、動作状況を監視する。
  3. 結果はログとしてテキストファイル、及び Excel シート上で管理する。
  4. Excel 2000 バージョンから動作するように作成する。
    Excel 2000 以上ならばWindows OS のバージョンは選ばない。

  

  

VirtualBox VBoxManageで仮想OSディスクを圧縮、サイズ変更の支援ツール

  

VirtualBox VBoxManageで仮想OSディスクを圧縮、サイズ変更の支援ツール

 

備考

  1. サイズ変更の機能は初期バージョンが安定した状態になってから、次期バージョンで検討します。 
    但し、ツール内部の構造は機能追加をしやすいような形のプログラム構成にするつもりです。

 


技術資料

1. 「 VBoxManage modifyhd 」コマンドプロンプトの内容

VBoxManage modifyhd を入力すると以下の引数に関する情報が表示される。

VirtualBox VBoxManageで仮想OSディスクを圧縮

 

C:¥Program Files¥Oracle¥VirtualBox>VBoxManage modifyhd
Usage:

VBoxManage modifyhd         <uuid|filename>
                            [--type normal|writethrough|immutable|shareable|
                                    readonly|multiattach]
                            [--autoreset on|off]
                            [--property <name=[value]>]
                            [--compact]
                            [--resize <megabytes>|--resizebyte <bytes>]

C:¥Program Files¥Oracle¥VirtualBox>





 

2. VirtualBox Help v4.3.24 の内容

V4.3.24 とは言っても頻度の高いバージョンアップにHelpも含む各種ドキュメントが追い付いていない状態です。

よって、事前にバージョンアップ内容も確認もしておかないと正確な情報を取得するのは無理があるでしょう。

  

Oracle VM VirtualBox > VBoxManage > VBoxManage modifyhd

  

この内容も英語だが、Helpファイルの状態での翻訳は手間が掛かり過ぎる。

Webサイトに引用形式にしておけば、必要な部分が右クリックで簡単に機械翻訳できる。

 

VirtualBox Help v4.3.24 modifyhd の内容

8.23. VBoxManage modifyhd
With the modifyhd command, you can change the characteristics of a disk image after it has been created:

VBoxManage modifyhd         <uuid|filename>
                            [--type normal|writethrough|immutable|shareable|
                                    readonly|multiattach]
                            [--autoreset on|off]
                            [--compact]
                            [--resize <megabytes>|--resizebyte <bytes>]

Note
Despite the "hd" in the subcommand name, the command works with all disk images, not only hard disks. For compatibility with earlier versions of VirtualBox, the "modifyvdi" command is also supported and mapped internally to the "modifyhd" command.

The disk image to modify must be specified either by its UUID (if the medium is registered) or by its filename. Registered images can be listed by VBoxManage list hdds (see Section 8.4, “VBoxManage list” for more information). A filename must be specified as valid path, either as an absolute path or as a relative path starting from the current directory.

The following options are available:

With the --type argument, you can change the type of an existing image between the normal, immutable, write-through and other modes; see Section 5.4, “Special image write modes” for details.

For immutable (differencing) hard disks only, the --autoreset on|off option determines whether the disk is automatically reset on every VM startup (again, see Section 5.4, “Special image write modes”). The default is "on".

With the --compact option, can be used to compact disk images, i.e. remove blocks that only contains zeroes. This will shrink a dynamically allocated image again; it will reduce the physical size of the image without affecting the logical size of the virtual disk. Compaction works both for base images and for diff images created as part of a snapshot.

For this operation to be effective, it is required that free space in the guest system first be zeroed out using a suitable software tool. For Windows guests, you can use the sdelete tool provided by Microsoft. Execute sdelete -z in the guest to zero the free disk space before compressing the virtual disk image. For Linux, use the zerofree utility which supports ext2/ext3 filesystems. For Mac OS X guests, use the Erase Free Space feature of the built-in Disk Utility. Use Zero Out Data there.

Please note that compacting is currently only available for VDI images. A similar effect can be achieved by zeroing out free blocks and then cloning the disk to any other dynamically allocated format. You can use this workaround until compacting is also supported for disk formats other than VDI.

The --resize x option (where x is the desired new total space in megabytes) allows you to change the capacity of an existing image; this adjusts the logical size of a virtual disk without affecting the physical size much.[38] This currently works only for VDI and VHD formats, and only for the dynamically allocated variants, and can only be used to expand (not shrink) the capacity. For example, if you originally created a 10G disk which is now full, you can use the --resize 15360 command to change the capacity to 15G (15,360MB) without having to create a new image and copy all data from within a virtual machine. Note however that this only changes the drive capacity; you will typically next need to use a partition management tool inside the guest to adjust the main partition to fill the drive.

The --resizebyte x option does almost the same thing, except that x is expressed in bytes instead of megabytes.

 

備考

  • 上記で圧縮の引数は「 --compact 」だが、引数の順番の位置が合っていればハイフン無しの「 compact 」でも動作した。

  

< TOPへ >

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


コメントを入れる前に以下を御覧ください。
VirtualBox のエラー & よくある質問

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください