accidentally-deleting-fstab.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /><meta name="keywords" content="GNU, Emacs, Libre Software, Hurd, Guile, Guix" /><meta name="description" content="GNUcode.me is a website focusing on libre software projects, especially the GNU project." /><link type="application/atom+xml" rel="alternate" title="GNUcode.me -- Feed" href="/feed.xml" /><a rel="me" href="https://fosstodon.org/@thegnuguy"></a><link type="text/css" href="css/footer.min.css" rel="stylesheet"></link><link type="text/css" href="css/header.min.css" rel="stylesheet"></link><link type="text/css" href="css/main.min.css" rel="stylesheet"></link><title>Accidentally Deleting fstab — GNUcode.me</title></head><body><header><nav><ul><li><a href="index.html">GNUcode.me</a></li><li><a href="services.html">Services</a></li><li><a href="about.html">About</a></li><li><a href="business-ideas.html">Business-ideas</a></li></ul></nav></header><h1>Accidentally Deleting fstab</h1><main><section class="basic-section-padding"><article><h3>by Joshua Branson — April 05, 2023</h3><div><p>The end of my previous blog post was a bit of a cliff hanger:</p><p>I did have a great time the next day. I was hoping to automount my usb
  2. stick on boot. So I added this beauty to my <code>/etc/fstab</code>.</p><blockquote><p><code>sd1i /mnt/usb msdos rw 1 2</code></p></blockquote><p>The next time I booted it threw me into a rescue shell with only <code>/</code> mounted.</p><p>This is the story of how I fixed a broken fstab on OpenBSD. The day began like
  3. any other. It was cold and dark as I arose to play with my new OpenBSD
  4. computer. It was time to reboot! That magical moment when OpenBSD <a href="https://www.openbsd.org/innovations.html">relinks the
  5. kernel at boot</a>. How cool is that?</p><p>My admiration for this world class operating continues to rise as it boots, and
  6. OpenBSD proudly slaps me in the face (I did not write down the OpenBSD error
  7. message, but this is essentially what it said):</p><blockquote><p>mount cannot find device sd1i. You are now in a resque shell.</p><p>root&gt;</p></blockquote><p>Hmmm. Well that’s a bummer. It looks like I had told OpenBSD that that usb stick
  8. was necesary for boot. I also did not have the usb stick plugged in, and OpenBSD
  9. needed me to write <code>/dev/sd1i</code> not <code>sd1i</code>. It might be a good project idea to
  10. add <a href="https://man.openbsd.org/opendev">opendev</a> support to OpenBSD’s mount. Any takers?</p><p>Anyway, to fix this, I attempted to delete that last line from <code>/etc/fstab</code>. I
  11. tried to type out <code>cd /etc/</code>. Instead I got gibberish. Testing the keyboard a
  12. bit, I noticed that the keyboard was in the qwerty layout. I use dvorak. And my
  13. laptop keyboard physically shows a dvorak keyboard layout. It’s really hard to
  14. type correctly on a keyboard when pressing “‘,.pyf” is “qwerty”. Well let’s
  15. change my keyboard layout (notice that all commands below are run as the <code>root</code>
  16. user. The <code>#</code> means you are running as a root user).</p><p>I painstakingly typed out the following command.</p><pre><code># wsconctl keyboard.encoding=us.dvorak</code></pre><p>Awesome, that is an improvement. Let’s change <code>/etc/fstab</code>. The following
  17. commands did not work, because the shell could not find the binary:</p><ul><li><code>nano /etc/fstab</code></li><li><code>vim /etc/fstab</code></li><li><code>vi /etc/fstab</code></li></ul><p>Well that’s weird. Is <code>/usr/bin</code> not mounted?</p><pre><code># mount
  18. /dev/sd1a on / type ffs (ro)</code></pre><p>Oh great! I only have <code>/</code> mounted! So my commands are limited, and <code>/</code> is
  19. mounted read only. So even if I find a text editor that I can use, I cannot
  20. modify <code>/etc/fstab</code>. How do I mount <code>/</code> read-write? According to the irc people
  21. who helped me out, this is how: you update the mount information based on what
  22. <code>/etc/fstab</code> says.</p><pre><code># mount -uvw /
  23. # mount
  24. /dev/sd1a on / type ffs (rw)</code></pre><p>Awesome, <code>fstab</code> is editable! I tried to edit <code>/etc/fstab</code> but <code>vi</code> was not
  25. available, probably because <code>vi</code> is located in <code>/usr</code>, which is not yet mounted.</p><p>What I should have done was <code>mount -U</code>. This just mounts all mount points
  26. listed in <code>/etc/fstab</code>. I did not read that option in the manpage yet. So I
  27. decided to manually try to guess which filesytem was which.</p><p>Well let’s print out human read-able file sizes of my filesystem partitions and
  28. that will give me some clue which filesystem is which. (please note that I am
  29. intentionally removing the offsets).</p><pre><code># disklabel -h sd1
  30. 16 partitions:
  31. # size offset fstype [fsize bsize cpg]
  32. a: 1.0G 4.2BSD 2048 16384 12960
  33. b: 8.0G swap
  34. c: 931.5G unused
  35. d: 4.0G 4.2BSD 2048 16384 12960
  36. e: 19.5G 4.2BSD 2048 16384 12960
  37. f: 30.0G 4.2BSD 2048 16384 12960
  38. g: 1.0G 4.2BSD 2048 16384 12960
  39. h: 20.0G 4.2BSD 2048 16384 12960
  40. i: 3.0G 4.2BSD 2048 16384 12960
  41. j: 6.0G 4.2BSD 2048 16384 12960
  42. k: 300.0G 4.2BSD 4096 32768 26062</code></pre><p>Ok. Clearly the 300G is my <code>/home</code>. I can mount that now.</p><pre><code># mount /dev/sd1k /home</code></pre><p>Ok. How do I mount <code>/usr</code> so that I have text editors? I don’t really know which
  43. partition is which. I guess I will just guess. Eventually I did correctly mount
  44. <code>/usr</code>, so now I should have access to some text editors! So now I could edit
  45. <code>fstab</code>.</p><pre><code># vim /etc/fstab
  46. vim: unknown command</code></pre><p>Ok. vim is not installed. Let’s try vi.</p><pre><code># vi /etc/fstab
  47. vi: unknown terminal type</code></pre><p>So vi doesn’t run on the console? That’s odd. Ok. Lets see what <code>head</code>
  48. shows me:</p><pre><code># head /etc/fstab
  49. 5583d235b610c8a2.a / ffs rw,softdep 1 1
  50. 5583d235b610c8a2.k /home ffs rw,softdep,nodev,nosuid 1 2
  51. 5583d235b610c8a2.d /tmp ffs rw,softdep,nodev,nosuid 1 2
  52. 5583d235b610c8a2.f /usr ffs rw,softdep,nodev 1 2
  53. 5583d235b610c8a2.g /usr/X11R6 ffs rw,softdep,nodev 1 2
  54. 5583d235b610c8a2.h /usr/local ffs rw,wxallowed,softdep,nodev 1 2
  55. 5583d235b610c8a2.j /usr/obj ffs rw,softdep,nodev,nosuid 1 2
  56. 5583d235b610c8a2.i /usr/src ffs rw,softdep,nodev,nosuid 1 2
  57. 5583d235b610c8a2.e /var ffs rw,softdep,nodev,nosuid 1 2
  58. 5583d235b610c8a2.b none swap sw</code></pre><p>Hey would you look at that! There is no line with <code>/mnt/usb</code>. I should be able
  59. to just overwrite <code>fstab</code> with the output of <code>head</code>. Please do NOT copy or
  60. execute the following command:</p><pre><code># head /etc/fstab &gt; /etc/fstab</code></pre><p>I wish I had read the irc chat before I had executed the above command. In the
  61. words of a wise sage, “the redirection happens before head runs, so you’ll just
  62. get a blank file.” And that is exactly what happened. <code>/etc/fstab</code> was empty.
  63. Now how do I mount filesystem partitions in the correct locations? “Out of the
  64. frying pan and into the fire.”</p><p>Some of the people on irc mentioned that <code>/var/backups</code> should have a copy of my
  65. <code>fstab</code>. Unfortunately, that backup command had not run yet. This was a fresh
  66. OpenBSD install afterall.</p><p>One of the people on the OpenBSD chat showed me this <a href="https://github.com/openbsd/src/blob/master/sbin/disklabel/editor.c#L91">link</a>, which was super
  67. helpful, because it shows you the default size of the various partitions that
  68. the auto installer sets up. With that information, I was able to re-mount all my various
  69. partitions. Then someone on irc chat gave me this beauty of a command:</p><pre><code># mount | awk '{ print $1 &quot; &quot; $3 &quot; &quot; $5 &quot; rw 0 0&quot;}' &gt; /etc/fstab</code></pre><p>That created my <code>fstab</code> for me! Let’s check it out!</p><pre><code># cat /etc/fstab
  70. sd1.a / ffs rw 1 1
  71. sd1.k /home ffs rw 1 2
  72. sd1.d /tmp ffs rw 1 2
  73. sd1.f /usr ffs rw 1 2
  74. sd1.g /usr/X11R6 ffs rw 1 2
  75. sd1.h /usr/local ffs rw 1 2
  76. sd1.j /usr/obj ffs rw 1 2
  77. sd1.i /usr/src ffs rw 1 2
  78. sd1.e /var ffs rw 1 2
  79. sd1.b none swap sw</code></pre><p>Hmm, well the mount options are absent, and it is NOT using UIDs…But this
  80. should be enough to boot into a complete system. So I rebooted. Upon reboot, I
  81. was able to change the mount points to UIDs and copy the proper mount options
  82. from my desktop OpenBSD. I then very quickly set up <a href="https://man.openbsd.org/hotplugd">hotplugd</a>, which I will
  83. explain next time. Until then!</p></div></article></section></main><footer><p>© 2020 Joshua Branson. The text on this site is free culture under the Creative Commons Attribution Share-Alike 4.0 International license.</p><p>This website is build with Haunt, a static site generator written in Guile Scheme. Source code is <a href="https://notabug.org/jbranso/gnucode.me">available.</a></p><p>The color theme of this website is based off of the famous <a href="#3f3f3f" target="_blank">zenburn</a> theme.</p></footer></body>