libvirt/kvm インスタンスでカスタム放浪ボックスを作成するには?

libvirt/kvm インスタンスでカスタム放浪ボックスを作成するには?

VirtualBoxインスタンスからカスタムバグラントボックスを作成するための多くのリソースがインターネットにあります。しかし、kvm / libvirtインスタンスから直接カスタム放浪ボックスを作成する直接的な方法を知りたいです。 VirtualBox を別のプロバイダに変換するために vagrant-mutate またはツールを使用することを提案しないでください。

ベストアンサー1

vagrantと時間を過ごした後、ボックスをカスタマイズするソリューションを得ました。まず、libvirt/qvmにLinux OSをインストールしてログインし、vagrantパスワードでカスタマイズして作成するvagrant

adduser vagrant

vagrantユーザーはパスワードプロンプトなしでsudoコマンドを実行できる必要があります。

sudo visudo -f /etc/sudoers.d/vagrant

そして貼り付け

vagrant ALL=(ALL) NOPASSWD:ALL

放浪者ボックスをカスタマイズしてインストールしたいことをすべて行います(openssh-server以前にインストールしていなかった場合)。

sudo apt-get install -y openssh-server

vagrantユーザーのSSHキーを入力してください。

mkdir -p /home/vagrant/.ssh
chmod 0700 /home/vagrant/.ssh
wget --no-check-certificate \
https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub \
-O /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant /home/vagrant/.ssh

sudoを開いてvi /etc/ssh/sshd_config変更してください。

PubKeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
PermitEmptyPasswords no
PasswordAuthentication no

次のコマンドを使用して SSH サービスを再起動します。

 sudo service ssh restart

ツールが正しくコンパイルされインストールされるように、追加の開発パッケージをインストールします。

sudo apt-get install -y gcc build-essential linux-headers-server

必要に応じて変更して仮想マシンをシャットダウンします。次に、ゲスト仮想マシンが実行されているホストに移動し、 /var/lib/libvirt/images/変更したソースイメージに移動して選択し、その場所にコピーします。/test

cp /var/lib/libvirt/images/test.img  /test 

2つのファイルを作成しmetadata.jsonて入力しますVagrantfile/testmetadata.json

{
  "provider"     : "libvirt",
  "format"       : "qcow2",
  "virtual_size" : 40
}

そしてVagrantfile

Vagrant.configure("2") do |config|
         config.vm.provider :libvirt do |libvirt|
         libvirt.driver = "kvm"
         libvirt.host = 'localhost'
         libvirt.uri = 'qemu:///system'
         end
config.vm.define "new" do |custombox|
         custombox.vm.box = "custombox"       
         custombox.vm.provider :libvirt do |test|
         test.memory = 1024
         test.cpus = 1
         end
         end
end

test.imgをqcow2形式に変換するために使用

sudo qemu-img convert -f raw -O qcow2  test.img  ubuntu.qcow2

ubuntu.qcow2の名前をbox.imgに変更します。

mv ubuntu.qcow2 box.img 

メモ:現在、libvirt-vagrantはqcow2形式のみをサポートしています。そのため、フォーマットを変更しないで、名前をbox.imgに変更してください。デフォルトでは、box.imgという名前の入力を許可するためです。
箱を作る

tar cvzf custom_box.box ./metadata.json ./Vagrantfile ./box.img 

トランプにボックスを追加

vagrant box add --name custom custom_box.box

vagrantを初期化したいディレクトリに移動し、次のコマンドを実行してVagrantファイルを作成します。

vagrant init custom

放浪VM構成の開始

vagrant up --provider=libvirt 

楽しむ! ! !

おすすめ記事