天天看點

VirtualBox之虛拟機更換虛拟磁盤

本文主要是在linux中安裝VirtualBox後,使用VBoxManage配置虛拟機。

本文指令支行環境如下:

主控端OS:fedora33

VirtualBox版本:6.1.22

虛拟機OS:CentOS7

虛拟機name:centos-7-20210521

檢視VirtualBox環境中有哪此虛拟磁盤,指令如下:

[[email protected] ~]# VBoxManage list hdds
UUID:           1a1982b2-ffc3-465f-96fe-350f7d54fd4b
Parent UUID:    base
State:          inaccessible
Type:           normal (base)
Location:       /root/VirtualBox VMs/centos-7/centos-7.vdi
Storage format: VDI
Capacity:       0 MBytes
Encryption:     disabled
           

使用如下指令檢視虛拟機資訊:

VBoxManage showvminfo centos-7-20210521
           

因虛拟機詳情資訊很多,我就不詳細列出了,大家隻需要找到如下資訊:

IDE (1, 0): Empty
SATA (0, 0): /root/VirtualBox VMs/centos-7/centos-7.vdi (UUID: 239206ae-49a3-4ed6-abfd-11b65b068b60)
           

其中的“SATA (0, 0)”代表是這兩個值“--port 0 --device 0”

現在可以從将這個磁盤從虛拟機上删除,但不删除虛拟磁盤的對應的檔案

删除指定虛拟機上的磁盤指令如下:

[[email protected] ~]# VBoxManage storageattach centos-7-20210521 --storagectl SATA --port 0 --device 0 --type hdd --medium none
           

再執行如下指令,從虛拟環境中删除磁盤,執行如下指令會删除對應的vdi檔案,如還需要需要備份好,指令如下 :

[[email protected] centos-7-20210521]# VBoxManage closemedium disk 239206ae-49a3-4ed6-abfd-11b65b068b60 --delete
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
[[email protected] centos-7-20210521]# 
           

再次檢視虛拟磁盤,已經沒有了如下 :

[[email protected] ~]# VBoxManage list hdds
[[email protected] ~]# 
           

再重新挂載虛拟磁盤到指定虛拟機上,指令如下 :

[[email protected] ~]# VBoxManage storageattach centos-7-20210521 --storagectl SATA --port 0 --device 0 --type hdd --medium "/root/VirtualBox VMs/centos-7/centos-7.vdi"
[[email protected] ~]# 
           

啟動虛拟機:

[[email protected] ~]# VBoxManage startvm centos-7-20210521 --type headless
Waiting for VM "centos-7-20210521" to power on...
VM "centos-7-20210521" has been successfully started.
[[email protected] ~]# 
           

正常啟動,完美

繼續閱讀