VirtualBoxでCenOSのクローンを作成する
VirtualBoxで作成した仮想マシンをベースに新しい仮想マシンを用意する方法。
複製元の仮想マシン
- CentOS 6.4 minimal 64bit
- NICはNAT用とホストオンリーアダプター用の2つ
Ubuntu版は、VirtualBoxでクローンを作成する - 作業ノートを参照。
クローン作成
1. VirtualBoxマネージャで、複製元の仮想マシンを選択
仮想マシンは電源オフの状態にする。
2. 右クリックし、メニューから「クローン」を選択
- 「新しいマシン名」ウィザード
- 仮想マシン名を入力する
- 「すべてのネットワークカードのMACアドレスを再初期化」をオン
- 「続ける」ボタンをおして次へ
- 「クローンのタイプ」ウィザード
- 「すべてをクローン」を選択
- 「クローン」ボタンを押す
これでクローンが作成される。
複製後の設定
複製した仮想マシンの設定を行う。
ネットワークの再設定
ネットワークカードのMACアドレスを初期化したので、下記のようにファイルを編集してNICを再設定する。
$ cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:f3:a6:3d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:5a:f7:cb", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:bd:de:99", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:2e:3d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"
複製前の設定(上2つ)を削除し、新しい設定(下2つ)のNAMEをそれぞれeth0, eth1にする。
$ cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:bd:de:99", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:64:2e:3d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
network-scriptsの変更
eth0, eth1のスクリプトのMACアドレスを変更する。
$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:bd:de:99
TYPE=Ethernet
UUID=f49787e6-6174-43e3-9aac-bf1929a7cb77
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
$ cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=08:00:27:64:2e:3d
TYPE=Ethernet
UUID=8f011266-4d43-4e11-be7e-31db6117a531
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
変更するのはHWADDR
の値。先ほど再設定したNICのMACアドレス(ATTR{address}
)と同じにする。
これらの設定後、再起動する。
再起動後、ifconfigコマンドでeth0とeth1が表示されればOK。