<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Datum</title>
    <description>The latest articles on DEV Community by Datum (@datum).</description>
    <link>https://dev.to/datum</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F441405%2F7b6309fe-61e8-4fa9-861c-fcfd77a43625.png</url>
      <title>DEV Community: Datum</title>
      <link>https://dev.to/datum</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/datum"/>
    <language>en</language>
    <item>
      <title>My first (headless) server for less than £60</title>
      <dc:creator>Datum</dc:creator>
      <pubDate>Mon, 25 Apr 2022 19:44:54 +0000</pubDate>
      <link>https://dev.to/datum/my-first-headless-server-for-less-than-ps60-4ek4</link>
      <guid>https://dev.to/datum/my-first-headless-server-for-less-than-ps60-4ek4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I can't speak for everyone, but the idea of having a local server has been a small dream of mine since I started programing. It took me a while before convincing myself it would be worth it and eventually I started looking at my options.&lt;/p&gt;

&lt;p&gt;I explored the idea of purchasing a pre-made server, but, &lt;br&gt;
there were a few problems for me. &lt;/p&gt;

&lt;p&gt;Firstly, the expense. I wanted to spend as little as I could on the very basics for my server. This would allow me to get a feel for owning a server, and decide if I wanted to invest more money and time into this project later down the line.&lt;/p&gt;

&lt;p&gt;Secondly, an excuse to learn more. I'm an enthusiast when it comes to knowing the details of a system, especially ones I intend to build upon.&lt;/p&gt;

&lt;p&gt;For these reasons, I wanted to have as much control over my server as I could, and an excuse to build it from the ground up (sort of) was just too perfect an opportunity to pass up.&lt;/p&gt;
&lt;h2&gt;
  
  
  The hardware
&lt;/h2&gt;

&lt;p&gt;There are two things I needed to create my server:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Hardware&lt;/th&gt;
&lt;th&gt;Price&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://www.amazon.co.uk/gp/product/B07TGBLK33/ref=ppx_yo_dt_b_asin_title_o01_s02?ie=UTF8&amp;amp;psc=1"&gt;A raspberry pi 4 model B&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£45.50&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://www.amazon.co.uk/gp/product/B073JYC4XM/ref=ppx_yo_dt_b_asin_title_o01_s01?ie=UTF8&amp;amp;psc=1"&gt;128GB SD card&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;£13.99&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://www.amazon.co.uk/gp/product/B07XCKNM8J/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&amp;amp;psc=1"&gt;Raspberry Pi Case&lt;/a&gt; [Optional]&lt;/td&gt;
&lt;td&gt;£10.99&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The first thing I want to point out is that you can save some money here if you choose an SD card with smaller memory, or a different raspberry pi.&lt;br&gt;
The second is that although I've bought a raspberry pi, I'm not limited to using the raspberry OS(s).&lt;/p&gt;
&lt;h2&gt;
  
  
  The software
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AOMEI Partition Assistant - To format the SD card to FAT32&lt;/li&gt;
&lt;li&gt;Raspberry Pi Imager - To load the OS's image onto the SD card&lt;/li&gt;
&lt;li&gt;Fing - An App for your mobile which tells you the IP addresses of devices connected to your LAN&lt;/li&gt;
&lt;li&gt;PuTTY - To access the Rasberry Pi via ssh &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  The approach
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Formatting
&lt;/h3&gt;

&lt;p&gt;Firstly, I had to check the formatting of my SD card. Turns out it was formatted using "exfat", which isn't the formatting I need. So, using AOMEI Partition assistant, I inserted the SD card into my PC, and selected it for formatting. I tried to format it with FAT32, however, the formatting kept failing and the error code gave an example of "bad sectors".&lt;/p&gt;

&lt;p&gt;I wasn't convinced this was the actual error and so I tried to format my SD card using Windows built-in formatter, knowing it would fail because it can only handle 32GB of memory. But, as I hoped, it gave me a much more reasonable error. The SD card was locked and thus had write protection enabled.&lt;/p&gt;

&lt;p&gt;The steps I used to resolve this were:&lt;br&gt;
&lt;code&gt;Press: &amp;lt;Windows Key&amp;gt; + r&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Type: 'cmd'&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Type: 'diskpart'&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Type: 'disk list'&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Type: 'select disk &amp;lt;number associated to SD card&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Any operation after this point will only apply to the selected disk&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Type: 'attr disk clear readonly'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Great, now we have a writeable SD card, we can continue with the formatting.&lt;/p&gt;

&lt;p&gt;After selecting the partition of my SD card I wanted to format, I simply had to choose the type of formatting, FAT32, and apply it to the partition.&lt;/p&gt;
&lt;h3&gt;
  
  
  Operating system
&lt;/h3&gt;

&lt;p&gt;Now the choice of OS. As I am starting out, I decided to go with &lt;a href="https://www.raspberrypi.org/software/operating-systems/"&gt;Raspberry Pi OS Lite&lt;/a&gt;, knowing that I can always change it in the future if I wish. Lite uses 423MB of storage, which is significatly less than most distributions I was looking at, and is perfect for a headless server.&lt;/p&gt;

&lt;p&gt;Using the Raspberry Pi imager, I was able to run and select both the SD card and the Lite OS without needing to download the OS's image separately - always a win in my mind.&lt;/p&gt;

&lt;p&gt;Once that had finished I could go into my SD's directory and see what had been installed.&lt;/p&gt;
&lt;h3&gt;
  
  
  Wireless connection config
&lt;/h3&gt;

&lt;p&gt;Follwing the guide on &lt;a href="https://www.raspberrypi.org/documentation/configuration/wireless/headless.md"&gt;www.raspberrypi.org&lt;/a&gt;, I added a wpa_supplicant.conf file to the boot partition/folder that the Raspberry Pi Imager had just created.&lt;/p&gt;

&lt;p&gt;Now I had created the file, I opened it using Notepad++ (but sublime text would work also). Inside the file I typed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
 ssid="Wireless LAN Name"
 psk="Wireless LAN Password"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason I used Notepad++ was because I read a lot of posts saying that Windows Notepad wasn't using the correct "New Line"//'\n' ASCII formatting, which would cause problems when booting up the server. &lt;/p&gt;

&lt;p&gt;Although I did read a few articles saying this had been patched, to avoid risk, I went ahead and downloaded Notepad++, wrote the file and then uninstalled it. Not because I don't like Notepad++, but I'll likely be using Vim as my go to editor from now on.&lt;/p&gt;

&lt;h3&gt;
  
  
  SSH connection
&lt;/h3&gt;

&lt;p&gt;Finally, we just need to tell the server to allow an ssh connection. To do this, I followed &lt;a href="https://www.raspberrypi.org/documentation/remote-access/ssh/"&gt;these instructions&lt;/a&gt;, which says to simply add a file called ssh (with either no extension or using a .txt will work). The contents of the file don't matter either, so I left mine empty.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final bits
&lt;/h3&gt;

&lt;p&gt;I went ahead and downloaded Fing on my phone. While it was downloading I plugged in my Raspberry Pi with the SD card inserted, and waited 2 minutes for it to boot just to be sure it would have time to boot, and load etc.&lt;/p&gt;

&lt;p&gt;Once 2 minutes had passed, I refreshed the search for local devices on the Fing app and conveniently found a device with a name "raspberry pi". Alongside the name of the device was the IP address.&lt;/p&gt;

&lt;p&gt;I copied the IP address into PuTTY's hostname field, created a session for my raspberry pi and connected to my brand new server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error handling
&lt;/h2&gt;

&lt;p&gt;You might notice, that sometimes updating the wpa_supplicant.conf doesn't always work. This can be for a few reasons, most are painful to figure out. So if updating the wpa_supplicant.conf file doesn't work - and you've waited at least 2 mins - you can do the following steps to help debug why and set up your wireless connection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# install the network manager CLI&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;network-manager

&lt;span class="c"&gt;# start the manager&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start NetworkManager.service
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;NetworkManager.service

&lt;span class="c"&gt;# connect to the wifi&lt;/span&gt;
nmcli d wifi connect &amp;lt;SSID&amp;gt; password &amp;lt;PASSWORD&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This was a great experience for me, and one which I am thrilled I managed to complete. There were moments where I worried I had wasted my money, or chose the wrong PI for the job. But now my server sits on my desk, happily storing some basic programs and I have no doubt I will be upgrading it again in the future.&lt;/p&gt;

&lt;p&gt;Have a good one!&lt;/p&gt;

&lt;h2&gt;
  
  
  Credit
&lt;/h2&gt;

&lt;p&gt;&lt;span&gt;Cover photo by &lt;a href="https://unsplash.com/@harrisonbroadbent?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Harrison Broadbent&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/raspberry-pi?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>raspberrypi</category>
      <category>productivity</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
