123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <!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
- 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
- any other. It was cold and dark as I arose to play with my new OpenBSD
- computer. It was time to reboot! That magical moment when OpenBSD <a href="https://www.openbsd.org/innovations.html">relinks the
- kernel at boot</a>. How cool is that?</p><p>My admiration for this world class operating continues to rise as it boots, and
- OpenBSD proudly slaps me in the face (I did not write down the OpenBSD error
- 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></p></blockquote><p>Hmmm. Well that’s a bummer. It looks like I had told OpenBSD that that usb stick
- was necesary for boot. I also did not have the usb stick plugged in, and OpenBSD
- needed me to write <code>/dev/sd1i</code> not <code>sd1i</code>. It might be a good project idea to
- 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
- tried to type out <code>cd /etc/</code>. Instead I got gibberish. Testing the keyboard a
- bit, I noticed that the keyboard was in the qwerty layout. I use dvorak. And my
- laptop keyboard physically shows a dvorak keyboard layout. It’s really hard to
- type correctly on a keyboard when pressing “‘,.pyf” is “qwerty”. Well let’s
- change my keyboard layout (notice that all commands below are run as the <code>root</code>
- 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
- 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
- /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
- mounted read only. So even if I find a text editor that I can use, I cannot
- modify <code>/etc/fstab</code>. How do I mount <code>/</code> read-write? According to the irc people
- who helped me out, this is how: you update the mount information based on what
- <code>/etc/fstab</code> says.</p><pre><code># mount -uvw /
- # mount
- /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
- 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
- listed in <code>/etc/fstab</code>. I did not read that option in the manpage yet. So I
- 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
- that will give me some clue which filesystem is which. (please note that I am
- intentionally removing the offsets).</p><pre><code># disklabel -h sd1
- 16 partitions:
- # size offset fstype [fsize bsize cpg]
- a: 1.0G 4.2BSD 2048 16384 12960
- b: 8.0G swap
- c: 931.5G unused
- d: 4.0G 4.2BSD 2048 16384 12960
- e: 19.5G 4.2BSD 2048 16384 12960
- f: 30.0G 4.2BSD 2048 16384 12960
- g: 1.0G 4.2BSD 2048 16384 12960
- h: 20.0G 4.2BSD 2048 16384 12960
- i: 3.0G 4.2BSD 2048 16384 12960
- j: 6.0G 4.2BSD 2048 16384 12960
- 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
- partition is which. I guess I will just guess. Eventually I did correctly mount
- <code>/usr</code>, so now I should have access to some text editors! So now I could edit
- <code>fstab</code>.</p><pre><code># vim /etc/fstab
- vim: unknown command</code></pre><p>Ok. vim is not installed. Let’s try vi.</p><pre><code># vi /etc/fstab
- 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>
- shows me:</p><pre><code># head /etc/fstab
- 5583d235b610c8a2.a / ffs rw,softdep 1 1
- 5583d235b610c8a2.k /home ffs rw,softdep,nodev,nosuid 1 2
- 5583d235b610c8a2.d /tmp ffs rw,softdep,nodev,nosuid 1 2
- 5583d235b610c8a2.f /usr ffs rw,softdep,nodev 1 2
- 5583d235b610c8a2.g /usr/X11R6 ffs rw,softdep,nodev 1 2
- 5583d235b610c8a2.h /usr/local ffs rw,wxallowed,softdep,nodev 1 2
- 5583d235b610c8a2.j /usr/obj ffs rw,softdep,nodev,nosuid 1 2
- 5583d235b610c8a2.i /usr/src ffs rw,softdep,nodev,nosuid 1 2
- 5583d235b610c8a2.e /var ffs rw,softdep,nodev,nosuid 1 2
- 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
- to just overwrite <code>fstab</code> with the output of <code>head</code>. Please do NOT copy or
- execute the following command:</p><pre><code># head /etc/fstab > /etc/fstab</code></pre><p>I wish I had read the irc chat before I had executed the above command. In the
- words of a wise sage, “the redirection happens before head runs, so you’ll just
- get a blank file.” And that is exactly what happened. <code>/etc/fstab</code> was empty.
- Now how do I mount filesystem partitions in the correct locations? “Out of the
- 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
- <code>fstab</code>. Unfortunately, that backup command had not run yet. This was a fresh
- 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
- helpful, because it shows you the default size of the various partitions that
- the auto installer sets up. With that information, I was able to re-mount all my various
- partitions. Then someone on irc chat gave me this beauty of a command:</p><pre><code># mount | awk '{ print $1 " " $3 " " $5 " rw 0 0"}' > /etc/fstab</code></pre><p>That created my <code>fstab</code> for me! Let’s check it out!</p><pre><code># cat /etc/fstab
- sd1.a / ffs rw 1 1
- sd1.k /home ffs rw 1 2
- sd1.d /tmp ffs rw 1 2
- sd1.f /usr ffs rw 1 2
- sd1.g /usr/X11R6 ffs rw 1 2
- sd1.h /usr/local ffs rw 1 2
- sd1.j /usr/obj ffs rw 1 2
- sd1.i /usr/src ffs rw 1 2
- sd1.e /var ffs rw 1 2
- sd1.b none swap sw</code></pre><p>Hmm, well the mount options are absent, and it is NOT using UIDs…But this
- should be enough to boot into a complete system. So I rebooted. Upon reboot, I
- was able to change the mount points to UIDs and copy the proper mount options
- from my desktop OpenBSD. I then very quickly set up <a href="https://man.openbsd.org/hotplugd">hotplugd</a>, which I will
- 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>
|