如何在Linux中将已下载的.box文件添加到无业游民
Linux发行版可以多种不同格式下载。 最广泛使用的格式是ISO。 除ISO外,它们还通过预先配置的映像分发,例如 .box
对于流浪汉, .vbox
对于虚拟盒子, .vmdk
对于Vmware, .qcow2
用于KVM / openStack,并已压缩 RAW
等。因此,您可以快速获取所需的映像并使用相应的虚拟化应用程序运行它。 本简要指南说明了如何添加已下载的内容 .box
文件到Linux操作系统中的Vagrant。
对于那些还不知道的人 流浪汉 是用于构建和维护虚拟软件开发环境的开源软件。 它提供了一个干净,易于配置,可复制且可移植的开发环境。 的 .box
是Vagrant环境的格式和扩展。 无业游民的盒子只是基础图像。 如今,许多操作系统都可以在 .box
图像文件格式。
添加下载 .box
在Linux中文件流浪汉
今天,我想在我的系统上尝试新发布的Fedora 33 OS。 我决定从现成的Fedora 33 Vagrant盒中取出现成的Fedora 33 Vagrant盒,然后在VirtualBox中运行几天,以查看其工作原理,而不是从ISO文件中手动下载和安装它。 所以我去了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
这里, 浅顶软呢帽33 是我分配给虚拟机的名称, “ Fedora云基无业游民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'!
将下载的.box文件添加到Linux中的Vagrant
的 .bo
为提供者添加了x文件。 就我而言,提供者是Oracle VirtualBox。
让我们通过列出可用的Vagrant框来验证它,如下所示:
$ vagrant box list
fedora33 (virtualbox, 0)
列出游民箱
接下来,使用以下命令初始化“ 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 vagrant框
Fedora 33 vagrant框已启动并在VirtualBox下运行。
打开Virtualbox管理器并检查其是否正在运行:
Fedora vagrant框正在VirtualBox下运行
您还可以使用以下命令从终端检查“无业游民”框的状态:
$ 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 ssh
如下所示:
$ vagrant ssh
开始使用VM:
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用法的更多信息,请参阅以下指南:
- 流浪汉教程–流浪汉入门
希望这可以帮助。
LinuxVagrantVirtualBox虚拟化