-
概述
- vagrant 修改时候, 遇到的坑
-
背景
- 初学 vagrant
- 刚开始, 该配置需要 先 destroy 再 up 生效
- 我感觉很麻烦
- 后来找到了一个叫 reload 的命令
- 据说可以不用 destroy 就直接 重载配置
- 而且还要比普通的快一些
- 结果一试, 就试出了问题
-
类型
- 这是一篇 教程向 的博客
- 如果比较着急, 可以直接到后面找结论
- 这是一篇 教程向 的博客
-
环境
- OS
- win10 - 1909
- virtualBox
- 6.1.14
- vagrant
- 2.2.13
- precise64
- 1.1.0
- OS
1. 场景
-
概述
- 问题的场景
-
思路
- 启动 vagrant
- 修改配置
- 重载 vagrant
1. 启动 vagrant
-
配置
# vagrant init 已经执行 Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" # 这是我添加的共享目录 config.vm.synced_folder "vagrant-data", "/vagrant_data", create: true, id: "data" end
-
命令
> vagrant up
-
结果
- 成功启动
- 共享目录有两个
- 默认的目录 vagrant
- 我创建的 data 目录
2. 修改配置
-
配置
Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" # 这是我添加的共享目录 config.vm.synced_folder "vagrant-data", "/vagrant_data", create: true, id: "data" # 关闭默认的共享目录 config.vm.synced_folder ".", "/vagrant", disabled: true end
-
命令
> vagrant reload
-
结果
- vagrant 无法连接
- 日志再 ref 里
- 失败: ssh 超时
- vagrant status 查看,
- 发现 vagrant 的状态, 既然是 running
- vagrant 无法连接
3. 疑问: 为什么超时了
-
概述
- 问题
-
问题
- 为什么超时了
- 我只改了 共享目录 的配置
- 我没有动 网络 的东西
- 为什么 提示的是 ssh 连不上?
- 明明 running 了, 我还是连不上
- 为什么超时了
2. 尝试
- 概述
- 尝试解决问题
1. ssh
-
概述
- ssh 的思路
-
问题
- 我明明没改网络配置
-
尝试1: destroy 后再 up
-
操作
> vagrant destroy > vagrant up > vagrant ssh
-
结果
- 没有一点问题
-
结论
- 就是我改 共享目录 改坏的
-
-
尝试2: 百度
-
操作
- 搜索了一堆 vagrant 连不上的问题
- 附带了一些日志的片段
- 搜索了一堆 vagrant 连不上的问题
-
结果
-
各路结果都是要检查 ssh
- 有检查 key 的
- 有删配置的
- 有直接 destroy 再 up 的
-
但是 ssh 我碰都没碰过
-
-
2. 虚机
-
概述
- 换个角度找问题
-
尝试3: 既然虚拟机启动了, 为什么不 ssh 去看看
-
操作
- 确认 ssh 端口
- 正常启动的日志, 告诉我 22 端口被映射到了 2222
- 账户
- 也不知道在哪看到的, 默认账户密码, 都是 vagrant
- 打开虚机
- 结果我惊了
- 虚机启动中, 被卡住了
- 确认 ssh 端口
-
结果
- 虚机卡在一个界面
- 日志在 ref 里
- 大概提示 fsck 检查
- /vagrant 挂载失败
- 需要手动确认, 是 跳过 还是 手动处理
- 一直卡在这, 不会自己走
- 虚机卡在一个界面
-
3. 结果
-
概述
- 初步的结论
-
初步结论
- 修改 共享目录, 导致 vagrant 无法启动
-
下一步
- 修改 共享目录 的配置, 就能搞成这样, 怎么感觉不科学...
- 自己试试
- 修改 共享目录 的配置, 就能搞成这样, 怎么感觉不科学...
3. 实验
- 概述
- 自己的一些尝试
- 不想写太详细了
1. 尝试1: 没有任何共享目录
-
概述
- 尝试1
-
操作
- vagrant up
- vagrant reload
-
结果
- 没有问题
2. 尝试2: 添加共享目录
-
概述
- 尝试2
-
操作
- vagrant up
- 添加了一条共享目录
- vagrant reload
-
结果
- 没有问题
3. 尝试3: 修改共享目录
-
概述
- 尝试3
-
操作
- vagrant up
- 修改了一条共享目录
- vagrant reload
-
结果
- 虚机 running
- ssh 失败
- 卡在了 fsck
4. 尝试4: 删除共享目录
-
概述
- 尝试4
-
操作
- vagrant up
- 删除了一条共享目录
- vagrant reload
-
结果
- 虚机 running
- ssh 失败
- 卡在了 fsck
5. 结论
-
一下操作, 可能会使得 vagrant 重启时, 卡在 fsck
- 修改 共享目录
- 删除 共享目录
-
所以, 这是为啥呢?
- 简单的看了看
4. 继续
-
概述
- 好奇这是为啥
-
准备
-
mount
- 概述
- 查看 mount 情况的命令行工具
- 概述
-
fstab
- 概述
- linux 中描述 挂载 的文件
- 检查
- vagrant 的共享目录, 确实在里面
- 概述
-
vagrant 的启动日志
- 概述
- 这是关键
- 概述
-
1. 看日志
-
概述
- 查看日志
-
比对: 启动超时 和 启动成功 的日志
- 结果
- 超时的日志, 没有对 共享目录 做任何调整
- 反倒是成功的日志, 在 ssh 通过了之后, 会对 共享目录 做一些修改...
- 结果
2. mount 和 fstab
-
概述
- 进入系统查看
-
结论
- mount 结果正确
- fstab 也是有专门的修改
5. 总结与后续
-
原因
- 修改 vagrantfile, 导致 虚机开机自检 无法通过
- fsck
- 修改 vagrantfile, 导致 虚机开机自检 无法通过
-
机制
- 新的 vagrant 虚机, 默认第一次是可以启动的
- 有些配置, 是需要在 ssh 通过之后, 才能去修改
- 如果启动中出现问题, 很容易出现 ssh 失败的假象
- 配合 running 的状态, 更容易误导人
-
办法
- 是在没招了, 去虚机上看看, 可能会有新发现
-
建议
- 对 vagrant 共享目录的配置
- 尽量一开始就配置好
- 如果要更改, 尽量只添加, 不做其他操作
- 换镜像(box)
- 可能真的是我镜像的问题, 没准别的镜像就不会有这种问题了
- 对 vagrant 共享目录的配置
-
修改存储配置
-
场景
- 忽然不想暴露目录了
-
解决
- 想办法跳过 开头的 fsck 自检查
- 通过 权限 设置, 来对特定的用户屏蔽
-
-
后续
- fsck
- fstab
- linux 权限
ps
-
ref
- 暂无
-
日志
-
vagrant
# 失败: ssh 超时 $ vagrant reload ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'hashicorp/precise64' version '1.1.0' is up to date... ==> default: Clearing any previously set forwarded ports... ==> 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: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Remote connection disconnect. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... Timed out while waiting for the machine to boot. This means that Vagrant was unable to communicate with the guest machine within the configured ("config.vm.boot_timeout" value) time period. If you look above, you should be able to see the error(s) that Vagrant had when attempting to connect to the machine. These errors are usually good hints as to what may be wrong. If you're using a custom box, make sure that networking is properly working and you're able to connect to the machine. It is a common problem that networking isn't setup properly in these boxes. Verify that authentication configurations are also setup properly, as well. If the box appears to be booting properly, you may want to increase the timeout ("config.vm.boot_timeout") value. # 成功: 我赶在超时之前, 登上了 vagrant 虚机, 手动跳过了 fsck ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'hashicorp/precise64' version '1.1.0' is up to date... ==> default: Clearing any previously set forwarded ports... ==> 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: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection aborted. Retrying... default: Warning: Connection reset. Retrying... ==> 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: 4.2.0 default: VirtualBox Version: 6.1 ==> default: Mounting shared folders... default: /vagrant => G:/VagrantVMs/vagrant_book_example default: /vagrant_data => G:/VagrantVMs/vagrant_book_example/vagrant-data ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run.
-
precise64
# 虚机启动时, 卡住的日志 fsck from util-linux 2.20.1 fsck from util-linux 2.20.1 dev/mapper/precise64-root: clean, 61688/5185536 files, 597883 20711424 blocks /dev/sda1: clean, 230/124496 files, 40607/248832 blocks rpcbind: Cannot open '/run/rpcbind/rpcbind.xdr' file for reading, errno 2 (No such file or directory) rpcbind: Cannot open '/run/rpcbind/portmap.xdr' file for reading, errno 2 (No such file or directory) /sbin/mount.vboxsf : mounting failed with the error: Protocol error mountall: mount /uagrant [458] term inated with status 1 mountall: Filesystem could not be mounted: /vagrant Am error occurred while mounting /uagrant. Press S to skip mounting or M for manual recovery
-