基于ubuntu22.04安装KVM虚拟机
操作系统镜像:ubuntu-22.04.1-live-server-amd64.iso。宿主机OS使用的是最小化安装ubuntu-22.04。
·
环境说明
操作系统镜像:ubuntu-22.04.1-live-server-amd64.iso
可以直接去官网下载Get Ubuntu Server | Download | Ubuntu
宿主机OS使用的是最小化安装ubuntu-22.04
参考如下链接执行:
Ubuntu 22.04 之 KVM 安装手札-ubuntu20.04安装kvm
-
更新 Ubuntu 22.04
-
检查虚拟化是否开启
3、在 Ubuntu 22.04 上安装 KVM
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
参考链接:
KVM hypervisor: a beginners’ guide | Ubuntu
Install KVM Ubuntu 22.04 - Step-by-Step - Virtualization Howto
创建虚拟网桥
sudo virsh net-define /dev/stdin <<EOF
<network>
<name>virbr0</name>
<forward mode="bridge"/>
<bridge name="virbr0"/>
</network>
EOF
sudo virsh net-start virbr0
sudo virsh net-autostart virbr0
4、创建 KVM虚拟机
virt-install --name=k8s01 --ram 1024 --vcpus=2 --disk path=~/k8s01.img,size=30 --accelerate --cdrom ~/CentOS-7-x86_64-DVD-2009.iso
virt-install --name=k8s02 --ram 1024 --vcpus=2--disk path=~/k8s02.qcow2,size=10,format=qcow2,bus=virtio --location=~/CentOS-7-x86_64-DVD-2009.iso --network network=default,model=virtio --graphics=none --console=pty,target_type=serial --extra-args="console=tty0 console=ttyS0"
5、登录 KVM虚拟机
virt-viewer --connect qemu:///system --wait k8s01
=========================================================================
报错记录
视图通过下面的这些方式创建ubuntu22.04虚拟机均失败
sudo virt-install --name=rke2-master-0-1 --disk path=ubuntu22.04-test.qcow2,size=20 --ram=8096 --vcpus=4 --os-variant ubuntu22.04 --network bridge=virbr0 --graphics vnc,listen=0.0.0.0 --noautoconsole --location 'http://archive.ubuntu.com/ubuntu/dists/jammy/main/installer-amd64/' --extra-args 'console=ttyS0,115200n8 serial'
sudo virt-install --name=rke2-master-0-1 --disk path=ubuntu22.04-test.qcow2,size=20 --ram=8096 --vcpus=4 --os-variant ubuntu22.04 --network bridge=virbr0 --graphics vnc,listen=0.0.0.0 --noautoconsole --location 'http://archive.ubuntu.com/ubuntu/dists/jammy' --extra-args 'console=ttyS0,115200n8 serial'
sudo virt-install --name=rke2-master-0-1 --disk path=ubuntu22.04-test.qcow2,size=20 --ram=8096 --vcpus=4 --os-variant ubuntu22.04 --network bridge=virbr0 --graphics vnc,listen=0.0.0.0 --noautoconsole --cdrom ubuntu-22.04.3-live-server-amd64.iso --extra-args 'console=ttyS0,115200n8 serial'
sudo virt-install --name=rke2-master-0-1 --disk path=ubuntu22.04-test.qcow2,size=20 --ram=8096 --vcpus=4 --os-variant ubuntu22.04 --network bridge=virbr0 --graphics vnc,listen=0.0.0.0 --noautoconsole --location ubuntu-22.04.3-live-server-amd64.iso --extra-args 'console=ttyS0,115200n8 serial'
sudo virt-install --name rke2-master-0-1 --os-variant ubuntu22.04 --vcpus 4 --memory 8096 --location ubuntu-22.04.3-live-server-amd64.iso,kernel=/mnt/casper/vmlinuz,initrd=/mnt/casper/initrd --network bridge=virbr0,model=virtio --disk path=ubuntu22.04-test.qcow2,size=20 --graphics none --extra-args='console=ttyS0,115200n8 --- console=ttyS0,115200n8' --debug
报错如下
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (guest:330) Setting Guest osinfo name <_OsVariant name=generic>
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (guest:330) Setting Guest osinfo name <_OsVariant name=ubuntu22.04>
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urlfetcher:71) Using scratchdir=/var/lib/libvirt/boot
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urldetect:285) Finding distro store for location=ubuntu-22.04.3-live-server-amd64.iso
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urldetect:875) variant=ubuntu22.04 has distro=ubuntu, looking for matching distro store to prioritize
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urldetect:884) Prioritizing distro store=<class 'virtinst.install.urldetect._UbuntuDistro'>
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urlfetcher:34) Generating iso filelist: ['xorriso', '-indev', 'ubuntu-22.04.3-live-server-amd64.iso', '-print', 'VIRTINST_BEGINLIST', '-find']
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urldetect:45) Failed to acquire file=current/images/MANIFEST: Couldn't acquire file /current/images/MANIFEST: iso doesn't have file=/current/images/MANIFEST
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urldetect:45) Failed to acquire file=current/legacy-images/MANIFEST: Couldn't acquire file /current/legacy-images/MANIFEST: iso doesn't have file=/current/legacy-images/MANIFEST
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urldetect:45) Failed to acquire file=daily/MANIFEST: Couldn't acquire file /daily/MANIFEST: iso doesn't have file=/daily/MANIFEST
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urlfetcher:46) Extracting iso file: ['xorriso', '-osirrox', 'on', '-indev', 'ubuntu-22.04.3-live-server-amd64.iso', '-extract', '/.disk/info', '/var/lib/libvirt/boot/virtinst-isoaog43vow-info']
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urlfetcher:105) Fetching URI: /.disk/info
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (urldetect:298) Detected class=_UbuntuDistro osvariant=None
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (installer:544) installer.detect_distro returned=None
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (osdict:216) No recommended value found for key='n-cpus', using minimum=1 * 2
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (guest:535) Prefer EFI => False
[Thu, 19 Oct 2023 15:32:19 virt-install 813519] DEBUG (cpu:282) Using default cpu mode=host-passthrough
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (guest:1094) Using num_pcie_root_ports=14
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (disk:236) DeviceDisk.check_path_search path=/var/lib/libvirt/boot
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (disk:236) DeviceDisk.check_path_search path=ubuntu-22.04.3-live-server-amd64.iso
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] WARNING (cli:309) ubuntu-22.04.3-live-server-amd64.iso may not be accessible by the hypervisor. You will need to grant the 'libvirt-qemu' user search permissions for the following directories: ['/home/test']
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (disk:236) DeviceDisk.check_path_search path=/home/test/ubuntu22.04-test.qcow2
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] WARNING (cli:309) /home/test/ubuntu22.04-test.qcow2 may not be accessible by the hypervisor. You will need to grant the 'libvirt-qemu' user search permissions for the following directories: ['/home/test']
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (disk:236) DeviceDisk.check_path_search path=/home/test/ubuntu-22.04.3-live-server-amd64.iso
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] WARNING (cli:309) /home/test/ubuntu-22.04.3-live-server-amd64.iso may not be accessible by the hypervisor. You will need to grant the 'libvirt-qemu' user search permissions for the following directories: ['/home/test']
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (cli:265)
Starting install...
Starting install...
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (urlfetcher:174) hasFile(/mnt/casper/vmlinuz) returning False
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (cli:255) File "/usr/bin/virt-install", line 8, in <module>
virtinstall.runcli()
File "/usr/share/virt-manager/virtinst/virtinstall.py", line 1220, in runcli
sys.exit(main())
File "/usr/share/virt-manager/virtinst/virtinstall.py", line 1213, in main
start_install(guest, installer, options)
File "/usr/share/virt-manager/virtinst/virtinstall.py", line 961, in start_install
fail(e, do_exit=False)
File "/usr/share/virt-manager/virtinst/cli.py", line 255, in fail
log.debug("".join(traceback.format_stack()))
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] ERROR (cli:256) Couldn't find kernel for install tree.
[Thu, 19 Oct 2023 15:32:20 virt-install 813519] DEBUG (cli:258)
Traceback (most recent call last):
File "/usr/share/virt-manager/virtinst/virtinstall.py", line 941, in start_install
domain = installer.start_install(
File "/usr/share/virt-manager/virtinst/install/installer.py", line 685, in start_install
self._prepare(guest, meter)
File "/usr/share/virt-manager/virtinst/install/installer.py", line 391, in _prepare
self._prepare_treemedia(guest, meter, unattended_scripts)
File "/usr/share/virt-manager/virtinst/install/installer.py", line 364, in _prepare_treemedia
kernel, initrd, kernel_args = self._treemedia.prepare(guest, meter,
File "/usr/share/virt-manager/virtinst/install/installertreemedia.py", line 279, in prepare
kernel, initrd = self._prepare_kernel_url(guest, cache, fetcher)
File "/usr/share/virt-manager/virtinst/install/installertreemedia.py", line 211, in _prepare_kernel_url
kernelpath, initrdpath = _check_kernel_pairs()
File "/usr/share/virt-manager/virtinst/install/installertreemedia.py", line 208, in _check_kernel_pairs
raise RuntimeError( # pragma: no cover
RuntimeError: Couldn't find kernel for install tree.
使用virsh-manager基于iso创建虚拟机
$ sudo apt install -y virt-manager
$ virt-manager
$ virsh shutdown ubuntu22.04
Domain 'ubuntu22.04' is being shutdown
$ virsh list --all
Id Name State
------------------------------
- ubuntu22.04 shut off
克隆虚拟机
更多推荐
已为社区贡献2条内容
所有评论(0)