VirtualBox virtual machine migration + vagrant management of existing virtual machines

Cause: My computer (mac) was lagging during the learning period, and the virtual machine + multiple microservices were too stuck. It happened that the school’s computer was useless, so the virtual machine was migrated to the school’s computer (win). The same is true for migrating from win to win.
I feel that the method of using vagrant to re-manage after the migration is a bit troublesome. Friends who have a more concise method are welcome to let me know.

1. Virtual machine migration

Directly use the official import and export functions
insert image description here

2. Vagrant manages existing virtual machines

2.1 Package the original virtual machine into a box

① Check which virtual machines are currently in virtualBox: Open the cmd window, switch to the virtualBox installation path, execute VBoxManage.exe list vms, and see something similar:
"guli_default_1686039503322_97466" {21fe0ff7-16d5-486b-9c91-fbdb978f8b9
insert image description here
② Open a new cmd window, switch to the path where you want to save the box file, and execute

vagrant package --base guli_default_1686039503322_97466 --output vagrant01.box
#guli_default_1686039503322_97466换成自己的
#vagrant01.box可换可不换

2.2 Add the packaged box file to the vagrant environment

In the cmd window, switch to the storage path of the box file and execute

vagrant box add vagrant01 vagrant01.box

If you want to view the existing box files in the current vagrant environment, executevagrant box list

2.3 Initialize the running environment

You can create a new directory to initialize the running environment separately.
Open the cmd window in the new directory and execute

vagrant init vagrant01 #(这个 vagrant01 是vagrant环境中已存在的 box 文件)

After execution, two files are generated in the directory, one .vagrantfor each Vagrantfile, indicating that the initialization is successful.

2.4 Configuration of virtual machine network and login username and password

Add in Vagrantfile

config.vm.network "private_network", ip: "192.168.33.1"
#这个可配置可不配置,配置了之后是固定的以后不会变

This ip is not scribbled, it needs to correspond with the local machine and cannot be scribbled. For example, what I found here is 192.168.33.1, so it needs to be set to 192.168.33.2~254

insert image description here

Remember that the catalog cannot contain Chinese, otherwise an error will be reported. incompatible character encodings: gbk and utf-8 (encoding::compatibilityerror)
If the above error is reported
insert image description here
insert image description here

`

Guess you like

Origin blog.csdn.net/weixin_44485316/article/details/131317442