diff options
Diffstat (limited to 'posts')
-rw-r--r-- | posts/2021-12-15-rescuing-freebsd-the-unix-way.php | 78 |
1 files changed, 59 insertions, 19 deletions
diff --git a/posts/2021-12-15-rescuing-freebsd-the-unix-way.php b/posts/2021-12-15-rescuing-freebsd-the-unix-way.php index 57937bd..39be005 100644 --- a/posts/2021-12-15-rescuing-freebsd-the-unix-way.php +++ b/posts/2021-12-15-rescuing-freebsd-the-unix-way.php @@ -1,4 +1,4 @@ -<h1>Rescuing FreeBSD, the UNIX Way!</h1> +<h1>Rescuing FreeBSD, the UNIX Way (And a Free Upgrade Too!)</h1> <div class="description"> <p> @@ -34,11 +34,13 @@ Now came the hard part. Un-effing everything I <em>didn't</em> know was missing or broken. Who knows what else got removed during that operation. I can reinstall my entire package tree pretty easily, so I'm not that worried about anything missing from <code>/usr/local</code>. Maybe I have one or two config files in <code>/usr/local/etc</code> that I can live without. I know <code>/usr/home</code> is safe and restored. So all that's left is stuff like <code>lib, sbin, include, lib32, share</code> and a few others that aren't very unique to my system (packages notwithstanding). </p> -Here's where the YOLO part begins. I was already in the middle of building my system from source to track FreeBSD 13.0-STABLE, instead of RELEASE. So instead of using a rescue CD to copy just the right files back or completely reinstalling my system, I'll just <code>make buildworld</code> and upgrade/replace my system in-place to track STABLE. The install/upgrade/switching process is well-documented, and there are already difftools/mergetools responsible for making sure that all of the new artifacts go exactly where they're supposed to (overtop of your old or broken existing ones). - -https://docs.freebsd.org/en/books/handbook/cutting-edge/#makeworld +<p> + Here's where the YOLO part begins. I was already in the middle of building my system from source to track 13.0-STABLE, instead of RELEASE. So instead of using a rescue CD to copy just the right files back or completely reinstalling my system, I'll just upgrade my system in-place to track STABLE. The install/upgrade/switching process is well-documented, and there are already mergetools responsible for making sure that all of the new artifacts go exactly where they're supposed to (over top of your old or broken existing ones). +</p> -So let's follow the Handbook shall we? I'll start where I left off when everything imploded. Clean out <code>/usr/src</code> and clone the source tree. +<p> + <a href="https://docs.freebsd.org/en/books/handbook/cutting-edge/#makeworld">Time for the Handbook</a>. I'll start where I left off when everything imploded. Clean out <code>/usr/src</code> and clone the source tree, but with an absolute path this time. +</p> <pre> <code> @@ -47,7 +49,9 @@ So let's follow the Handbook shall we? I'll start where I left off when everythi </code> </pre> -And then start by compiling the world (userland) and the kernel. I'm going to use the GENERIC kernel for now so I can just get back up and running. +<p> + And then start compiling the world (userland, services, utilities) and the kernel. I'm going to use the GENERIC kernel for now so I can just get back up and running. This part takes a really really long time. +</p> <pre> <code> @@ -55,7 +59,9 @@ And then start by compiling the world (userland) and the kernel. I'm going to us </code> </pre> -It took literally hours. Poor little dual-core i5. It was already well on its way to completing when I realized I could have done this on my 8-core/16-thread server. "Oh, so you're reckless <em>and</em> stupid." Don't worry, I redeem myself later. Now I can actually install the new kernel and reboot into it. This is required before installing the world (userland). +<p> + It took literally half the day. Poor little dual-core i5. It was already well on its way to completing when I realized I could have done this on my 8-core/16-thread server. "Oh, so you're reckless <em>and</em> stupid." Don't worry, I redeem myself later. Now I can actually install the new kernel and reboot into it. This is required before installing the world (userland). +</p> <pre> <code> @@ -65,7 +71,9 @@ It took literally hours. Poor little dual-core i5. It was already well on its wa </code> </pre> -After rebooting I can check out my new version. +<p> + After rebooting I can check out my new version. +</p> <pre> <code> @@ -74,7 +82,9 @@ After rebooting I can check out my new version. </code> </pre> -Hmm, probably can't use <code>freebsd-version</code> because it's tied to the userland and <code>freebsd-update</code>. Let's try <code>uname</code>: +<p> + Hmm, probably can't use <code>freebsd-version(1)</code> because it's tied to the userland and <code>freebsd-update(1)</code>. Let's try <code>uname(1)</code>: +</p> <pre> <code> @@ -83,7 +93,9 @@ Hmm, probably can't use <code>freebsd-version</code> because it's tied to the us </code> </pre> -Success. Kernel is rebuilt, reinstalled, and tracking STABLE. Now it's time to install/upgrade everything else. Side note: this is one of the cool things about FreeBSD. It's a complete operating system, not just a kernel or a userland. All of the pieces were made to fit together instead of being glued together into a distro. +<p> + Success. Kernel is rebuilt, reinstalled, and tracking STABLE. Now it's time to install/upgrade everything else. Side note: this is one of the cool things about FreeBSD. It's a complete operating system, not just a kernel or just a userland with a compiler and some utilities. All of the pieces were made to fit together instead of being glued together into a distro. +</p> <pre> <code> @@ -91,9 +103,20 @@ Success. Kernel is rebuilt, reinstalled, and tracking STABLE. Now it's time to i </code> </pre> -This took a little bit longer, but from the output I could see that all of my important, potentially-missing binaries were being installed. Libraries, core utilities, applications, daemons, and man pages all got put back in their proper place. My system is totally back to life nad I'm confident that I'm running an un-maimed FreeBSD 13.0-STABLE. +<p> + This took a little bit longer, but from the output I could see that all of my important, potentially-missing files were being restored. Libraries, core utilities, applications, daemons, config, and man pages all got put back in their proper place. My system is totally back to life and I'm confident that I'm running an un-maimed FreeBSD 13.0-STABLE: +</p> + +<pre> +<code> +% freebsd-version +13.0-STABLE +</code> +</pre> -Now comes the sanity checking part of this job. I'm actually running a newer system now than I was before the upgrade. One of the components that was upgraded was ZFS, and with every major ZFS upgrade, I'm going to reinstall my ZROOT bootloader: +<p> + Now comes the sanity checking part of this job. I'm actually running a newer system now than I was before the upgrade. One of the components that was upgraded was ZFS, and with every major ZFS upgrade, I'm going to reinstall my root-on-ZFS bootloader before I reboot: +</p> <pre> <code> @@ -103,11 +126,17 @@ Now comes the sanity checking part of this job. I'm actually running a newer sys </code> </pre> -This may be unecessary, but it ensures that my root-on-ZFS will load correctly after a reboot with the new ZFS. And to be fair, it is mentioned in the <a href="https://cgit.freebsd.org/src/tree/UPDATING?h=stable/13"><code>UPDATING</code></a> guide in the source. +<p> + This may be unecessary, but it ensures that my root-on-ZFS will load correctly after a reboot with the new ZFS. And to be fair, it is mentioned in the <a href="https://cgit.freebsd.org/src/tree/UPDATING?h=stable/13"><code>UPDATING</code></a> guide in the source. +</p> -After a reboot, I've got one more sanity check. FreeBSD comes with <code>etcupdate(8)</code>, which you can use to manage merging upgrades with local changes to your <code>/etc /usr/local/etc</code> system config. If you run <code>etcupdate diff</code> you can see a diff of all of your customized system config. This is so good, I can't believe something like this doesn't exist on your typical Linux distro. Maybe it does and I just never realized it, but I'm betting they're all just different enough to not be able to share something like this. Anyway, after reviewing the diff, I applied any changes/merges by running <code>etcupdate</code>. +<p> + After a reboot, I've got one more sanity check. FreeBSD comes with <code>etcupdate(8)</code>, which you can use to manage merging upgrades with local changes to your <code>/etc, /usr/local/etc</code> system config. If you run <code>etcupdate diff</code> you can see a diff of all of your customizations. This is so good, I can't believe something like this doesn't exist on your typical Linux distro. Maybe it does and I just never realized it, but I'm betting they're all just different enough to not be able to share something like this. Anyway, after reviewing the diff, I applied any changes/merges by running <code>etcupdate</code>. +</p> -Now for one last bit of housekeeping, and this comes straight from the handbook. After an upgrade, the world installation leaves behind old libraries and files that the new system doesn't need but old applications or ports built against an older target might still require. To get rid of them, you can use the <code>Makefile</code> directives in <code>/usr/src</code> +<p> + Now for one last bit of housekeeping, and this comes straight from the handbook. After an upgrade, the world installation leaves behind old libraries and files that the new system doesn't need but old applications or ports built against an older target might still require. To get rid of them, you can use the <code>Makefile</code> directives in <code>/usr/src</code> +</p> <pre> <code> @@ -115,7 +144,9 @@ Now for one last bit of housekeeping, and this comes straight from the handbook. </code> </pre> -After reviewing the list and ensuring you don't need those files, you can clean them up with +<p> + After reviewing the list and ensuring you don't need those files, you can clean them up with +</p> <pre> <code> @@ -123,7 +154,16 @@ After reviewing the list and ensuring you don't need those files, you can clean </code> </pre> -// TODO: pkg reinstall -//I'm a <code>pkg leaf | xargs pkg install -f</code> away from completely restoring those. +<p> + And finally, I'll force install my entire package tree to make sure any third-party missing files are reinstalled: +</p> + +<pre> +<code> +# pkg leaf | xargs pkg install -f +</code> +</pre> -Redemption. I went from attempting to customize my kernel to annihilating <code>/usr</code> to restoring my entire system by building from FreeBSD's source tree via <code>git</code> and <code>make</code>. And I got an upgrade in the process too! Moving forward, I'm running slightly frequent automatic full-system snapshots. It should make it a lot easier to rescue accidental deletions of system files. I'm also going to take the time to learn more about the rescue disk process using the FreeBSD installer image. All told, not too bad for something that could have gone a lot worse. +<p> + Redemption. I went from attempting to customize my kernel to annihilating <code>/usr</code> to restoring my entire system by building from FreeBSD's source tree via <code>git(1)</code> and <code>make(1)</code>. And I got a free upgrade out of it! Moving forward, I'm running slightly frequent automatic full-system snapshots. It should make it a lot easier to rescue accidental deletions of system files. I'm also going to take the time to learn more about the rescue disk process using the FreeBSD installer image. All told, not too bad for a disaster-turned-learning-experience. +</p> |