当前位置: 首页 > news >正文

vagrant怎么在宿主机管理虚拟机镜像box(先搁置)

Vagrant在宿主机管理虚拟机镜像Box的详细指南

1. 基本概念

Vagrant Box是Vagrant的核心组件,它是一个预配置的虚拟机镜像,包含操作系统和基本的软件配置。在宿主机上管理这些Box镜像是Vagrant工作流中的重要环节。

2. 常用Box管理命令

2.1 添加Box到本地仓库

vagrant box add [box名称] [box文件路径/URL]

示例:

vagrant box add ubuntu/trusty64 https://vagrantcloud.com/ubuntu/boxes/trusty64

2.2 列出已安装的Box

vagrant box list

输出示例:

centos/7          (virtualbox, 1905.1)
ubuntu/bionic64   (virtualbox, 20190618.0.0)

2.3 更新Box

vagrant box update [box名称]

示例:

vagrant box update ubuntu/bionic64

2.4 删除Box

vagrant box remove [box名称]

示例:

vagrant box remove centos/7

3. Box文件存储位置

Vagrant Box默认存储在以下位置:

  • Linux/macOS: ~/.vagrant.d/boxes
  • Windows: C:\Users\<username>\.vagrant.d\boxes

4. 高级管理技巧

4.1 查看Box详细信息

vagrant box outdated
vagrant box prune

4.2 手动管理Box文件

你可以直接操作.vagrant.d/boxes目录,但建议使用Vagrant命令进行管理。

4.3 自定义Box存储路径

通过设置环境变量可以改变Box存储位置:

export VAGRANT_HOME=/path/to/custom/location

5. Box版本管理

Vagrant支持Box的多版本管理,可以通过以下方式指定特定版本:

vagrant box add ubuntu/bionic64 --box-version "20190618.0.0"

6. 创建自定义Box

从现有虚拟机创建自定义Box:

vagrant package --output mybox.box

7. 最佳实践

  1. 定期清理不再使用的Box以节省磁盘空间
  2. 为生产环境使用固定版本的Box以保证一致性
  3. 对自定义Box做好版本标记
  4. 考虑使用私有Box仓库管理内部镜像

通过合理管理Box镜像,可以大大提高Vagrant的工作效率和环境一致性。

实践

添加ubuntu到vagrant

vagrant box add ubuntu "/Users/skywalk/VirtualBox VMs/ubuntu/ubuntu.vdi"

但是没有添加成功,可能是空间不够了....以后有时间再调试。

调试

导入box到本地仓库失败报错

skywalk$ vagrant box add freebsd "/Users/skywalk/VirtualBox VMs/freebsd/freebsd.vbox"

==> box: Box file was not detected as metadata. Adding it directly...

==> box: Adding box 'freebsd' (v0) for provider: (amd64)

    box: Unpacking necessary files from: file:///Users/skywalk/VirtualBox%20VMs/freebsd/freebsd.vbox

The box failed to unpackage properly. Please verify that the box

file you're trying to add is not corrupted and that enough disk space

is available and then try again.

The output from attempting to unpackage (if any):

bsdtar: Error opening archive: Unrecognized archive format

检查Virtualbox版本,发现原来是7.x,现在最新7.1.12,升级到新版本试试

升级后问题照旧

尝试转换vbox存盘文件报错

VBoxManage export <vm-name> -o freebsd.ova

-bash: vm-name: No such file or directory

(base) laiweilideMacBook-Air:freebsd skywalk$ VBoxManage export freebsd.vbox -o freebsd.ova

VBoxManage: error: Failed to create the VirtualBox object!

VBoxManage: error: Code NS_ERROR_FAILURE (0x80004005) - Operation failed (extended info not available)

VBoxManage: error: Most likely, the VirtualBox COM server is not running or failed to start.

弄明白了,应该是vbi文件。另外前面的FreeBSD镜像有问题,换用ubuntu的镜像就好了。因为能添加,所以也就不需要转换vbox了

vagrant box add ubuntu "/Users/skywalk/VirtualBox VMs/ubuntu/ubuntu.vdi"

好吧,又报错了,不过这回看着可能是磁盘空间不够了

==> box: Adding box 'ubuntu' (v0) for provider: (amd64)box: Unpacking necessary files from: file:///Users/skywalk/VirtualBox%20VMs/ubuntu/ubuntu.vdi
The box failed to unpackage properly. Please verify that the box
file you're trying to add is not corrupted and that enough disk space
is available and then try again.
The output from attempting to unpackage (if any):bsdtar: Error opening archive: Unrecognized archive format

http://www.dtcms.com/a/352484.html

相关文章:

  • 中国移动云电脑一体机-创维LB2004_瑞芯微RK3566_2G+32G_开ADB安装软件教程
  • 【自监督检测】HASSOD:Hierarchical Adaptive Self-Supervised Object Detection
  • 《基于 Spring Boot 的足球青训俱乐部管理后台系统设计与实现--文末获取源码》
  • wsl安装的系统更换路径
  • 【Modbus-TCP】linux为主机—PC为从机通信
  • 8.26 支持向量机
  • GD32和STM32的区别在哪里?
  • Python训练营打卡 DAY 48 随机函数与广播机制
  • 摩尔信使MThings V0.8.1更新要点
  • flume监控目录文件实战:三种 Source 方案对比与配置指南
  • vue新增用户密码框自动将当前用户的密码自动填充的问题
  • Windows server 2019安装wsl2
  • Python3.11升级到高版本-aioredis兼容问题
  • 洛谷: CF632D Longest Subsequence-普及+/提高
  • 下载python离线安装包,在无网络机器安装方法
  • DeepSeek用C编写的支持Zstandard 压缩的 ZIP 工具
  • 2020-2022年 CLES村庄、农户调查问卷、清理和审核报告相关数据
  • 【RAGFlow代码详解-25】HTTP 接口
  • VGG改进(5):基于Multi-Scale Attention的PyTorch实战
  • 解析xml文件并录入数据库
  • 给高斯DB写一个函数实现oracle中GROUPING_ID函数的功能
  • 分布式锁;Redlock
  • 【世纪龙科技】职业院校汽车职业体验中心建设方案
  • imx6ull-驱动开发篇43——I.MX6U 的 I2C 驱动分析
  • 如何在ubuntu下制作linux镜像
  • 深度学习之卷积神经网络原理(cnn)
  • AT_abc401_f [ABC401F] Add One Edge 3
  • Rocky9配置完VMware桥接模式后没有自动获取IP
  • 系统架构设计师-【2025上半年论文题目分享】
  • 六足机器人系统设计与实现cad+设计说明书+电路原图模式+装配图+电路图