linux内搭建临时桌面系统

1、安装vnc viewer
https://www.realvnc.com/en/connect/download/viewer/

2、在linux系统内安装qemu-system-x86

yum -y install qemu-system-x86
或者
apt-get -y install qemu-system-x86

3、下载desktop版本ubuntu20.04

wget https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/20.04/ubuntu-20.04.6-desktop-amd64.iso

4、启动虚拟机

qemu-system-x86_64 -enable-kvm -smbios type=1,serial=XX -smp 4 -m 16384 -vnc :1 -cdrom ubuntu-20.04.6-desktop-amd64.iso -net nic,macaddr=34:3c:53:2a:c6:bd -net tap,ifname=tap0,script=no,downscript=no -device virtio-9p-pci,fsdev=fs1,mount_tag=newrootfs -fsdev local,id=fs1,path=/root/,security_model=none
有如下报错:
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.svm [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.svm [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.svm [bit 2]
qemu-system-x86_64: warning: host doesn't support requested feature: CPUID.80000001H:ECX.svm [bit 2]

解决方法是在命令里加上-cpu host
qemu-system-x86_64 -cpu host -enable-kvm -smbios type=1,serial=XX -smp 4 -m 16384 -vnc :1 -cdrom ubuntu-16.04.6-desktop-amd64.iso -net nic,macaddr=34:3c:53:2a:c6:bd -net tap,ifname=tap0,script=no,downscript=no -device virtio-9p-pci,fsdev=fs1,mount_tag=newrootfs -fsdev local,id=fs1,path=/root/,security_model=none

5、通过vnc访问启动的虚拟机
linux内搭建临时桌面系统_第1张图片
linux内搭建临时桌面系统_第2张图片

6、宿主机配置网络

ip l s tap0 up
ip a a 192.168.121.1/24 dev tap0
iptables -t nat -A POSTROUTING -s 192.168.121.0/24  -j MASQUERADE

6、虚拟机配置ip

7、从宿主机ping虚拟机
linux内搭建临时桌面系统_第3张图片

8、挂载宿主机目录到虚拟机, 把虚拟机启动时用的newrootfs,挂载到虚拟机的mnt目录

mount -t 9p newrootfs /mnt

你可能感兴趣的:(Linux,linux,运维,服务器)