{"id":12139,"date":"2025-01-12T10:54:46","date_gmt":"2025-01-12T18:54:46","guid":{"rendered":"https:\/\/www.xh86.me\/?p=12139"},"modified":"2025-01-12T10:54:46","modified_gmt":"2025-01-12T18:54:46","slug":"proxmox-%e4%b8%8b%e8%87%aa%e5%8a%a8%e5%ae%89%e8%a3%85%e7%b3%bb%e7%bb%9f%e8%84%9a%e6%9c%ac%ef%bc%88%e6%b5%8b%e8%af%95%e4%b8%ad%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.xh86.me\/?p=12139","title":{"rendered":"Proxmox \u4e0b\u81ea\u52a8\u5b89\u88c5\u7cfb\u7edf\u811a\u672c\uff08\u6d4b\u8bd5\u4e2d\uff09"},"content":{"rendered":"<p>#!\/bin\/bash<\/p>\n<p># \u901a\u7528\u914d\u7f6e<br \/>\nPASSWORD=&#8221;Digital!!29&#8243;<br \/>\nSTORAGE=&#8221;local-lvm&#8221;<br \/>\nBRIDGE=&#8221;vmbr0&#8243;<br \/>\nMEMORY_LINUX=&#8221;2048&#8243;<br \/>\nMEMORY_WINDOWS=&#8221;4096&#8243;<br \/>\nCORES_LINUX=&#8221;2&#8243;<br \/>\nCORES_WINDOWS=&#8221;4&#8243;<br \/>\nDISK_SIZE_LINUX=&#8221;40G&#8221;<br \/>\nDISK_SIZE_WINDOWS=&#8221;80G&#8221;<br \/>\nISO_DIR=&#8221;\/var\/lib\/vz\/template\/iso&#8221;<br \/>\nCLOUDINIT_DIR=&#8221;\/var\/lib\/vz\/snippets&#8221;<\/p>\n<p># \u521b\u5efaISO\u548cCloud-Init\u76ee\u5f55<br \/>\nmkdir -p $ISO_DIR<br \/>\nmkdir -p $CLOUDINIT_DIR<\/p>\n<p># \u83b7\u53d6\u5f53\u524d\u6700\u5927VM ID<br \/>\nget_next_vmid() {<br \/>\nlocal next_id=$(($(qm list | awk &#8216;NR&gt;1 {print $1}&#8217; | sort -n | tail -n 1) + 1))<br \/>\necho $next_id<br \/>\n}<\/p>\n<p># \u4e0b\u8f7dISO\u955c\u50cf\u51fd\u6570<br \/>\ndownload_iso() {<br \/>\nlocal url=$1<br \/>\nlocal output=$2<br \/>\nif [ ! -f &#8220;$ISO_DIR\/$output&#8221; ]; then<br \/>\necho &#8220;\u6b63\u5728\u4e0b\u8f7d $output&#8230;&#8221;<br \/>\nwget -O &#8220;$ISO_DIR\/$output&#8221; &#8220;$url&#8221;<br \/>\nelse<br \/>\necho &#8220;$output \u5df2\u5b58\u5728\uff0c\u8df3\u8fc7\u4e0b\u8f7d\u3002&#8221;<br \/>\nfi<br \/>\n}<\/p>\n<p># \u521b\u5efaLinux Cloud-Init\u6587\u4ef6<br \/>\ncreate_linux_cloudinit() {<br \/>\nlocal vmid=$1<br \/>\ncat &gt; $CLOUDINIT_DIR\/${vmid}-user-data &lt;&lt;EOF<br \/>\n#cloud-config<br \/>\nhostname: ${name}<br \/>\npassword: ${PASSWORD}<br \/>\nchpasswd: { expire: False }<br \/>\nssh_pwauth: True<br \/>\nssh_authorized_keys:<br \/>\n&#8211; $(cat ~\/.ssh\/id_rsa.pub)<br \/>\nEOF<br \/>\n}<\/p>\n<p># \u521b\u5efaWindows\u65e0\u4eba\u503c\u5b88\u5b89\u88c5\u6587\u4ef6<br \/>\ncreate_windows_autounattend() {<br \/>\nlocal vmid=$1<br \/>\ncat &gt; $ISO_DIR\/autounattend.xml &lt;&lt;EOF<br \/>\n&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;utf-8&#8243;?&gt;<br \/>\n&lt;unattend xmlns=&#8221;urn:schemas-microsoft-com:unattend&#8221;&gt;<br \/>\n&lt;settings pass=&#8221;oobeSystem&#8221;&gt;<br \/>\n&lt;component name=&#8221;Microsoft-Windows-Shell-Setup&#8221; processorArchitecture=&#8221;amd64&#8243; publicKeyToken=&#8221;31bf3856ad364e35&#8243; language=&#8221;neutral&#8221; versionScope=&#8221;nonSxS&#8221;&gt;<br \/>\n&lt;AutoLogon&gt;<br \/>\n&lt;Password&gt;<br \/>\n&lt;Value&gt;${PASSWORD}&lt;\/Value&gt;<br \/>\n&lt;PlainText&gt;true&lt;\/PlainText&gt;<br \/>\n&lt;\/Password&gt;<br \/>\n&lt;Enabled&gt;true&lt;\/Enabled&gt;<br \/>\n&lt;Username&gt;Administrator&lt;\/Username&gt;<br \/>\n&lt;\/AutoLogon&gt;<br \/>\n&lt;UserAccounts&gt;<br \/>\n&lt;AdministratorPassword&gt;<br \/>\n&lt;Value&gt;${PASSWORD}&lt;\/Value&gt;<br \/>\n&lt;PlainText&gt;true&lt;\/PlainText&gt;<br \/>\n&lt;\/AdministratorPassword&gt;<br \/>\n&lt;\/UserAccounts&gt;<br \/>\n&lt;OOBE&gt;<br \/>\n&lt;HideEULAPage&gt;true&lt;\/HideEULAPage&gt;<br \/>\n&lt;NetworkLocation&gt;Work&lt;\/NetworkLocation&gt;<br \/>\n&lt;\/OOBE&gt;<br \/>\n&lt;\/component&gt;<br \/>\n&lt;\/settings&gt;<br \/>\n&lt;\/unattend&gt;<br \/>\nEOF<br \/>\n}<\/p>\n<p># \u521b\u5efaLinux\u865a\u62df\u673a\u51fd\u6570<br \/>\ncreate_linux_vm() {<br \/>\nlocal name=$1<br \/>\nlocal iso=$2<br \/>\nlocal vmid=$(get_next_vmid)<\/p>\n<p>create_linux_cloudinit $vmid<\/p>\n<p>qm create $vmid \\<br \/>\n&#8211;name $name \\<br \/>\n&#8211;memory $MEMORY_LINUX \\<br \/>\n&#8211;cores $CORES_LINUX \\<br \/>\n&#8211;net0 virtio,bridge=$BRIDGE \\<br \/>\n&#8211;ostype l26 \\<br \/>\n&#8211;scsihw virtio-scsi-pci \\<br \/>\n&#8211;scsi0 $STORAGE:$DISK_SIZE_LINUX \\<br \/>\n&#8211;ide2 $STORAGE:cloudinit \\<br \/>\n&#8211;boot order=scsi0 \\<br \/>\n&#8211;cdrom $ISO_DIR\/$iso \\<br \/>\n&#8211;cicustom &#8220;user=$CLOUDINIT_DIR\/${vmid}-user-data&#8221; \\<br \/>\n&#8211;agent enabled=1<\/p>\n<p>qm start $vmid<br \/>\necho &#8220;$name \u865a\u62df\u673a (VM ID: $vmid) \u521b\u5efa\u5b8c\u6210\u5e76\u5df2\u542f\u52a8\u3002&#8221;<br \/>\n}<\/p>\n<p># \u521b\u5efaWindows\u865a\u62df\u673a\u51fd\u6570<br \/>\ncreate_windows_vm() {<br \/>\nlocal name=$1<br \/>\nlocal iso=$2<br \/>\nlocal vmid=$(get_next_vmid)<\/p>\n<p>download_iso &#8220;https:\/\/fedorapeople.org\/groups\/virt\/virtio-win\/direct-downloads\/latest-virtio\/virtio-win.iso&#8221; &#8220;virtio-win.iso&#8221;<br \/>\ncreate_windows_autounattend $vmid<\/p>\n<p>qm create $vmid \\<br \/>\n&#8211;name $name \\<br \/>\n&#8211;memory $MEMORY_WINDOWS \\<br \/>\n&#8211;cores $CORES_WINDOWS \\<br \/>\n&#8211;net0 virtio,bridge=$BRIDGE \\<br \/>\n&#8211;ostype win11 \\<br \/>\n&#8211;scsihw virtio-scsi-pci \\<br \/>\n&#8211;scsi0 $STORAGE:$DISK_SIZE_WINDOWS \\<br \/>\n&#8211;ide2 $STORAGE:cloudinit \\<br \/>\n&#8211;boot order=scsi0 \\<br \/>\n&#8211;cdrom $ISO_DIR\/$iso \\<br \/>\n&#8211;ide1 $STORAGE:iso\/virtio-win.iso,media=cdrom \\<br \/>\n&#8211;ide3 $STORAGE:iso\/autounattend.xml,media=cdrom \\<br \/>\n&#8211;agent enabled=1<\/p>\n<p>qm start $vmid<br \/>\necho &#8220;$name \u865a\u62df\u673a (VM ID: $vmid) \u521b\u5efa\u5b8c\u6210\u5e76\u5df2\u542f\u52a8\u3002&#8221;<br \/>\n}<\/p>\n<p># \u7cfb\u7edf\u9009\u62e9\u83dc\u5355<br \/>\necho &#8220;\u8bf7\u9009\u62e9\u8981\u5b89\u88c5\u7684\u64cd\u4f5c\u7cfb\u7edf\uff1a&#8221;<br \/>\necho &#8220;1) Ubuntu Server \u6700\u65b0\u7248&#8221;<br \/>\necho &#8220;2) Debian Server \u6700\u65b0\u7248&#8221;<br \/>\necho &#8220;3) CentOS \u6700\u65b0\u7248&#8221;<br \/>\necho &#8220;4) Rocky Linux \u6700\u65b0\u7248&#8221;<br \/>\necho &#8220;5) AlmaLinux \u6700\u65b0\u7248&#8221;<br \/>\necho &#8220;6) Windows 11 Pro \u6700\u65b0\u7248&#8221;<br \/>\necho &#8220;7) Windows Server 2022 Datacenter&#8221;<br \/>\necho &#8220;8) Windows Server 2024 Datacenter&#8221;<br \/>\necho -n &#8220;\u8bf7\u8f93\u5165\u9009\u9879 (1-8): &#8221;<br \/>\nread choice<\/p>\n<p>case $choice in<br \/>\n1) download_iso &#8220;https:\/\/releases.ubuntu.com\/24.04\/ubuntu-24.04-live-server-amd64.iso&#8221; &#8220;ubuntu.iso&#8221;; create_linux_vm &#8220;Ubuntu-Server&#8221; &#8220;ubuntu.iso&#8221;;;<br \/>\n2) download_iso &#8220;https:\/\/cdimage.debian.org\/debian-cd\/current\/amd64\/iso-cd\/debian-12.4.0-amd64-netinst.iso&#8221; &#8220;debian.iso&#8221;; create_linux_vm &#8220;Debian-Server&#8221; &#8220;debian.iso&#8221;;;<br \/>\n3) download_iso &#8220;https:\/\/mirror.centos.org\/centos\/8.5.2111\/isos\/x86_64\/CentOS-8.5.2111-x86_64-dvd1.iso&#8221; &#8220;centos.iso&#8221;; create_linux_vm &#8220;CentOS-Server&#8221; &#8220;centos.iso&#8221;;;<br \/>\n4) download_iso &#8220;https:\/\/download.rockylinux.org\/pub\/rocky\/9\/isos\/x86_64\/Rocky-9.1-x86_64-dvd.iso&#8221; &#8220;rocky.iso&#8221;; create_linux_vm &#8220;Rocky-Server&#8221; &#8220;rocky.iso&#8221;;;<br \/>\n5) download_iso &#8220;https:\/\/repo.almalinux.org\/almalinux\/9\/isos\/x86_64\/AlmaLinux-9.1-x86_64-dvd.iso&#8221; &#8220;almalinux.iso&#8221;; create_linux_vm &#8220;AlmaLinux-Server&#8221; &#8220;almalinux.iso&#8221;;;<br \/>\n6) download_iso &#8220;https:\/\/software-download.microsoft.com\/db\/Win11_Pro_English_x64.iso&#8221; &#8220;win11pro.iso&#8221;; create_windows_vm &#8220;Windows11Pro&#8221; &#8220;win11pro.iso&#8221;;;<br \/>\n7) download_iso &#8220;https:\/\/software-download.microsoft.com\/db\/Win2022_Datacenter.iso&#8221; &#8220;win2022.iso&#8221;; create_windows_vm &#8220;WinServer2022&#8221; &#8220;win2022.iso&#8221;;;<br \/>\n8) download_iso &#8220;https:\/\/software-download.microsoft.com\/db\/Win2024_Datacenter.iso&#8221; &#8220;win2024.iso&#8221;; create_windows_vm &#8220;WinServer2024&#8221; &#8220;win2024.iso&#8221;;;<br \/>\n*) echo &#8220;\u65e0\u6548\u9009\u9879\uff0c\u8bf7\u8f93\u51651-8\u4e4b\u95f4\u7684\u6570\u5b57\u3002&#8221;;;<br \/>\nesac<\/p>\n<p>echo &#8220;\u865a\u62df\u673a\u5b89\u88c5\u5b8c\u6210\u3002&#8221;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash # \u901a\u7528\u914d\u7f6e PASSWORD=&#8221;Digital!!29&#8243; S [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-12139","post","type-post","status-publish","format-standard","hentry","category-proxmox"],"_links":{"self":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/12139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12139"}],"version-history":[{"count":1,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/12139\/revisions"}],"predecessor-version":[{"id":12140,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/12139\/revisions\/12140"}],"wp:attachment":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}