{"id":309,"date":"2023-09-27T17:17:10","date_gmt":"2023-09-27T09:17:10","guid":{"rendered":"https:\/\/tys.fun\/?p=309"},"modified":"2023-09-27T17:19:10","modified_gmt":"2023-09-27T09:19:10","slug":"309","status":"publish","type":"post","link":"https:\/\/tys.fun\/?p=309","title":{"rendered":"OpenWrt \u8fc1\u79fb PVE"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u4e4b\u524d\u4e00\u76f4\u662f\u88f8\u673a\u5b89\u88c5 <code>OpenWrt<\/code> \uff0c\u4f46\u662f\u6700\u8fd1\u9047\u5230\u4e86\u4e00\u4e9b\u5947\u602a\u7684\u95ee\u9898\uff0c\u8def\u7531\u603b\u662f\u83ab\u540d\u5176\u5999\u7684\u6b7b\u6389\uff0c\u4e00\u70b9\u8ff9\u8c61\u4e5f\u6ca1\u6709\uff0clog \u4e2d\u4e5f\u65e0\u6709\u6548\u5185\u5bb9\uff0c\u518d\u52a0\u4e0a <code>OpenWrt<\/code> \u7269\u7406\u8fde\u63a5\u4e0d\u9700\u8981\u5bc6\u7801\u5c31\u80fd\u8fdb\u5165 <code>root shell<\/code> \uff0c\u8fd8\u662f\u8fc7\u4e8e\u4e0d\u5b89\u5168\u4e86\uff0c\u51b3\u5b9a\u5c06 <code>OpenWrt<\/code> \u8fc1\u79fb\u81f3 PVE\u3002<\/p>\n<h2>CT vs VM<\/h2>\n<p>\u8d77\u521d\u542c\u53d6\u4e86\u5e08\u5144\u7684\u5efa\u8bae\uff0c\u91c7\u7528\u4e86\u66f4\u65b9\u4fbf\u8fc1\u79fb\u7684\u65b9\u5f0f\uff1aPVE \u7684 Container\uff0c\u8fd9\u4e2a\u4e1c\u897f\u7684\u4f18\u52bf\u5728\u4e8e\uff0c\u6709 <code>rootfs<\/code> \u5c31\u80fd\u8dd1\uff0c\u4e0d\u9700\u8981\u5b89\u88c5\u4ec0\u4e48\u7684\uff0c\u628a\u5f53\u524d\u7684\u6574\u4e2a <code>\/<\/code> \u76ee\u5f55\u590d\u5236\u4e0b\u6765\u6253\u4e2a\u5305\uff08<code>tar.gz<\/code>\uff09\uff0c\u4e0a\u4f20\u5230 PVE \u7684 <code>template<\/code> \uff0c\u7136\u540e\u901a\u8fc7\u8fd9\u4e2a <code>template<\/code>  \u5efa\u7acb <code>lxc<\/code> \uff0c\u5373 PVE \u7684\u5bb9\u5668\uff0c\u5c31\u53ef\u4ee5\u8fd0\u884c\u4e86\u3002<\/p>\n<h3>\u95ee\u9898 1\uff1a<\/h3>\n<p>\u4e00\u5f00\u59cb\u5c31\u662f <code>dnsmasq<\/code> \u65e0\u6cd5\u542f\u52a8\uff0c\u5c1d\u8bd5\u542f\u52a8\u603b\u662f\u62a5\u9519\uff0c\u539f\u56e0\u662f <code>procd<\/code> \u7684\u53c2\u6570\u6709\u95ee\u9898\uff0c\u6ce8\u91ca\u6389 <code>\/etc\/init.d\/dnsmasq<\/code> \u4e2d\u7684 <code>procd_add_jail<\/code> \u90e8\u5206\u53ef\u4ee5\u89e3\u51b3\uff0c<code>dhcpd<\/code> \u6210\u529f\u542f\u52a8\u3002<\/p>\n<h3>\u95ee\u98982\uff1a<\/h3>\n<p>\u521b\u5efa\u7684 <code>lxc<\/code> \u6ca1\u6709\u9009\u62e9\u7279\u6743\uff0c\u800c <code>lxc<\/code> \u4f5c\u4e3a\u4e00\u4e2a\u534a\u865a\u62df\u5316\u7684\u5de5\u5177\uff0c\u5176\u5f88\u591a\u786c\u4ef6\u662f\u4e0e <code>host<\/code> \u5171\u4eab\u7684\uff0c\u8fd9\u5176\u5b9e\u5c31\u662f\u6211\u51b3\u5b9a\u4ece <code>lxc<\/code> \u6362\u56de <code>vm<\/code> \u7684\u4e3b\u8981\u539f\u56e0\u3002 <code>OpenWrt<\/code> \u8fd9\u79cd\u8f6f\u8def\u7531\u7cfb\u7edf\u4e0d\u53ef\u907f\u514d\u7684\u8981\u521b\u5efa\u4e00\u4e9b\u7f51\u7edc\u63a5\u53e3\uff0c\u6bd4\u5982 <code>tun<\/code>\u3001<code>tap<\/code> \u7b49\uff0c\u800c\u534a\u865a\u62df\u5316\u9700\u8981 <code>host<\/code> \u4e2d\u6709\u8fd9\u4e9b\u7f51\u7edc\u8bbe\u5907\uff0c\u5e76\u4e14\u8981\u5355\u72ec\u4e3a <code>lxc<\/code> \u5f00\u542f\u6743\u9650\uff0c\u8fd9\u6781\u5927\u5730\u589e\u52a0\u4e86\u865a\u62df\u5316\u5e73\u53f0\u548c\u7cfb\u7edf\u4e4b\u95f4\u7684\u8026\u5408\u5ea6\uff0c\u5e76\u4e14\u5e26\u6765\u4e86\u5f88\u591a\u4e0d\u5fc5\u8981\u7684\u9ebb\u70e6\u3002<\/p>\n<p>\u6700\u7ec8\u6211\u8fd8\u662f\u4f7f\u7528\u4e86 <code>VM<\/code> \u4f5c\u4e3a\u8f6f\u8def\u7531\u7684\u8f7d\u4f53\u3002<\/p>\n<h2>Install OpenWrt VM on PVE<\/h2>\n<h3>1. \u4e0a\u4f20\u955c\u50cf<\/h3>\n<p>\u7565\uff0c\u8fd9\u4e00\u6b65\u4e0d\u4f1a\u7684\u8fd8\u662f\u522b\u6298\u817e\u8f6f\u8def\u7531\u4e86\u3002<\/p>\n<h3>2. \u65b0\u5efa\u865a\u62df\u673a<\/h3>\n<p>\u8bb0\u4f4f <code>VM ID<\/code> \uff0c\u4e00\u4f1a\u513f\u8fd8\u5f97\u7528\uff0c\u64cd\u4f5c\u7cfb\u7edf\u9009\u4e0d\u4f7f\u7528\u4efb\u4f55\u4ecb\u8d28\uff0c\u53ea\u6709\u8fd9\u4e24\u4e2a\u9700\u8981\u6ce8\u610f\u7684\u9009\u9879\uff0c\u5176\u4ed6\u9ed8\u8ba4\u6216\u81ea\u884c\u6269\u5bb9\uff0c\u8fd8\u6709\u7f51\u5361\uff0c\u5f88\u597d\u914d\u3002\u8fd9\u4e24\u4e2a\u9009\u9879\u4e3b\u8981\u662f\u56e0\u4e3a <code>OpenWrt x86<\/code> \u7684\u955c\u50cf\uff0c\u771f\u7684\u5c31\u662f\u955c\u50cf\uff0c\u4e0d\u662f\u5b89\u88c5\uff0c\u7269\u7406\u673a\u5b89\u88c5\u53ea\u9700\u8981 <code>dd<\/code> \u5199\u5165\u5c31\u884c\u7684\uff0c\u4e0d\u5305\u542b\u4e00\u822c <code>iso<\/code> \u6587\u4ef6\u62e5\u6709\u7684\u5b89\u88c5\u7528\u7684 <code>boot image<\/code> \uff0c\u9009\u62e9\u4e86\u8fd9\u4e2a\u6587\u4ef6\u4f1a\u8ba9 PVE \u6ca1\u6cd5\u5f15\u5bfc\uff0c\u4e5f\u56e0\u6b64\u662f\u91c7\u7528\u76f4\u63a5\u5bfc\u5165\u786c\u76d8\u7684\u65b9\u5f0f\uff0c\u800c\u4e0d\u7528\u65b0\u5efa\u4e00\u5757\u786c\u76d8\u3002<\/p>\n<h3>3. \u5bfc\u5165\u78c1\u76d8\u955c\u50cf<\/h3>\n<p>\u8fdb <code>PVE host<\/code> \u7684\u7ec8\u7aef\uff0c\u6267\u884c<\/p>\n<pre><code class=\"language-shell\">qm disk import $VM_ID \/var\/lib\/vz\/template\/iso\/$IMAGE_NAME local-lvm<\/code><\/pre>\n<p>\u5c06\u955c\u50cf\u4f5c\u4e3a\u786c\u76d8\u5bfc\u5165 <code>VM<\/code> \uff0c\u7b49 <code>successfully imported<\/code> \u4e86\u53ef\u4ee5\u53bb <code>VM<\/code> \u7684\u786c\u4ef6\u90a3\u513f\u7ed9\u786c\u76d8\u6269\u5bb9\uff0c\u6bd5\u7adf\u5bfc\u5165\u8fdb\u53bb\u591a\u5927\u5c31\u53ea\u6709\u591a\u5927\uff0c\u5982\u679c\u8981\u88c5\u4e00\u4e9b\u63d2\u4ef6\u7684\u8bdd\u663e\u7136\u662f\u4e0d\u591f\u7528\u7684\u3002<\/p>\n<h3>4. ____\uff0c\u542f\u52a8\uff01<\/h3>\n<p>\u7ed9 <code>VM<\/code> \u8fde\u4e0a\u7f51\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u914d\u4e86\uff0c\u6216\u8005\u76f4\u63a5\u4ece\u4e4b\u524d\u7684\u5907\u4efd\u6062\u590d\u3002<\/p>\n<p>\u8981\u6269\u5bb9\u786c\u76d8\uff0c\u76f4\u63a5\u7528\u5b98\u7f51\u7ed9\u7684\u65b9\u5f0f<\/p>\n<h4>\u5148\u6269\u5bb9\u5206\u533a<\/h4>\n<pre><code class=\"language-sh\"># Install packages\nopkg update\nopkg install parted\n\n# Identify disk name and partition number\necho -e &quot;ok\\nfix&quot; | parted -l ---pretend-input-tty\n\n# Expand root partition\nparted -s \/dev\/sda resizepart 2 100%\n\n# Apply changes\nreboot<\/code><\/pre>\n<h4>\u518d\u6269\u5bb9\u6587\u4ef6\u7cfb\u7edf<\/h4>\n<pre><code class=\"language-sh\"># Install packages\nopkg update\nopkg install losetup resize2fs\n\n# Map loop device to root partition\nlosetup \/dev\/loop1 \/dev\/sda2\n\n# Expand root filesystem\nresize2fs -f \/dev\/loop1\n\n# Apply changes\nreboot<\/code><\/pre>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u4e0d\u96be\uff0c\u6298\u817e\uff0c\u5c3d\u91cf\u641e\u4e00\u4e2a\u7a33\u5b9a\u7684\u73af\u5883\uff0c\u6bd5\u7adf\u5f71\u54cd\u6574\u4e2a\u5b50\u7f51\u7684\u4e0a\u7f51\uff0cPVE \u65b9\u4fbf\u8fc1\u79fb\uff0c\u4ee5\u540e\u6362\u8bbe\u5907\u4e86\u4e5f\u597d\u641e\uff0c\u9700\u8981\u7528\u5230\u65b0\u7684\u8bbe\u5907\u7684\uff0c\u4e0d\u7ba1\u865a\u62df\u8fd8\u662f\u5b9e\u4f53\uff0c\u8fd8\u662f\u7528 <code>VM<\/code> \u5427\uff0c\u6bd4\u8f83\u7701\u5fc3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u4e4b\u524d\u4e00\u76f4\u662f\u88f8\u673a\u5b89\u88c5 OpenWrt \uff0c\u4f46\u662f\u6700\u8fd1\u9047\u5230\u4e86\u4e00\u4e9b\u5947\u602a\u7684\u95ee\u9898\uff0c\u8def\u7531\u603b\u662f\u83ab\u540d\u5176\u5999\u7684\u6b7b\u6389\uff0c\u4e00\u70b9\u8ff9\u8c61\u4e5f\u6ca1 &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-309","post","type-post","status-publish","format-standard","hentry","category-skills"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309"}],"version-history":[{"count":2,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/tys.fun\/index.php?rest_route=\/wp\/v2\/posts\/309\/revisions\/311"}],"wp:attachment":[{"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tys.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}