{"id":35,"date":"2024-08-20T10:27:04","date_gmt":"2024-08-20T02:27:04","guid":{"rendered":"https:\/\/cnsn.rr.nu\/?p=35"},"modified":"2024-08-20T10:27:04","modified_gmt":"2024-08-20T02:27:04","slug":"%e5%9c%a8debian11%e4%b8%8a%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%aekvm%e8%99%9a%e6%8b%9f%e6%9c%ba","status":"publish","type":"post","link":"https:\/\/blog.cnsn.fun\/?p=35","title":{"rendered":"\u5728Debian11\u4e0a\u5b89\u88c5\u914d\u7f6eKVM\u865a\u62df\u673a"},"content":{"rendered":"<h3><strong>\u4e00\u3001\u524d\u63d0<\/strong><\/h3>\n<p>\u68c0\u67e5\u662f\u5426\u6ee1\u8db3\u865a\u62df\u5316\u8981\u6c42, \u53ef\u4ee5\u6839\u636e\u5982\u4e0b\u6b65\u9aa4\u9a8c\u8bc1:<\/p>\n<p>\u68c0\u67e5\u662f\u5426\u5f00\u542f\u865a\u62df\u5316,\u5982\u679c\u503c\u5927\u4e8e0\u5219\u652f\u6301\u865a\u62df\u5316\uff0c\u5426\u5219\u9700\u8981\u5728BIOS\u4e2d\u5f00\u542f\u865a\u62df\u5316, \u91cd\u542f\u91cd\u65b0\u6267\u884c\u5982\u4e0b\u547d\u4ee4<br \/>\n<code>egrep -c &#039;(vmx|svm)&#039; \/proc\/cpuinfo<\/code><br \/>\n\u68c0\u67e5CPU\u7c7b\u578b: \u5982\u679c\u662fIntel\u7684CPU, \u8f93\u51faVMX;\u5982\u679c\u662fAMD\u7684CPU, \u8f93\u51faSVM<\/p>\n<p><code>grep -E --color &#039;(vmx|svm)&#039; \/proc\/cpuinfo<\/code><\/p>\n<h3><strong>\u4e8c\u3001\u5b89\u88c5\u76f8\u5173\u5305<\/strong><\/h3>\n<pre><code>apt update\napt install -y qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon<\/code><\/pre>\n<p>\u5b89\u88c5GUI\u7ba1\u7406\u5de5\u5177(\u53ef\u9009)<\/p>\n<p>\u6ca1\u7528\u684c\u9762\u7684\u4e0d\u7528\u88c5GUI<\/p>\n<p><code>apt install virt-manager -y<\/code><\/p>\n<h3><strong>\u4e09\u3001\u914d\u7f6e\u7f51\u7edc<\/strong><\/h3>\n<p>\u8981\u5217\u51fa\u8981\u5728 KVM \u865a\u62df\u673a\u4e2d\u4f7f\u7528\u7684\u53ef\u7528\u7f51\u7edc\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p><code>virsh net-list --all<\/code><br \/>\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u662f\u4e0d\u6d3b\u8dc3\u7684\uff0c\u9700\u8981\u542f\u52a8<\/p>\n<pre><code>virsh net-start default\nvirsh net-autostart default<\/code><\/pre>\n<p>\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u540e\u7ed3\u679c\u5982\u4e0b<\/p>\n<pre><code>root@debian 13:14 \u279c  ~ virsh net-list --all\n Name      State    Autostart   Persistent\n--------------------------------------------\n default   active   yes         yes<\/code><\/pre>\n<p>\u52a0\u8f7d\u5185\u6838\u6a21\u5757vhost_net\uff0c\u63d0\u9ad8\u7f51\u7edc\u6027\u80fd<br \/>\n<code>modprobe vhost_net<\/code><\/p>\n<h1>\u68c0\u67e5\u662f\u5426\u52a0\u8f7d\u6210\u529f<\/h1>\n<p><code>lsmod | grep vhost<\/code><br \/>\n\u914d\u7f6e\u6865\u63a5\u7f51\u7edc<br \/>\nKVM\u81ea\u5e26\u6709\u4e00\u4e2a\u5f00\u7bb1\u5373\u7528\u7684virbr0\u6865\u63a5\u7f51\u7edc\u63a5\u53e3, \u4f46\u662f\u9ed8\u8ba4\u5206\u914dip\u4e0d\u592a\u6ee1\u8db3\u9700\u6c42\uff0c\u9700\u8981\u65b0\u5efa\u4e00\u4e2a<br \/>\n\u7f16\u8f91\/etc\/network\/interfaces<br \/>\n\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u65b0\u589e\u5982\u4e0b, \u6211\u9700\u8981dhcp\u5206\u914dip(\u53ef\u4ee5\u662f\u9759\u6001ip)<\/p>\n<pre><code>auto br0\niface br0 inet dhcp\n  bridge_ports wlp1s0<\/code><\/pre>\n<p>\u66f4\u6539\u5b8c\u6210\u540e, \u91cd\u542f\u7f51\u7edc<\/p>\n<pre><code>systemctl restart networking.service\nip a<\/code><\/pre>\n<h3><strong>\u56db\u3001\u4ece\u955c\u50cf\u521b\u5efa\u865a\u62df\u673a<\/strong><\/h3>\n<p>\u521b\u5efaLinux\u865a\u62df\u673a<\/p>\n<h1>\u521b\u5efa\u865a\u62df\u673a\u78c1\u76d8<\/h1>\n<pre><code>qemu-img create -f qcow2 \/var\/lib\/libvirt\/images\/debian11.qcow2 20G\n\nvirt-install \\\n--name debian11 \\\n--memory memory=1024,currentMemory=512 \\\n--disk path=\/var\/lib\/libvirt\/images\/debian11.qcow2,size=20 \\\n--vcpus 1 \\\n--os-type linux \\\n--os-variant debian10 \\\n--network bridge=br0,model=virtio \\\n--graphics none \\\n--console pty,target_type=serial \\\n--location &#039;http:\/\/mirrors.tencent.com\/debian\/dists\/bullseye\/main\/installer-amd64\/&#039; \\\n--extra-args &#039;console=ttyS0,115200n8 serial&#039; \\\n--debug<\/code><\/pre>\n<p>\u521b\u5efawindows\u865a\u62df\u673a<\/p>\n<pre><code>virt-install \\\n--name win10 \\\n--ram 2048 \\\n--disk path=\/var\/lib\/libvirt\/images\/win10.qcow2,size=20 \\\n--vcpus 2 \\\n--os-type windows \\\n--os-variant win10 \\\n--network bridge=br0,model=virtio \\\n--graphics none \\\n--console pty,target_type=serial \\\n--cdrom \/home\/ysicing\/Downloads\/Win10_21H1_Chinese(Simplified)_x64.iso \\\n--extra-args &#039;console=ttyS0,115200n8 serial&#039;<\/code><\/pre>\n<p>\u5f00\u542fvnc<\/p>\n<pre><code>virsh vncdisplay win10\n\u5bfc\u5165\u865a\u62df\u673a\nvirt-install \\\n--name debian11 \\\n--ram 2048 \\\n--disk path=\/var\/lib\/libvirt\/images\/debian11.qcow2,size=20 \\\n--vcpus 2 \\\n--os-type linux \\\n--os-variant debian11 \\\n--network bridge=br0,model=virtio \\\n--graphics none \\\n--console pty,target_type=serial \\\n--import<\/code><\/pre>\n<p>\u5bfc\u51fa\u865a\u62df\u673a\u4e3aqcow2<\/p>\n<p><code>virt-clone --original debian11 --name debian11-clone --file \/var\/lib\/libvirt\/images\/debian11-clone.qcow2<\/code><\/p>\n<h3><strong>\u4e94\u3001\u5e38\u89c1\u9ad8\u7ea7\u64cd\u4f5c<\/strong><\/h3>\n<p>\u67e5\u770b\u865a\u62df\u673a<br \/>\n<code>virsh list --all<\/code><br \/>\n\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u540e\u7ed3\u679c\u5982\u4e0b<\/p>\n<pre><code>root@debian 13:14 \u279c  ~ virsh list --all\n Id   Name      State\n------------------------\n 2    debian11  running<\/code><\/pre>\n<p>\u9500\u6bc1\u865a\u62df\u673a<\/p>\n<pre><code>virsh destroy debian11\nvirsh undefine debian11<\/code><\/pre>\n<p>\u5173\u95ed\u865a\u62df\u673a<br \/>\n<code>virsh shutdown debian11<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u524d\u63d0 \u68c0\u67e5\u662f\u5426\u6ee1\u8db3\u865a\u62df\u5316\u8981\u6c42, \u53ef\u4ee5\u6839\u636e\u5982\u4e0b\u6b65\u9aa4\u9a8c\u8bc1: \u68c0\u67e5\u662f\u5426\u5f00\u542f\u865a\u62df\u5316,\u5982\u679c\u503c\u5927\u4e8e0\u5219\u652f\u6301\u865a\u62df\u5316\uff0c\u5426\u5219 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[18,19],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-linux","tag-kvm","tag-linux"],"_links":{"self":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35"}],"version-history":[{"count":0,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cnsn.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}