18
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant 1.8 で Linked Clones がサポートされたので試してみた

Last updated at Posted at 2015-12-24

1. はじめに

Linked Cloneはオリジナルのディスクイメージとの差分をディスクイメージとして保存することでディスク容量を大幅に削減することができます。VirtualBoxでは2011年にリリースされた4.1からLinked Cloneが実装されていました。

それから約4年 Vagrant がようやく? Linked Clone をサポートしたので早速使用してみました。

2. Linked Cloneを有効にして仮装マシンを起動する

Boxのインポートは初回起動時に行われるので destroy を行なうか新たに init をする。

seiyakubo$ mkdir linked_clone
seiyakubo$ cd linked_clone
seiyakubo$ vagrant init hashicorp/precise64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Linked Cloneはデフォルトでは無効になっているので,ドキュメントに書いてある通り Vagrantfile を修正し下記を設定を追加する。

config.vm.provider "virtualbox" do |v|
  v.linked_clone = true
end

準備が整ったので仮想マシンを起動する。

seiyakubo$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Preparing master VM for linked clones...
    default: This is a one time operation. Once the master VM is prepared,
    default: it will be used as a base for linked clones, making the creation
    default: of new VMs take milliseconds on a modern system.
==> default: Importing base box 'hashicorp/precise64'...
==> default: Cloning VM...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: linked_clone_default_1450925354550_76866
==> default: Fixed port collision for 22 => 2222. Now on port 2201.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2201 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2201
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: 
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => /Users/seiyakubo/Desktop/linked_clone

Preparing master VM for linked clones と表示されていますね!

作成されたVMファイルの容量を確認してみます。
私の環境では /Users/seiyakubo/Documents/VM 配下に保存されるようにしているので,そこに移動します。

seiyakubo$ cd /Users/seiyakubo/Documents/VM/linked_clone_default_*
seiyakubo$ du -sch *
 60K	Logs
 19M	Snapshots
 12K	linked_clone_default_1450925354550_76866.vbox
 12K	linked_clone_default_1450925354550_76866.vbox-prev
 19M	total

19Mしかディスクを消費していない!
参考までにLinked Cloneを使用しない場合の容量は下記のとおりです。

seiyakubo$ cd /Users/seiyakubo/Documents/VM/no_linked_clone_default_*
seiyakubo$ du -sch *
 60K	Logs
1.1G	box-disk1.vmdk
 12K	no_linked_clone_default_1450925266594_6742.vbox
 12K	no_linked_clone_default_1450925266594_6742.vbox-prev
1.1G	total

かなりディスク容量が節約できていることが確認できました。

3. まとめ

Vagrant 1.8 で Linked Clones がサポートされたので実際に試してディスク容量を節約できることを確認しました。

ちなみに apt-get update && apt-get upgrade を行なった後は

seiyakubo$ du -sch *
 60K	Logs
966M	Snapshots
 12K	linked_clone_default_1450925354550_76866.vbox
 12K	linked_clone_default_1450925354550_76866.vbox-prev
966M	total

だいぶ容量が増えました・・・

18
19
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?