Author: Leroy Förster

Leroy is a heavy Linux user and smart home enthusiast born in 1991 and living in Hamburg, Germany. Other hobbies include tinkering with open source hardware and composing mostly electronic music.
Living Room Forced-Airflow Old-Laptop-Rack Cabinet Build

Living Room Forced-Airflow Old-Laptop-Rack Cabinet Build

Building a Do-It-Yourself server rack, with old laptops as servers, airflow optimization, network and power distribution and low-noise ventilation for use in a living room while completely blending in and looking like a regular cabinet.

Introduction

What a title! Honestly – this is kind of hard to describe but you will get the idea. A few years ago I ditched my Chef-driven, hand-cooked Raspberry Pi farm and went for a more modern solution with less configuration. I wasted so much time trying to automate the software installation, OS maintenance and monitoring everything and yet couldn’t perform all the upgrades in time. It was terrible. So I moved to the everything is containerized operating system called “Rancher OS” and stacked those dusty old laptops I had lying around to a 2-server “Rack”.

Fast-forward 2 years – everything is running fine and the whole building and shipping happen on my workstation. No in-depth automation needed. When in use, the laptops got very hot and even switched themselves off as last resort. Even though the cabinet has no back wall there was just no good airflow. Leaving the door open did not help as well. Time for a better solution.

IMG_20180913_191835-e156f63b-5500-4aff-b932-50f4d5600bd2.jpg


Old cabinet: Over 29 °C with open back and front, laptops on the floor below, remains of the Raspberry Pi farm on the left

Taking measurements

I already have another one of those cabinets which is almost empty. I will transform this cheapo cabinet into a budget-friendly server cabinet. Before firing up the PC I take some measurements of the cabinet to bring it into my CAD software for further planning.

vlcsnap-2018-10-31-21h46m19s993-abe7d435-127e-4db4-8592-1f340de8af1d.png

3D Scan The Real Cabinet Into The CAD Software

Jk, it’s still 2018 so I have to re-create the cabinet manually using a Computer-Aided Drawing software. Being a complete beginner I heard a lot of good things about Autodesk’s Fusion 360 and already happily use Autodesk’s EAGLE software for PCB design so I will try this one out. They even let you register for the full version if you use it for non-commercial or low-volume purposes (Start-Up License) without any limits.

3D-CAD/CAM-Software für das Produktdesign | Fusion 360

Untitled-1c8b1625-d21d-465c-9f7f-1ee3bf0df830.png


First steps in Fusion 360: Creating the outer shell of the cabinet

Getting around in Fusion 360 is very easy and I did not need any tutorials or help. I’m totally amazed how easy it was. Autodesk has a very very in-depth tutorial series about absolutely everything, so if you feel like it, check it out on the Fusion 360 product page.

I will not cover every step of the creation of the 3D model. If you are interested in how I did the things I did or miss a step, you can inspect, download and change my project, which I released under an open-source license for you.

Server Cabinet

Untitled-30293efc-ba82-4669-a16f-665d67446cef.png


“Extruded” wooden block from the sketch above. Those are the outer measurements of the original cabinet

Untitled-108659ef-eaf0-4553-b59d-61649cf8e6b9.png


“Hollowed” the block and added a back wall. Thickness of the wood matches the original cabinet

Creation Of The Custom Back Wall And Cabinet Floors

Untitled-ebd6c0b3-c680-462a-ad8d-0d46b134e02b.png


Cutouts for the air inlet. Those have the size of 3 140×140 computer fan filters (only the filters) to reduce dust contamination

Untitled-a8c9e0a4-2e51-4e54-902c-c3f8e40112d0.png


Same for the fan air outlets on top and a cable inlet hole right above the air inlet

Alright. The basics of a server cabinet are there. Let’s now get to the really interesting part: Custom cabinet floors for each laptop model. To get the maximum cooling efficiency I will force the air through every air inlet of the laptops. There will be no chance of any heat jam in the cabinet itself and hot, used laptop air will be transported out of the cabinet right away. I have never seen something like this so let’s give it a try.

Untitled-19e0f0d4-7e23-45fc-9fb4-35ab2420a3d7.png
render-c6d1ca6b-d0d3-4f83-b401-73daa18fbf4b.png


Slightly outdated 3D render

Looks good to me. Now let’s go buy some wood. In Fusion 360 you can generate a drawing from your model. All the measurements are already known so you never have to type anything manually. Awesome. Let’s just put down some drawings and take these to the hardware store.

Untitled-c0feb212-08a6-48fc-9c45-9707ecaee64a.png


I did this for every new part I want to build. The only interesting measurements right now are the ones marked in red. I buy wood with the right thickness and dimensions and do all the cutouts with saws later by myself.

Now that I got myself some wood. Erm. Let’s just start doing the cutouts.

IMG_20180906_184719-ac9ef59b-aad2-4a5c-a340-f3dcd92f37c8.jpg


I use the jigsaw for all the rectangular and the three big fan outlet cutouts and a holesaw for the smaller, round ones.

20180903_193349-dcfc49f6-593d-46cb-b01c-8934b91d25e9.jpg
IMG_20180911_213322-7885416d-63d2-4b2f-b478-cbf8a9e991a8.jpg
IMG_20180911_213417-7813060e-b8fb-4fd2-acab-a8f2a42ca56a.jpg


The cable inlet gets an especially tight fit

IMG_20180911_215004-681abc7d-3e55-4b4b-b6c0-6683678e20df.jpg


I use some duct tape to fix the dust filters from the outer side to be able to easily dust it off if needed

IMG_20180911_220241-1f22e94c-617a-4b55-bd50-f0565a539649.jpg
IMG_20180911_220511-31445a39-278d-437c-8e74-7e04380433e6.jpg
IMG_20180909_144259-734f48ea-5596-45cc-9bfc-06039dd22bfb.jpg


After drilling new holes at the correct height for the cabinet floors, I can test if it fits. In case you wonder about that additional tiny hole in the back wall – The power connector of one laptop is in an awkward position and I have no chance to connect it from inside the cabinet. Looks weird, works well.

Adding Peripherals

IMG_20180911_200912-62041efb-9c59-4f25-b1e3-2359ce5b8742.jpg


Yes, I went shopping again.

I bought some peripherals to give the cabinet some life. The Amazon links below are affiliate links and you support me by clicking them and buying from there. Thanks for your support!

ARCTIC F14 PWM PST CO – 140 mm PWM PST Gehäuselüfter für Dauerbetrieb | Case Fan mit PST-Anschluss (PWM Sharing Technology) + Doppelkugellager | Reguliert RPM synchron

Novaato 2x Metall Kabeldurchführungen 60 mm Kabeldurchlass mit Bürste für mehr Ordnung auf dem Schreibtisch

ARCTIC Fan Grill – Lüfterabdeckung aus Stahl für 140 mm Lüfter I Lüftergitter Luftstrom-Durchlässig I Erhältlich in unterschiedlichen Größen

140mm PVC schwarze Computer PC Kühler Lüfter Lüftergitter Staubfilter Filtermatte Gehäuselüfter, 10 Stück

D-Link DGS-108 8-Port Layer2 Gigabit Switch (bis zu 2000 Mbit/s Datenübertragung pro Port, Non-Blocking-Architektur, lüfterlos, Metallgehäuse) schwarz

Brennenstuhl Eco-Line 6-fach Steckdosenleiste (mit Überspannungsschutz, Steckerleiste, Kindersicherung, Schalter und 5 m Kabel) anthrazit

The fans are especially interesting, because they are optimized for 24/7 operation and can be daisy-chained.

IMG_20180911_202405-71e34457-b51c-4faa-91c1-aae849080a1c.jpg
IMG_20180911_202937-082e6719-65ed-470a-968a-a98fb6fac7ba.jpg
IMG_20180911_203046_Bokeh-f0913180-e5a5-4abb-b78a-f6d6a3841f06.jpg
IMG_20180912_192852-bf45d37d-d786-4cf8-bc1d-b62f689b264d.jpg


After drilling holes for the fans, I use screws and nuts to fix the fan on the inside and the fan grill on the outside

IMG_20180912_192743_Bokeh-fe3eebd0-ba37-4a8e-9504-96b5cffdd907.jpg
IMG_20180912_201436-21d09be0-1fce-4e3f-bac4-06185bc069c5.jpg


Daisy-chained fans on the back wall and the turned-around cabinet behind it

IMG_20180912_202538-9b6cf1c8-d68f-4b43-a477-97e6c3616081.jpg


Nailed it

IMG_20180912_203127-dbd1f830-1a83-4fa0-954a-479bfae3af4c.jpg
IMG_20180913_182333-3d555208-31a5-4d26-96e3-a8a46bba1043.jpg


Add power and network

The network cable comes directly from the central switch. The 12 V fans are powered by a 9 V power supply to keep the noise low. The power comes from a discrete output of a UPS which can supply the whole cabinet (together with the rest of the infrastructure) for about 20 minutes allowing for a clean shutdown for all servers.

https://hub.docker.com/r/gersilex/apcupsd

My Docker image to shut down the Docker host from an APCUPSd container

APC Back-UPS BX – Unterbrechungsfreie Stromversorgung 700VA, BX700U-GR (AVR, 4 Schuko Ausgänge, USB) schwarz

Amazon affiliate link: The UPS I use, for a clean power output to the infrastructure. Worth it.

Alright. Now I have a stable network and power connection and I can even hear the air being pulled inside when closing the door. I think it pulls a lot of air through the cracks of that cheap cabinet.

IMG_20180913_182643-13d97aec-4c61-40a1-a826-41565b8a8de9.jpg
IMG_20180913_182650-23e01d34-32bf-40a2-b918-075883ddafe0.jpg
IMG_20180913_182637-ed76d404-7328-42ec-ae69-30eabc5ebdee.jpg


I use Door/Window insulation foam band and put it into or behind all the cracks

IMG_20180913_204354-8e10b905-3d2e-48eb-b4e4-56773102f106.jpg
IMG_20180913_183832-237787e2-8d6b-4c6c-aa6e-3a7d87c6cfe4.jpg


Just the usual cabinet. Or is it? It is. Or is it?

Conclusion

I can barely hear the new cabinet. In fact – it’s quieter than before because of the closed system. And thanks to the airflow and the cold air the laptop fans don’t need to spin high at all. Win-win.

IMG_20181101_003710-61a83da4-616d-4c46-a0b3-c0c86dd0a86c.jpg


The precise trusty old Chinese Alecto thermometer knock-off confirms our success. We now have about 1 °C ambient-to-cabinet difference as opposed to the 8 °C from before.

What’s Next?

I expect to add one or two more laptops and maybe some other small electronics. I will test with a pegboard next, which is basically all holes. This will put the directed cooling method I used in contrast with an overall cooling airflow concept. I will definitely report back as soon as I have new information.

I hope you enjoyed my biggest project to date. Have a great one!

Stop Entering Your SSH Passphrase All The Time

Stop Entering Your SSH Passphrase All The Time

You use SSH every day. You check out Git repositories, connect to servers and you Rsync a backup of your priceless home directory to remote machines for archiving and syncing. Because you know the importance of security you never use password authentication but an at least 4096 bit long RSA public-private keypair, encrypted by a passphrase only you know.

You are great. But you also waste time and patience, because you always enter the same single passphrase every time your computer wants to use SSH. Is it more secure, if you need to enter it every time? Probably not. The chance of someone figuring out (or keylogging) your passphrase is high enough, but I also heard of people who keep their passphrase in the clipboard for fast entry. Wow.

There is a simple, secure and elegant way to save your passphrase in-memory for your whole working session. Authentication agents like Pageant (Windows) or ssh-agent (OSX / Linux) can safely store your password and provide it to the SSH application when it requests a passphrase for your key.

„No Talk. Just Solution.“

Here is how I use it on my Linux and OSX machines. It requires you to install something called an SSH Agent Frontend – so basically a software that in turn talks to the ssh-agent – but in turn it provides a very elegant solution that manages the ssh agent, gpg agents and works even outside of environment scope (for cron jobs, etc.).

Using the frontend is optional and you can use the plain ssh-agent if you make sure to check for, inherit and run ssh-agent processes when needed. I strongly recommend using Keychain, though.

Installation & Configuration for Linux, OSX with Bash

I assume you already have installed SSH together with an SSH Agent, which is the case on most systems. I also assume that you use the bash or can transfer this article to other shells of your choice.

  • Install keychain by Funtoobrew install keychain yum install keychain apt-get install keychain pacman -Syu keychain (Or download and install manually from funtoo.org/Keychain)
  • Edit your ~/.bashrc and append the following line:eval `keychain --agents ssh --eval id_rsa` (Where ssh is the agent you want to use and id_rsa is a list of paths to your private key(s))
  • Re-open your shell or terminal emulator.

Keychain will ask you to enter your passphrase once and save it to the ssh-agent. You no longer need to enter your passphrase

Use keychain --stop all to stop all agents. The next time you start bash or your terminal emulator (and effectively keychain) you will be asked to unlock your private key with your passphrase again.

Installation & Configuration for Windows

Because Windows has no stable built-in SSH client we use an open-source tool called PuTTY. It comes bundled with an authentication agent called Pageantwhich works the same way as the OpenSSH SSH agent for Linux and OSX.

  • Install PuTTY by Simon Tathamchoco install putty (Or download and install manually from putty.org)
  • Open it and select Add... to load and unlock your private keys with your passphrases.
  • Use PuTTY like you would normally. It automatically detects the running Pageant authentication agent.

See Also

Modify a battery-powered speaker to be a permanent DC-powered speaker

Modify a battery-powered speaker to be a permanent DC-powered speaker

In my first tech-video I explain how I tranform the JKR KR-1000 – a battery-powered speaker with included charging circuits – to a classic DC-powered speaker, bypassing the battery circuits completely. This allows for permanent use of this speaker without the battery-protection circuits triggering and cutting off the power.

Feedback is greatly appreciated.

Buy the speaker on AliExpress.com // Amazon.de // Amazon.com // Gearbest.com // Ebay.com

(All links are clean search links and don’t bring us any money.)

Portable HDMI Screen Using Your Smartphone

Portable HDMI Screen Using Your Smartphone

When it comes to Raspberry Pies, it’s all fun and games until one of them doesn’t boot anymore. If you are lucky, you can attach your TV or a Computer screen to the HDMI or Composite port and watch the boot messages. My recent routine got a little uncomfortable as I tend to have my devices in a stacking enclosure and cannot carry them to the TV. It now mostly got like this:

  1. Power off the problematic Raspberry Pi
  2. Power off the Hyperion (Ambilight-Clone) Raspberry Pi attached behind the TV
  3. Change the cabling of the TV to output Hyperion’s boot messages.
  4. Swap the SD cards
  5. Power it up and watch the boot messages of the problematic Raspberry Pi’s SD Card in the Hyperion Pi
  6. Write it down
  7. Try to fix it
  8. Swap & repeat

Wow. This takes a lot of time and only works with the same hardware. This was no permanent solution anymore. But where can I get a small HDMI-capable screen, ideally battery-powered and cheap? Everything I found were some DVD-Players with HDMI input, starting at around 100 European bucks or car reverse cameras at 12 Volts with open-ended cables or lighter plugs. Both are weird and too expensive. But wait a second: While Ebaying for these devices I noticed I actually am staring at such a screen right now and it’s even battery-powered!

DIY HDMI Screen

Alright, we can’t have it completely free, but we don’t need a new display-and-battery whatever. Look at this:

Different USB video grabbers
Different USB video grabbers

I recently found a very cheap HDMI USB grabber on Ebay. If you already built an Ambilight clone, you may recognize the hardware on the center and right hand side. They are a combination of a (2) Composite USB Grabber and a (3) HDMI to Composite Converter, which – in combination – resemble a pretty ugly HDMI USB Grabber. The Converter even needs extra power. That’s not a good portable solution. Also the quality of the image sucks, because it is a digital signal converted to 480p analog video and then back to HDMI (still at 480p, because the pixels are lost forever).

There is an (1) All-In-One solution available now. Unfortunately it doesn’t have better specs, but it does not need extra power and is a lot smaller and handier. I took it apart and it uses almost the same circuitry as the combination of (2) and (3). It even converts it down to analog and back to digital, but without the signal loss of the connectors and cables:

USB HDMI grabber disassembled
USB HDMI grabber disassembled

Some of the chips are unmarked. I appreciate any identification hints.

If you don’t use a tablet with an USB A port, you might also need a microUSB to USB A (or USB C to USB A, if you are not using a 2014 phone) adapter. They are very cheap and (at least in the case of Micro-USB) only consist of wire traces without any logic or ICs. Some of mine look like this:

Smartphone, USB OTG Adapter, USB HDMI Grabber
Smartphone, USB OTG Adapter, USB HDMI Grabber
Smartphone, USB OTG Adapter, USB HDMI Grabber
Smartphone, USB OTG Adapter, USB HDMI Grabber
USB OTG Adapter, USB HDMI Grabber plugged into the Smartphone
USB OTG Adapter, USB HDMI Grabber plugged into the Smartphone

 

Fits acceptably. Now we still need a piece of software to view the grabber’s video input. All of my tested grabbers use EasyCap-compatible chipsets. The modules are usually included in the linux-firmware and work with any Video-For-Linux compatible software. If you use an Android smartphone there are multiple apps that work just fine. I chose “USB Camera” by ShenYao China which is free but shows banner advertisements.

Let’s plug in a Raspberry Pi and start it up:

The video quality is pretty bad. I recommend to reduce the default HDMI resolution of the Raspi to something lower to increase readability. After that, and with the pinch-to-zoom functionality of the app, I can now use it for debugging misbehaving hardware without the hassle of disconnecting and moving stuff. Great!

I also switched to this USB HDMI Grabber for my Hyperion-based Ambilight clone. It produces absolutely no green flashes (grabber dropouts) and saves a lot of space behind the TV. Do you have any other applications in mind? Let me know in the comments below!

Links

USB HDMI Grabber

MicroUSB OTG Adapter

Raspberry Pi Docs

Google Play Store Apps

Save your SD cards: Raspberry Pi on a network file system

Save your SD cards: Raspberry Pi on a network file system

If you work a lot with your Raspberry Pi, you probably have burned one or another SD card. While SD flash cards are great for storing photos or music, they suck at being written to very often. This is exactly the case if you run a whole operating system on them. Hundreds of thousands of read and write operations wear your SD cards out and if you do not have a solid backup concept you have probably lost some data, too.

In my home, a couple of systems are running on the cheap, embedded hardware by the Raspberry Pi Foundation because they are both small and power-saving at a very affordable price point. And so are the accessories like cases and add-on-boards. At the time of writing, these are the jobs that are done by my Raspberries:

  • SSH server (as gateway and tunnel from the internet into the LAN)
  • Monitoring
  • OpenHAB smart home controller
  • TV Server
  • Backup
  • Ambilight

 

When living alone, having all this run on SD card-based Raspberries is fine and you know what to do when something breaks. As soon as you have a partner to share your home with, you probably need to agree on an SLA to ensure a high WAF:

SLA (Service Level Agreement):

If you want to have a smart home controlled by a computer, you have a very short acceptable “TTR” if something breaks. Our Time-To-Recover is usually as short as 1 day. Honestly, it is more like same-day. Do not go to sleep until it is fixed.

WAF (Wife Acceptance Factor):

If you stick to the SLA, you are free to do all this crazy stuff; your partner accepts it and maybe even likes it.

 

And that is basically the reason I am writing this. It is completely OK if the ambilight stops working, it is also acceptable if the backups do not run for some days. But if the smart home controller fails, … well, you better have a backup plan. You do not want to deal with someone who spent two hours trying to turn the lights up or the television on and ultimately failed because it simply does not work anymore without the central controlling instance.

So we should reduce these outages to a minimum:

The Objective

  • Increase device uptime / reduce device outages
  • save data on a central storage for easy backups or snapshots

 

There are so many other things that can fail. The processor may overheat and hang, forcing a reboot by the watchdog, the power consumption could be too high and disable the USB bus (including the Ethernet Port), the cheap phone charger you use for powering may fail as well, but the single biggest problem is – without a doubt – the SD card.
So today I am showing you how simple it is to boot and run your Pi completely from the network.

 

The Requirements

  • always-on network storage with NFS server software
  • stable network connection to the storage (wired whenever possible)
  • 16+ MB SD card for the Raspberry Pi bootloader and config file that points to your network storage
    (Note: Starting with the Raspberry Pi 3 there are ways to modify the internal bootloader to boot from network without an SD card. I am not going to cover this here; this method will work with all the Raspberry Pi versions)
  • 3 beers of time

Everything I do is based on a Linux computer (I use Arch Linux and Manjaro) but you can also do this on OS X and maybe on Windows with a lot of tools. I really recommend you to use a Linux computer or a linux VM.

The Network Storage

You need a network storage capable of running an nfs-server. You can even use a Raspberry Pi as sever but that would not really solve the problem here, would it? 😉

Ensure the NFS service is globally enabled

Most commercial NAS systems support NFS and so does my Seagate BlackArmor NAS 4000. I highly recommend to create a seperate share for the filesystems of your Raspberries to be able to add stricter permissions later.

You may need to enable the NFS service first, because a lot of people do not need it and use CIFS only.

Create a share where you will put the filesystems for your Raspis

The resulting config, that my NAS generates, looks like this:

~ $ grep rootfs /etc/exports
/nfs/rootfs *(rw,async,insecure,no_root_squash,no_subtree_check)

Please note that the options rw, no_root_squash and no_subtree_check are obligatory for what we want to achieve. For a detailed description of all possible options, please consult the man page on your system or here.

 

The Extraction Of The SD Card Image Content

You have your NFS Server up and running and configured.

I already stumbled across some distributions of Raspberry Pi SD card images, that depend on and wait for partitions on the local sd card – even if you boot them from NFS. If you see your Raspberry Pi failing at boot, because it waited for a local partition or device for too long, simply flash the sd card image onto that sd card like you would normally. Then, change the settings to have it boot over NFS. Your local SD card still will not be touched, but the boot scripts and dependencies will work now.

This topic can be split into two subtopics: Using a freshly downloaded image to start from scratch, or converting a normal SD-card-based Raspberry Pi to a NFS-based one. Skip to Convert SD-Card-Based Raspberry Pi To NFS if you already have an SD card image, which you want to convert.

 

Create A RootFS From Scratch (New Download)

Now you can download any SD card image like you would do normally. But instead of flashing it onto an SD card, you will mount it and copy the content to your NFS share.

In this example I will download the official Raspberry Pi Foundation Raspbian Stretch Lite Image over the Torrent protocol on my Manjaro Linux machine.

[[email protected] Downloads]$ transmission-cli https://downloads.raspberrypi.org/raspbian_lite_latest.torrent
2017-09-07-raspbian-stretch-lite.zip: State changed from "Incomplete" to "Complete"

Be nice and give something back to the torrent community by leaving this open seeding (uploading) for the other downloaders. Meanwhile in another terminal window:

Check the checksum to check if the data was downloaded successfully and was not modified:

[[email protected] Downloads]$ sha256sum 2017-09-07-raspbian-stretch-lite.zip 
bd2c04b94154c9804cc1f3069d15e984c927b750056dd86b9d86a0ad4be97f12 2017-09-07-raspbian-stretch-lite.zip

The checksum equals the checksum from the website. Great! Let’s unpack it and have a look inside the partition table. It is a complete device image, so it contains everything from (or for) the SD card, including partition table.

[[email protected] Downloads]$ unzip 2017-09-07-raspbian-stretch-lite.zip 
Archive: 2017-09-07-raspbian-stretch-lite.zip
 inflating: 2017-09-07-raspbian-stretch-lite.img
[[email protected] Downloads]$ fdisk -l 2017-09-07-raspbian-stretch-lite.img 
Disk 2017-09-07-raspbian-stretch-lite.img: 1.7 GiB, 1854590976 bytes, 3622248 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
                                ^^^-----<<< write this down! <<<-------
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x11eccc69

Device                           Boot Start  End      Sectors Size Id Type
2017-09-07-raspbian-stretch-lite.img1 8192   93813    85622   41.8M c W95 FAT32 (LBA)
2017-09-07-raspbian-stretch-lite.img2 94208  3622247  3528040 1.7G 83 Linux
                                      ^^^^^-----<<< and this! <<<-------

In the output of fdisk -l you see some important information. As we are not interested in putting the boot partition onto our NFS server (but the rootfs partition, the second partition) instead, we need to know the offset where the interesting partition starts. To get this offset you simply multiply the sector size (usually always 512 bytes) with the start sector of the second partition (both are marked above).

[[email protected] Downloads]$ echo $(( 512 * 94208 ))
48234496

Let’s create a loopback device with this information so we can mount it and steal the data from it.

[[email protected] Downloads]$ sudo losetup -f --show -o $((512*94208)) 2017-09-07-raspbian-stretch-lite.img 
/dev/loop1

You need to be root to create loopback devices. -f found us a free loop device, -o took the offset we calculated and –show made sure we get to know which loop device losetup used. Now we can go and mount it like any other partition.

[[email protected] Downloads]$ mkdir /tmp/fresh-pi-rootfs
[[email protected] Downloads]$ sudo mount -v /dev/loop1 /tmp/fresh-pi-rootfs
mount: /dev/loop1 mounted on /tmp/fresh-pi-rootfs.
[[email protected] Downloads]$ cd /tmp/fresh-pi-rootfs
[[email protected] fresh-pi-rootfs]$ ls
bin boot dev etc home lib lost+found media mnt opt proc root run sbin srv sys tmp usr var

Now let’s copy that data to your NFS share. Refer to the code snippet in Convert SD-Card-Based Raspberry Pi To NFS, but copy from /tmp/fresh-pi-rootfs instead of /.

Afterwards, burn the SD card image to your SD card like you would normally. This ensures that you have the proper boot partition (the first partition in the partition table) on your card. If you feel fancy or have a tiny SD card, you can also extract the partition data like we did above and put it onto a fresh FAT partition on the SD card with the same start sector.

 

Convert SD-Card-Based Raspberry Pi To NFS

If you already have a running Raspberry Pi, you probably do not want to rebuild everything from scratch but move your existing data to the network share. All you need to do is to log into your Pi, install rsync (or any other application that reliably copies filesystem attributes like scp), and copy all your stuff over. Do not forget to stop your applications to have them in a defined (stopped) state.

[email protected] ~ $ mkdir /tmp/rootfs
[email protected] ~ $ mount nas:/nfs/rootfs /tmp/rootfs
[email protected] ~ $ rsync -Phax --numeric-ids / /tmp/rootfs/openhab

There are about 31.000 files to copy, so this might take a while. Go brew some coffee or grab a beer.

 

The Configuration

All your data are belong to the NFS share. The last step is to tell the Raspberry Pi to boot from the share instead of the local SD card. One widespread method that works on almost every linux device is to modify the kernel command line. This is usually done in the bootloader (Syslinux,  Grub, U-Boot). The Raspberry Pi got a configurable U-Boot bootloader starting with version 3. In the versions before you have to have a partition on your SD-Card, containing the boot files and a file called “cmdline.txt” that contains the kernel command line. This also works with Version 3 and newer, if you do not want to bother with U-Boot and you are fine with using an SD card for that.

Modify the “cmdline.txt” file on the boot partition. You can do this directly on your Raspberry Pi, or by plugging the SD card into another computer. When using another computer, you’ll find the file on the first Partition of the card, usually called “boot” partition. When editing the file directly on the Pi, it is located at “/boot/cmdline.txt”.

This is an example cmdline.txt I use in production:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=192.168.21.1:/nfs/rootfs/openhab ip=dhcp elevator=deadline

This is basically the default cmdline.txt with additions of the root, nfsroot and ip options. If you want to define a static IP address, use something like

ip=192.168.21.50::192.168.21.1:255.255.255.0:raspberrypi:eth0:off

(ip=<client-IP-number>::<gateway-IP-number>:<netmask>:<client-hostname>:eth0:off)

Please keep in mind, that there must only be exactly one line in the cmdline.txt file. No comments, nothing else. Just one line.

 

The First Boot

Save it, unmount the boot partition (Apple and Microsoft call this “eject securely” or similar), put the SD card into your Pi and fire it up. If you have a screen attached, you will see the communication with the DHCP server and the handover to the NFS filesystem. This usually takes only a second. My boot time increases by 50% which is most likely the case because of my very old and slow NAS. Results may vary.

Congratulations, you just separated hardware from software resources and made your IT a lot more agile. Now, if your Pi explodes, you can just swap it with a new one from you Raspberry-Pi-drawer and be up again in no time. I am not responsible for exploding Pis, though.

 

The Remaining Questions

People asked me about this a lot so maybe this is interesting for you as well:

Q: Wait! What happens, if my NAS crashes, or is offline in some other way?
A: As soon as the NFS server doesn’t answer anymore, your devices will just stop completely. The root filesystem is essential so your Raspberry Pi will just wait until it is reachable again. It will not crash and it won’t reboot or panic. It just waits until your server is back. I think this is quite nice.

 

If you have any other questions, feel free to ask in the comments section below!

 

Read Also

Wow, another tech blog

Wow, another tech blog

So here we are. A small group of Linux-administering, Raspberry Pi-stacking, Micro-controller-soldering and programming people, that opened up yet another Weblog for the world out there.

After sourcing so much useful information from all those tech bloggers across the planet, we now want to give something back. We hope to help you avoid pitfalls we fell into and provide solutions for problems we struggled with.

We are not sure about the name, nor do we fully know which topics we may share with you. Prepare for a chaotic startup, some unclean redesigns, changing domain names and server downtimes whenever you need us. But it will become nicer, cleaner and more stable. And that is a promise – we are all admins at least, so what could possibly go wrong?

See you soon!

 

via https://www.desktopbackground.org/wallpaper/8-bit-pixel-art-wallpapers-959054