有史以来最酷的项目:bashvm,创建、配置和管理虚拟机

今天我们要看看一个非常酷的项目:bashvm.com

该项目允许您使用(您猜对了)bash 创建、修改和管理虚拟机。整个环境被编码为 bash shell 脚本。这真的很整洁!

在家里,我有一个中等的 VM 环境,运行在带有 i5-8250U CPU 的专用 Protectli 系统上(正如我所说,我的需求并不大)。我没有多余的物理机器来设置 bashvm 进行测试,因此我决定创建一个嵌套虚拟化 VM。换句话说,虚拟机本身充当其自己的虚拟机的主机。

这非常简单,但是有一个关键的“qm”命令我必须在谷歌上搜索。

我设计了一个名为 bashvm 的 Deb 12 系统,具有 4 个 vCPU、16GB RAM、20GB 根目录和第二个 60GB 磁盘,我将其安装为 /data。

然后我前往bashvm.com并按照那里的步骤安装 bashvm。非常容易做到——只需克隆存储库并运行安装程序,然后安装程序就会在我的 12.5 系统上安装 277 个软件包(!)。

然后你就

bash bashvm.sh

您将看到一个令人愉快的简约菜单:

那时,您就可以开始玩了。

自然地,我就跳入虚拟机并尝试创建一个。但这不起作用,我发现正确的做法是首先创建一个存储池。

我备份并创建了一个存储池(“stor1”)并将其放入 /data:

 Name    State     Autostart   Persistent   Capacity    Allocation   Available
--------------------------------------------------------------------------------
 stor1   running   yes         yes          58.76 GiB   633.79 MiB   58.14 GiB

这样一来,我就可以创建一个虚拟机了:

Enter your choice: 8
Enter the name for the new / existing virtual machine: vm1
Enter the amount of memory in MB (e.g., 1024): 1024
Enter the number of virtual CPUs (e.g., 2): 1
Would you like to download or use a debian 12 iso? (y/n): y
Enter the storage pool name [default]: stor1
File debian-12.5.0-amd64-netinst.iso already there. Canceling re-download.
Would you like to create a new volume? (y/n): y
Enter the name of the new storage volume (e.g., new-vm): vol2
Enter the size of the volume (e.g., 10GB): 10GB
Enter the storage pool name [default]: stor1
Vol vol2.qcow2 created

Enter the network name to connect the virtual machine to [default]:
Enter the mac address for this vm (nothing for auto generate):
Domain 'vm1' defined from /etc/libvirt/qemu/vm1.xml

Please note that there will be a vnc port automatically assigned to this vm.
This is optional if needed and the ports will start at 5900 and onward.

顺便说一句,您会注意到 Debian 12 CD 已经在那里。这是之前的一次尝试。令我高兴的是,bashvm 会为您下载 ISO 并将其放入您的存储池中。这是企业级平台可以学习的技巧!

完成上述操作后,我启动了虚拟机。

Enter your choice: 2
Enter the name of the virtual machine to start: vm1
Domain 'vm1' started


==================== Manage Virtual Machine ====================
 s.  Show all virtual machines     1. Show more details of a VM
 2.  Start a VM                    3. Reboot a VM
 4.  Shutdown a VM (graceful)      5. Shutdown a VM (force)
 6.  Enable autostart of a VM      7. Disable autostart of a VM
 8.  Create a new / existing VM    9. Undefine a VM
10.  Create a new VM (Automated)  11. Console into a VM
12.  Change resources of a VM     13. Delete a VM
 q.  Back to main menu

Enter your choice: s
 Id   Name   State
----------------------
 1    vm1    running

我可以在 ps 中看到它:

libvirt+   12406       1 10 15:40 ?        00:01:55 /usr/bin/qemu-system-x86_64 -name guest=vm1,debug-threads=on...

接下来我尝试连接到控制台,但不幸的是无法进一步连接。不知道为什么……

==================== Manage Virtual Machine ====================
 s.  Show all virtual machines     1. Show more details of a VM
 2.  Start a VM                    3. Reboot a VM
 4.  Shutdown a VM (graceful)      5. Shutdown a VM (force)
 6.  Enable autostart of a VM      7. Disable autostart of a VM
 8.  Create a new / existing VM    9. Undefine a VM
10.  Create a new VM (Automated)  11. Console into a VM
12.  Change resources of a VM     13. Delete a VM
 q.  Back to main menu

Enter your choice: 11
Enter the VM name to console into: vm1
Connected to domain 'vm1'
Escape character is ^] (Ctrl + ])

那时,我按了几次回车键,但从未得到回应。 bashvm 只是在幕后调用“virsh console”,我有一种感觉,我只是没有做正确的事情。连接到主机的5900进行vnc要求输入密码,但我不知道,因为从来没有要求我输入密码。

好吧,我已经超出了我的深度。这就是为什么我购买虚拟机而不是尝试运行自己的 LOL。

尽管如此,看起来还是一个非常酷的项目。你绝对应该检查一下。我的意思是,还有什么比使用 bash 来创建、配置和管理虚拟机更低端的呢?


【AD】炭云:768元/年/1GB内存/20GB SSD空间/2TB流量/500Mbps-1Gbps端口/独立IPv4/KVM/广州移动

【AD】美国洛杉矶CN2 VPS/香港CN2 VPS/日本CN2 VPS推荐,延迟低、稳定性高、免费备份_搬瓦工vps