{"id":196,"date":"2023-09-17T21:29:47","date_gmt":"2023-09-17T13:29:47","guid":{"rendered":"https:\/\/techblog.hxdy2013.com\/?p=196"},"modified":"2023-09-17T22:36:42","modified_gmt":"2023-09-17T14:36:42","slug":"install-freebsd-with-zfs-root-in-multi-system-on-uefi","status":"publish","type":"post","link":"https:\/\/techblog.hxdy2013.com\/?p=196","title":{"rendered":"Install FreeBSD 13.2 with ZFS Root on UEFI Multi-System"},"content":{"rendered":"<div class=\"wp-block-post-date\"><time datetime=\"2023-09-17T21:29:47+08:00\">2023-09-17<\/time><\/div>\n\n\n<p class=\"wp-block-paragraph\">UEFI\u591a\u7cfb\u7edf\u4e2d\u7684FreeBSD\u8981\u4f7f\u7528ZFS\u5e76\u4e0e\u540c\u4e00\u5757\u78c1\u76d8\u4e0a\u7684\u5176\u4ed6OS\u5171\u5b58\uff0c\u5b89\u88c5\u65f6\u5fc5\u987b\u9009\u62e9\u8fdb\u5165Shell\u624b\u52a8\u5206\u533a\u3002\u9009\u62e9Auto(ZFS)\u5c31\u5fc5\u987b\u8986\u76d6\u6574\u4e2a\u78c1\u76d8\uff0c\u65e0\u6cd5\u4e0e\u5176\u4ed6OS\u5171\u5b58\u3002FreeBSD\u5728\u8fd9\u4e00\u70b9\u4e0a\u4e0d\u5982Linux\u7075\u6d3b\u3002<br>\u672c\u6587\u901a\u8fc7\u5b9e\u4f8b\u8bb2\u8ff0\u5982\u4f55\u5728\uff08VirtualBox\u865a\u62df\u673a\u4e2d\u7684\uff09FreeBSD 13.2\u5b89\u88c5\u65f6\u8fdb\u5165Shell\u624b\u52a8\u5206\u533a\u5b9e\u73b0UEFI\u591a\u7cfb\u7edf\u4e2d\u7684FreeBSD\u4f7f\u7528ZFS\u5e76\u4e0e\u540c\u4e00\u5757\u78c1\u76d8\u4e0a\u7684\u5176\u4ed6OS\u5171\u5b58\u3002<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">\u786c\u4ef6\u73af\u5883<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lenovo ThinkPad T14 Gen2 20W1S3H811: Intel i5-1145G7 + DDR4 16GB + NVMe 512GB<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">\u8f6f\u4ef6\u73af\u5883<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Win11 x64 Build 22621.2134 \u82f1\u6587\u4e13\u4e1a\u7248 + VirtualBox v7.0.8 r156879<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">VirtualBox\u73af\u5883<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VM Type = BSD<br>Version = FreeBSD (64bit)<br>Base Memory = 4GB<br>Processor = 4 Cores<br>VirtualDisk:<br>Size = 128GB<br>Partition1 = EFI 300MB<br>Partition2 = NTFS 32GB, Win11 Installed<br>Partition3 = Ext4 32GB, Xubuntu 22.04 Installed<br>Free Sapce = 64GB<\/p>\n\n\n\n<p class=\"has-large-font-size wp-block-paragraph\">\u5b89\u88c5FreeBSD 13.2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u6b65\u9aa4\u7565\uff0c\u91cd\u70b9\u5728\u624b\u52a8\u5206\u533a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"208\" src=\"https:\/\/techblog.hxdy2013.com\/wp-content\/uploads\/2023\/09\/48.png\" alt=\"\" class=\"wp-image-201\" srcset=\"https:\/\/techblog.hxdy2013.com\/wp-content\/uploads\/2023\/09\/48.png 522w, https:\/\/techblog.hxdy2013.com\/wp-content\/uploads\/2023\/09\/48-300x120.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u65b9\u5411\u952e\u9009\u5230Shell\uff0c\u56de\u8f66\u8fdb\u5165Shell<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\uff08\u53ef\u9009\u6b65\u9aa4\uff09FreeBSD\u5b89\u88c5\u7a0b\u5e8f\u652f\u6301\u7f51\u7edc\u8fde\u63a5\uff0c\u5982\u679c\u8fde\u63a5\u7740\u7f51\u7edc\uff0c\u53ef\u4ee5\u914d\u7f6eSSH\u670d\u52a1\uff0c\u65b9\u4fbf\u540e\u7eed\u8f93\u5165\u5927\u91cf\u547d\u4ee4\u3002<\/strong><br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>dhclient em0<\/code><\/mark>    # \u542f\u7528DHCP\u5ba2\u6237\u7aef\uff0c\u5c1d\u8bd5\u4eceDHCP\u670d\u52a1\u5668\u83b7\u53d6IP\u914d\u7f6e<br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>mkdir \/tmp\/etc \/tmp\/root<br>mount -t unionfs \/tmp\/etc \/etc<br>mount -t unionfs \/tmp\/root \/root<br>echo \"PermitRootLogin yes\" >> \/etc\/ssh\/sshd_config<\/code><\/mark>    # \u5141\u8bb8FreeBSD\u5b89\u88c5\u8fdb\u7a0b\u4e34\u65f6root\u8d26\u6237SSH\u8fdc\u7a0b\u767b\u5f55<br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>passwd<\/code><\/mark>    # FreeBSD\u5b89\u88c5\u8fdb\u7a0b\u4e34\u65f6root\u8d26\u6237\u9700\u8981\u5bc6\u7801\u624d\u80fd\u8fdc\u7a0b\u767b\u5f55\uff0c\u4e3a\u5176\u8bbe\u7f6e\u5bc6\u7801<br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>service sshd onestart<\/code><\/mark>    # \u4e34\u65f6\u4e00\u6b21\u6027\u542f\u52a8SSH\u670d\u52a1<br>SSH\u670d\u52a1\u542f\u52a8\u540e\uff0c\u7528SSH\u5ba2\u6237\u7aef\u8fde\u63a5\u5230FreeBSD\u5b89\u88c5\u8fdb\u7a0b\u7684Shell<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u67e5\u770b\u78c1\u76d8\u4fe1\u606f<\/strong><br><code><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">gpart show -p<\/mark><br><mark style=\"background-color:#ffd700\" class=\"has-inline-color\">=> 63 2072929 cd0 MBR (4.0G)<br>   63 2072929 - free - (4.0G)<br>=> 63 2072929 iso9660\/13_2_RELEASE_AMD64_DVD MBR (4.0G)<br>   63 2072929 - free - (4.0G)<br>=> 34 268435389 ada0 GPT (128G)<br>   34 2014 - free - (1.0M)<br> 2048 614400 ada0p1 efi (300M)<br>616448 67108864 ada0p2 ms-basic-data (32G)<br>67725312 67106816 ada0p3 linux-data (32G)<br>134832128 133603295 - free - (64G)<br>=> 34 268435389 diskid\/DISK-VB0b986931-09156175 GPT (128G)<br>   34 2014 - free - (1.0M)<br> 2048 614400 diskid\/DISK-VB0b986931-09156175p1 efi (300M)<br>616448 67108864 diskid\/DISK-VB0b986931-09156175p2 ms-basic-data (32G)<br>67725312 67106816 diskid\/DISK-VB0b986931-09156175p3 linux-data (32G)<br>134832128 133603295 - free - (64G)<\/mark><\/code><br>\u53ef\u4ee5\u770b\u5230\u6709\u4e2a4GB\u7684DVD\u5b89\u88c5\u5149\u76d8\u8bbe\u5907\u540dcd0\uff1b\u8fd8\u6709\u4e2a128GB\u7684\u786c\u76d8\u8bbe\u5907\u540dada0\uff0c\u5df2\u7ecf\u5206\u914d\u4e86300MB\u7684efi\u5206\u533a\u8bbe\u5907\u540dada0p1\uff0c32GB\u7684ms-basic-data\u5206\u533a\u8bbe\u5907\u540dada0p2\uff08Win11\u5b89\u88c5\u5728\u6b64\u5206\u533a\uff09\uff0c32GB\u7684linux-data\u5206\u533a\u8bbe\u5907\u540dada0p3\uff08Xubuntu 22.40\u5b89\u88c5\u5728\u6b64\u5206\u533a\uff09\uff0c\u8fd8\u670964GB\u7684\u7a7a\u95f2\u78c1\u76d8\u7a7a\u95f4\uff08\u53ef\u4ee5\u5212\u51fa\u4e00\u90e8\u5206\u6216\u5168\u90e8\uff0c\u7528\u4e8e\u5b89\u88c5FreeBSD\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u624b\u52a8\u5206\u533a<\/strong><br><code><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">kldload zfs<br>sysctl vfs.zfs.min_auto_ashift=12<\/mark><br><mark style=\"background-color:#ffd700\" class=\"has-inline-color\">vfs.zfs.min_auto_ashift: 9 -> 12<\/mark><br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">gpart add -a 1m -s 8G -t freebsd-swap -l swap0 ada0<\/mark><\/code> \/\/ \u4ea4\u6362\u5206\u533a\u5927\u5c0f\u901a\u5e38\u8bbe\u7f6e\u4e3a\u5185\u5b582\u500d<br><code><mark style=\"background-color:#ffd700\" class=\"has-inline-color\">ada0p4 added<\/mark><br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">gpart add -a 1m -s 28G -t freebsd-zfs -l disk0 ada0<\/mark><\/code>    \/\/ \u5212\u520628GB\u4f5c\u4e3aFreeBSD\u6839\u5206\u533a<br>\u6216\u4e0d\u6307\u5b9a-s\u53c2\u6570\uff0c<mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>gpart add -a 1m -t freebsd-zfs -l disk0 ada0<\/code><\/mark> \/\/ \u5269\u4f59\u6240\u6709\u78c1\u76d8\u7a7a\u95f4\u90fd\u5212\u5206\u7ed9FreeBSD\u6839\u5206\u533a<br><mark style=\"background-color:#ffd700\" class=\"has-inline-color\"><code>ada0p5 added<\/code><\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u624b\u52a8\u521b\u5efa\u5fc5\u8981\u7684zpool\u548c\u5404\u4e2a\u6302\u8f7d\u70b9<\/strong><br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>mount -t tmpfs tmpfs \/mnt<br>zpool create -o altroot=\/mnt zroot ada0p5<\/code><\/mark> \/\/ ada0p5\u5c31\u662f\u524d\u9762\u521b\u5efa\u7684freebsd-zfs\u5206\u533a<br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>zfs set compress=on zroot<\/code><\/mark>    \/\/ \uff08\u53ef\u9009\u9879\uff09zroot\u542f\u7528\u538b\u7f29<br><code><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">zfs create -o mountpoint=none zroot\/ROOT<br>zfs create -o mountpoint=\/ -o canmount=noauto zroot\/ROOT\/default<br>mount -t zfs zroot\/ROOT\/default \/mnt<br>zfs create -o mountpoint=\/tmp -o exec=on -o setuid=off zroot\/tmp<br>zfs create -o canmount=off -o mountpoint=\/usr zroot\/usr<br>zfs create zroot\/usr\/home<br>zfs create -o exec=off -o setuid=off zroot\/usr\/src<br>zfs create zroot\/usr\/obj<br>zfs create -o mountpoint=\/usr\/ports -o setuid=off zroot\/usr\/ports<br>zfs create -o exec=off -o setuid=off zroot\/usr\/ports\/distfiles<br>zfs create -o exec=off -o setuid=off zroot\/usr\/ports\/packages<br>zfs create -o canmount=off -o mountpoint=\/var zroot\/var<br>zfs create -o exec=off -o setuid=off zroot\/var\/audit<br>zfs create -o exec=off -o setuid=off zroot\/var\/crash<br>zfs create -o exec=off -o setuid=off zroot\/var\/log<br>zfs create -o atime=on -o exec=off -o setuid=off zroot\/var\/mail<br>zfs create -o exec=on -o setuid=off zroot\/var\/tmp<br>ln -s \/usr\/home \/mnt\/home<br>chmod 1777 \/mnt\/var\/tmp<br>chmod 1777 \/mnt\/tmp<br>zpool set bootfs=zroot\/ROOT\/default zroot<br>cat &lt;&lt; EOF > \/tmp\/bsdinstall_etc\/fstab<\/mark><br>? <mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"># Device Mountpoint FStype Options Dump Pass#<\/mark><br>? <mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">\/dev\/gpt\/swap0 none swap sw 0 0<\/mark><br>? <mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">EOF<\/mark><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u521b\u5efaFreeBSD\u7684EFI\u5f15\u5bfc\u9879<\/strong><br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>mount -t msdosfs \/dev\/ada0p1 \/media<\/code><\/mark> \/\/ \u6302\u8f7dEFI\u5206\u533a\/dev\/ada0p1<br><code><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\">cp \/boot\/loader.efi \/media\/EFI\/Boot\/bootx64-freebsd.efi<br>efibootmgr --create --activate --label \"FreeBSD\" --loader \"\/media\/EFI\/Boot\/bootx64-freebsd.efi\"<\/mark><br><mark style=\"background-color:#ffd700\" class=\"has-inline-color\">Boot to FW : false<br>BootCurrent: 0001<br>Timeout : 0 seconds<br>BootOrder : 0007, 0006, 0004, 0000, 0001, 0002, 0003, 0005<br> Boot0007* FreeBSD<br> Boot0006* ubuntu<br> Boot0004* Windows Boot Manager<br> Boot0000* UiApp<br>+Boot0001* UEFI VBOX CD-ROM VB1-1a2b3c4d<br> Boot0002* UEFI VBOX HARDDISK VB0b986931-09156175<br> Boot0003 EFI Internal Shell<br> Boot0005* UEFI PXEv4 (MAC:XXXXXXXXXXXX)<\/mark><\/code><br>\u4e0d\u5e26\u53c2\u6570\u7684<mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>efibootmgr<\/code><\/mark>\u547d\u4ee4\u4f1a\u5217\u51faEFI\u542f\u52a8\u9879<br>\u547d\u4ee4<mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>efibootmgr -b 0007 -B<\/code><\/mark>\u53ef\u4ee5\u5220\u9664\u7f16\u53f7\u4e3a0007\u7684EFI\u542f\u52a8\u9879<br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>umount \/media<\/code><\/mark>    \/\/ \u5378\u8f7dEFI\u5206\u533a<br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>exit<\/code><\/mark>    \/\/ \u9000\u51faShell<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u540e\u7eed\u5b89\u88c5<\/strong><br>\u9000\u51faShell\u540e\uff0cFreeBSD\u5b89\u88c5\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u7ee7\u7eed\uff1a\u590d\u5236\u6587\u4ef6->\u8bbe\u7f6eRoot\u5bc6\u7801->\u9009\u62e9\u65f6\u533a->\u8bbe\u7f6e\u65f6\u95f4->\u9009\u62e9\u968f\u7cfb\u7edf\u5f00\u542f\u7684\u670d\u52a1->\u5b89\u5168\u9009\u9879->\u6dfb\u52a0\u7528\u6237->\u6700\u540e\u7684\u624b\u52a8\u914d\u7f6e\u9009\u62e9<mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>Yes<\/code><\/mark>\u8fdb\u5165Shell<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"351\" height=\"144\" src=\"https:\/\/techblog.hxdy2013.com\/wp-content\/uploads\/2023\/09\/49.png\" alt=\"\" class=\"wp-image-205\" srcset=\"https:\/\/techblog.hxdy2013.com\/wp-content\/uploads\/2023\/09\/49.png 351w, https:\/\/techblog.hxdy2013.com\/wp-content\/uploads\/2023\/09\/49-300x123.png 300w\" sizes=\"auto, (max-width: 351px) 100vw, 351px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>sysrc zfs_enable=\"YES\"<\/code><\/mark>    \/\/ \u8bbe\u7f6eZFS\u968f\u7cfb\u7edf\u542f\u52a8<br><mark style=\"background-color:#ffd700\" class=\"has-inline-color\">zfs_enable: NO -> YES<\/mark><br>\u67e5\u770b<code>\/boot\/loader.conf<\/code>\u662f\u5426\u6709<code>zfs_load=\"YES\"<\/code>\uff0c\u6ca1\u6709\u5c31\u6dfb\u52a0\u8fdb\u53bb<br><mark style=\"background-color:#9DFF20\" class=\"has-inline-color\"><code>cat \/boot\/loader.conf<br>echo zfs_load=\"YES\" >> \/boot\/loader.conf<br>exit<\/code><\/mark>    \/\/ \u9000\u51faShell<br>\u9000\u51faShell\u540e\u91cd\u542f\uff0c\u5b8c\u6210\u5b89\u88c5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UEFI\u591a\u7cfb\u7edf\u4e2d\u7684FreeBSD\u8981\u4f7f\u7528ZFS\u5e76\u4e0e\u540c\u4e00\u5757\u78c1\u76d8\u4e0a\u7684\u5176\u4ed6OS\u5171\u5b58\uff0c\u5b89\u88c5\u65f6\u5fc5\u987b\u9009\u62e9\u8fdb\u5165Shell\u624b\u52a8\u5206\u533a\u3002\u9009\u62e9Auto(ZFS)\u5c31\u5fc5\u987b\u8986\u76d6\u6574\u4e2a\u78c1\u76d8\uff0c\u65e0\u6cd5\u4e0e\u5176\u4ed6OS\u5171\u5b58\u3002FreeBSD\u5728\u8fd9\u4e00\u70b9\u4e0a\u4e0d\u5982Linux\u7075\u6d3b\u3002\u672c\u6587\u901a\u8fc7\u5b9e\u4f8b\u8bb2\u8ff0\u5982\u4f55\u5728\uff08VirtualBox\u865a\u62df\u673a\u4e2d\u7684\uff09FreeBSD 13.2\u5b89\u88c5\u65f6\u8fdb\u5165Shell\u624b\u52a8\u5206\u533a\u5b9e\u73b0UEFI\u591a\u7cfb\u7edf\u4e2d\u7684FreeBSD\u4f7f\u7528ZFS\u5e76\u4e0e\u540c\u4e00\u5757\u78c1\u76d8\u4e0a\u7684\u5176\u4ed6OS\u5171\u5b58\u3002 \u786c\u4ef6\u73af\u5883 Lenovo ThinkPad T14 Gen2 20W1S3H811: Intel i5-1145G7 + DDR4 16GB + NVMe 512GB \u8f6f\u4ef6\u73af\u5883 Win11 x64 Build 22621.2134 \u82f1\u6587\u4e13\u4e1a\u7248 + VirtualBox v7.0.8 r156879 VirtualBox\u73af\u5883 VM Type = BSDVersion = FreeBSD (64bit)Base Memory = 4GBProcessor = 4 CoresVirtualDisk:Size = 128GBPartition1 = EFI 300MBPartition2 = NTFS 32GB, Win11 InstalledPartition3 = Ext4 32GB, Xubuntu 22.04 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-196","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=\/wp\/v2\/posts\/196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=196"}],"version-history":[{"count":8,"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":206,"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions\/206"}],"wp:attachment":[{"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techblog.hxdy2013.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}