the-hurd-on-bare-metal.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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>The Hurd on Bare Metal — 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>The Hurd on Bare Metal</h1><main><section class="basic-section-padding"><article><h3>by Joshua Branson — August 13, 2023</h3><div><p>This blog post was written on a Debian GNU/Hurd system on a IBM ThinkPad T43
  2. with 1.5 GB of RAM. (It was edited on Guix System (running linux)). Apparently
  3. running Emacs on the hurd in the console is actually quite stable. This post
  4. will describe my attempt to make this T43 be my daily laptop. Let’s see
  5. how far I can get with that eh?</p><p>tl;dr Debian GNU/Hurd is shockingly stable. If you are an emacs wiz,
  6. then you will feel right at home.</p><p>The first thing to notice after you login to the Hurd is that you can
  7. easily switch virtual consoles via <code>Alt-&lt;right-arrow&gt;</code>. It is
  8. actually pretty awesome that you can do this. I know literally every
  9. other OS has this, but it is cool to have Emacs open in one console,
  10. and have another program running on another console; switching
  11. between them feels beautiful.</p><p>Another thing to notice is that <code>mount</code> does not work. Let's explore that shall
  12. we?</p><pre><code>cat /etc/mtab | awk '{ print $1 &quot; &quot; $2 &quot; &quot; $3 }'
  13. /dev/hd0s1 / ext2fs
  14. none /run /hurd/tmpfs
  15. none /run/lock /hurd/tmpfs
  16. /dev/hd0s6 /home /hurd/ext2fs
  17. proc /proc /hurd/procfs</code></pre><p>Actually <code>/etc/mtab</code> is a symlink to <code>/proc/mounts</code>.</p><pre><code>ls -lha /etc/mtab
  18. lrwxr-xr-x 1 root root 12 Apr 10 12:14 /etc/mtab -&gt; /proc/mounts</code></pre><p>It looks like the Hurd labels MBR partitions slightly differently from Linux. It
  19. appears that the Hurd uses <code>/dev/hd0s1</code>, <code>dev/hd0s2</code>, and so on.</p><pre><code>echo $pw | sudo -S fdisk -l /dev/hd0
  20. Disk /dev/hd0: 37.26 GiB, 40007761920 bytes, 78140160 sectors
  21. Units: sectors of 1 * 512 = 512 bytes
  22. Sector size (logical/physical): 512 bytes / 512 bytes
  23. I/O size (minimum/optimal): 512 bytes / 512 bytes
  24. Disklabel type: dos
  25. Disk identifier: 0x1ab32a1b
  26. Device Boot Start End Sectors Size Id Type
  27. /dev/hd0s1 2048 26681343 26679296 12.7G 83 Linux
  28. /dev/hd0s2 26683390 78139391 51456002 24.5G 5 Extended
  29. /dev/hd0s5 26683392 28682239 1998848 976M 82 Linux swap / Solaris
  30. /dev/hd0s6 28684288 78139391 49455104 23.6G 83 Linux</code></pre><p>It looks like a good place to start learning how to use the Hurd is
  31. via <code>https://www.debian.org/ports/hurd/hurd-install</code>.</p><p>So the file that describes my network interfaces is here:</p><pre><code>cat /etc/network/interfaces
  32. # This file describes the network interfaces available on your system
  33. # and how to activate them. For more information, see interfaces(5).
  34. source /etc/network/interfaces.d/*
  35. # The loopback network interface
  36. auto lo
  37. iface lo inet loopback
  38. # The primary network interface
  39. auto /dev/eth0
  40. iface /dev/eth0 inet dhcp</code></pre><p>So it looks like i should definitely read <code>man 5 interfaces</code> at some
  41. point. And the Debian Hurd guide mentions that I should add name
  42. servers to my /etc/resolv.conf file. I am not certain why it says
  43. that I should do that though, but I went ahead and added OpenDNS’ name
  44. servers.</p><pre><code>cat /etc/resolv.conf
  45. nameserver 172.16.112.1
  46. cat /etc/resolv.conf
  47. nameserver 172.16.112.1
  48. nameserver 208.67.222.222
  49. nameserver 208.67.220.220</code></pre><p>Ok, so it seems like <code>pfinit</code> is still the default GNU Hurd <code>TPC/IP</code>
  50. translator, which is based on an old Linux TCP/IP driver (<code>lwip</code> or
  51. <code>rumpkernel</code> may one day replace it). Apparently my internet
  52. connectivity can be found by quering <code>/servers/socket/2</code> (for IPv4)
  53. and <code>/servers/socket/26</code> (for IPv6).</p><pre><code># fsysopts /servers/socket/2</code></pre><p>If you run the above command you will see that the ethernet device
  54. that the Hurd uses is <code>/dev/eth0</code>.</p><p>The Hurd has a stateless (stateful is better) ethernet filter. For example, here
  55. is how to disable ssh access:</p><pre><code># settrans -c /dev/eth0f /hurd/eth-filter \
  56. -i /dev/eth0 -r &quot;not port 22&quot;</code></pre><p>I could then, tell the pfinit translator to use <code>/dev/eth0f</code> instead
  57. of <code>/dev/eth0</code> via (I think this how you would do it):</p><pre><code># fsysopts /server/socket/2 --interface=/dev/eth0f</code></pre><p>This is course is not persistant across reboots. I would probably
  58. need to replace <code>/dev/eth0</code> in <code>/etc/network/interfaces</code> with
  59. <code>/dev/eth0f</code>.</p><p>The Hurd lets you mount cd drives as a regular user. I should be able
  60. to look at the files in my CD drive via:</p><pre><code>cd /dev
  61. # ./MAKEDEV cd0
  62. # settrans /media/cdrom0 /hurd/is09660fs /dev/cd0
  63. $ cd /media/cdrom0</code></pre><p>Apparently the Hurd does have a network filesystem translator
  64. (<code>/hurd/nfs</code>), but I believe that that translator only supports
  65. NFSv2. So it may not be as performanent as one might want or support
  66. the latest NSF features.</p><p>Since I installed the stable Hurd release from 2021, the guide
  67. recommends that if I want a stable environment, then I can just
  68. configure apt to use the apt sources from 2021. That should let me
  69. have a fairly stable Hurd distro. So let’s try that.</p><pre><code>cat /etc/apt/apt.conf.d/99ignore-valid-until
  70. Acquire::Check-Valid-Until &quot;false&quot;;
  71. cat /etc/apt/sources.list
  72. deb [trusted=yes] https://snapshot.debian.org/archive/debian-ports/20210812T100000Z sid main
  73. deb [trusted=yes] https://snapshot.debian.org/archive/debian-ports/20210812T100000Z unreleased main
  74. deb-src [trusted=yes check-valid-until=no] https://snapshot.debian.org/archive/debian/20210812T100000Z sid main</code></pre><p>This mostly worked, but apt gave a warning about the debian gpg key
  75. had expired.</p><p>Well let’s try to upgrade anyway.</p><pre><code># apt update &amp;&amp; apt upgrade</code></pre><p>That seemed to work.</p><pre><code># apt install debian-ports-archive-keyring
  76. # apt update
  77. # apt upgrade
  78. # apt install git git-email
  79. $ git config --global user.name &quot;Joshua Branson&quot;
  80. $ git config --global user.email &quot;jbranso@dismail.de&quot;
  81. $ cd; git clone https://notabug.org/jbranso/prog</code></pre><p>Now I suppose that it is time to follow <a href="https://drewdevault.com/2019/12/30/dotfiles.html">Drew Devault’s guide</a> on how to
  82. manage your home directory’s configuration files as a git repository.</p><p>I should also read the <a href="https://www.debian.org/ports/hurd/hurd-doc-translator">hurd-doc-translator</a> webpage.</p><p>Apparently, the Hurd’s translators transform data into different data.
  83. The usual case, is that a translator translates bits of the filesystem
  84. into different data, and what is awesome is that translators run in
  85. userspace. Most of the time translators will need to get data from
  86. hardware, and they will request the kernel to help them get this data.
  87. There are some exceptions: <code>/dev/zero</code> does not need hardware data, so
  88. a read from <code>dev/zero</code> is entirely run in userspace.</p><p>There are two kinds of translators: active and passive. An active
  89. translator is currently running. You can change its settings or kill
  90. it via the <code>settrans -a</code> command. The <code>-a</code> refers to the <strong>active</strong>
  91. translator. So <code>settrans -a file.txt</code> will try to kill the userspace
  92. translator process. If you start a translator via the <code>-a</code> option,
  93. then the translator is not persistant accross reboot. For that reason,
  94. most of the time you do not want the <code>-a</code> option, which is what
  95. settrans by default does.</p><p>If you are ever curious to know if a filesystem node has an attached translator,
  96. then you can find out via this command:<code>showtrans NODE</code>. It will tell you what
  97. passive translators are set at a filesystem node.</p><p>Let's take a walk through some basic Hurd translators.</p><pre><code>settrans [OPTIONS...] NODE [TRANSLATOR ARGS...]</code></pre><p>For example, I can have a text file like so:</p><pre><code>cat ~/Documents/hello.txt
  98. boring text document.</code></pre><p>Now let’s set the <code>hello</code> translator on that filesystem node.</p><pre><code>settrans -a ~/Documents/hello.txt /hurd/hello
  99. cat ~/Documents/hello.txt
  100. Hello, world!</code></pre><p>Now let’s see that the file system options are for the <code>/hurd/hello</code>
  101. translator:</p><pre><code>fsysopts ~/Documents/hello.txt
  102. /hurd/hello --contents='Hello, world!
  103. '</code></pre><p>I can modify the <code>contents</code> of the hello translator via:</p><pre><code>fsysopts ~/Documents/hello.txt --contents=&quot;Hello Joshua
  104. &quot;
  105. cat ~/Documents/hello.txt
  106. Hello Joshua</code></pre><p>Notice that we changed the options for that translator without having
  107. to restart it with normal user privledges.</p><p>Now let’s make the hello translator go away:</p><pre><code>settrans -a ~/Documents/hello.txt
  108. cat ~/Documents/hello.txt
  109. boring text document.</code></pre><p>Now let’s try to stack these translators eh?</p><pre><code>settrans gnucode.me /hurd/httpfs http://gnucode.me
  110. ls gnucode.me/installing-wordpress.html
  111. gnucode.me/installing-wordpress.html
  112. settrans -c xml /hurd/xmfls ~/gnucode.me/feed.xml
  113. cd
  114. ls</code></pre><p>Here the ls command apparently hanged. <code>C-c</code> ended said hanging, but
  115. the Hurd locked up on me. I actually saw an error message that said
  116. something like “kbd queue full.” And then my keyboard become
  117. unresponsive. After a few hours, I pressed “Ctrl-Alt-Del,” and that
  118. saved my bacon. That killed the hurd console, and it let me switch to
  119. a virtual console. That enabled me to shut down the hurd gracefully.
  120. BUT…What went wrong? Why did <code>ls</code> hang?</p><p>Well here is a clue:</p><pre><code>ls ~/gnucode.me/feed.xml
  121. ls: cannot access feed.xml': No such file or directory</code></pre><p>Well, httpfs does not expose feed.xml. It does not recognize that as part of the
  122. gnucode.me website. <code>httpfs</code> only lists webpages that are listed on
  123. <code>index.html</code>. So <code>~/gnucode.me/feed.xml</code> does not translate to the local the
  124. filesystem. If I had to guess, I would say that xmlfs tries to run but does not
  125. check if its underlying file exists.</p><p>I should also mention that I am using a very minimal <code>.emacs.d/init.el</code>. It is
  126. possible to get doom emacs to run on the Hurd, but the last time that I tried
  127. it, emacs locked up on me. I was forced to do a hard shutdown, which resulted in
  128. filesystem corruption and I had to re-install. So for now, I am using a very
  129. simple and minimal emacs. You can actually install some emacs packages via apt.
  130. Just search for <code>apt search magit</code> to get you started.</p><p>I would like to try running i3 on the hurd at some point, because that
  131. is a very light-weight window manager, but I have not yet tried
  132. setting up X to run. Partly because I only have 1.5GB of RAM, and I
  133. have heard that X tends to lock up or be really slow on the Hurd.</p><p>Surprizingly the Hurd only uses about <code>161MB</code> of RAM, when I run emacs
  134. on the console.</p><ul><li><p>What I have done so far</p><ul><li><p>Emacs
  135. I would love to remap control and caps, but I am not certain how
  136. to do that in the console.</p></li><li><p>Irc (via Erc)</p></li><li><p>Gnus my email client
  137. But I still need to set up the ability to send email.</p></li></ul></li></ul><p>Packages to install (glibc-doc-reference) requires enabling non-free
  138. packages:</p><pre><code># apt install gnupg emacs surfraw msmtp glibc-doc glibc-doc-reference</code></pre><p>Trying to create/open a file in emacs that ends in *.gpg crashes
  139. Emacs. I have no idea why.</p><p>Currently, msmtp cannot securely send email, because it cannot decrypt
  140. the encrypted file that has my password.</p><p>My Hurd machine also has my “jbranso@dismail.de” gpg key. I was able
  141. to import the data via an ssh session.</p><p>I was actually surprized that the debian wiki mentioned this command:
  142. <code>service ssh restart</code> and not a systemd specific command, but
  143. apparently <code>man service</code> is the manual that I want to read.
  144. Apparently ssh is already running. I verified this with:</p><pre><code>echo $pw1 | sudo -S service --status-all | grep ssh
  145. [ + ] ssh</code></pre><p>I really should set up Sergey's terrible MDNS responder, so that I can ssh in
  146. the Hurd more easily, but that is a task that I will set for a later date. I
  147. should also possibly update my hard drive to a larger drive. I think the current
  148. one has 100GB or so. Maybe less. And it might not be a bad idea to set up an SSD
  149. or DVD drive via the CD-ROM bay and try the rumpdisk out. I would also like to
  150. be able to publish my blog from the Hurd too, but I have been unsuccessful to
  151. install Haunt on my Hurd box. I should also try to install Guix on it, but I am
  152. concerned about hard drive space at the moment.</p><p>Anyway, you can take a look at my <a href="https://notabug.org/jbranso/hurd-home">hurd
  153. home</a> git directory if you like. Safe
  154. travels!</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>