如何在 Linux 中将下载的 .box 文件添加到 Vagrant

[ad_1]

Linux 发行版可以以多种不同的格式下载。 最广泛使用的格式是 ISO。 除了 ISO 之外,它们还通过预配置的映像进行分发,例如 .box 对于流浪者, .vbox 对于虚拟盒子, .vmdk 对于 Vmware, .qcow2 用于 KVM/openStack,并压缩 RAW 等等。因此您可以快速获取您选择的映像并使用相应的虚拟化应用程序运行它。 这个简短的指南解释了如何添加下载的 .box 文件到 Linux 操作系统中的 Vagrant。

还不知道的小伙伴们, 流浪汉 是用于构建和维护虚拟软件开发环境的开源软件。 它提供了一个干净、易于配置、可重现和可移植的开发环境。 这 .box 是 Vagrant 环境的格式和扩展。 流浪盒子只是基本图像。 如今,许多操作系统都可以在 .box 图像文件格式。

添加已下载 .box 文件到 Linux 中的 Vagrant

今天我想试试新发布的 Fedora 我的系统上有 33 个操作系统。 与其从 ISO 文件手动下载和安装它,我决定抓住现成的 Fedora 33 Vagrant box 运行几天 VirtualBox 看看它是如何工作的。 所以我去了 Fedora 官方下载页面并下载了 .box 申请 Fedora 33. 然后我在我的 Ubuntu 桌面上安装了 Vagrant,如以下指南中所述:

  • 如何在 Linux 上安装 Vagrant

安装 Vagrant 后,我​​去了我下载的位置 .box 文件并使用命令将其添加到 Vagrant:

$ vagrant box add --name fedora33 Fedora-Cloud-Base-Vagrant-33-1.2.x86_64.vagrant-virtualbox.box

这里, Fedora33 是我分配给虚拟机的名称, ”Fedora——Cloud-Base-Vagrant-33-1.2.x86_64.vagrant-virtualbox.box” 是个 .box 我从下载的文件 Fedora 下载页面。

示例输出:

==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'fedora33' (v0) for provider: 
    box: Unpacking necessary files from: file:///home/sk/Vagrant/Fedora-Cloud-Base-Vagrant-33-1.2.x86_64.vagrant-virtualbox.box
==> box: Successfully added box 'fedora33' (v0) for 'virtualbox'!
在 Linux 中将下载的 .box 文件添加到 Vagrant

.bo为提供程序添加了 x 文件。 就我而言,提供者是 Oracle VirtualBox.

让我们通过列出可用的 Vagrant 框来验证它,如下所示:

$ vagrant box list 
fedora33 (virtualbox, 0)
列出 Vagrant 盒子

接下来使用命令初始化 Vagrant 框:

$ vagrant init fedora33

示例输出:

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.

现在开始 Fedora 通过运行以下命令来虚拟机:

$ vagrant up

示例输出:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'fedora33'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: Vagrant_default_1606997309282_57379
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (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:2222
    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: 6.0.0 r127566
    default: VirtualBox Version: 6.1
==> default: Rsyncing folder: /home/sk/Vagrant/ => /vagrant
开始 Fedora 命令行中的流浪框开始 Fedora 命令行中的流浪框

这 Fedora 33 vagrant box 已启动并运行 VirtualBox.

打开 Virtualbox 管理器并检查它是否正在运行:

Fedora  vagrant box 正在运行 VirtualBoxFedora vagrant box 正在运行 VirtualBox

您还可以使用以下命令从终端检查 vagrant 框的状态:

$ vagrant status

示例输出:

Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

是的,VM 正在运行!

通过以下方式连接并访问正在运行的 VM ssh 如下所示:

$ vagrant ssh

开始使用虚拟机:

Last login: Thu Dec  3 12:13:42 2020
[[email protected] ~]$ cat /etc/redhat-release 
Fedora release 33 (Thirty Three)
[[email protected] ~]$ 

请注意,我下载了 Virtualbox 盒映像,因此 Fedora VM 在 Virtualbox 中自动启动。 如果您下载了 libvirt/kvm 映像,它将在 kvm 管理程序下运行。

嗯,这就是现在。 您现在学习了如何添加已下载的 .box 文件到 Linux 中的 vagrant。 您还学习了如何启动 Vagrant box 以及如何连接以从命令行访问它。

要了解有关 Vagrant 用法的更多信息,请参阅以下指南:

  • Vagrant 教程——Vagrant 入门

希望这可以帮助。

LinuxVagrantVirtualBox虚拟化

[ad_2]

Related Posts