Samat Says (Posts about Raspberry Pi)https://blog.samat.org/tag/raspberry-pi.atom2018-06-29T09:25:27ZSamat K JainNikolaSlimming an existing Raspbian installhttps://blog.samat.org/2015/02/05/slimming-an-existing-raspbian-install/2015-02-05T00:00:00Z2015-02-05T00:00:00ZSamat K Jain<div><p><a class="reference external" href="http://www.raspbian.org/">Raspbian</a> is the definitive full-featured Linux distribution for the
<a class="reference external" href="http://www.raspberrypi.org/">Raspberry Pi</a>.
As it is tailored for educational use, there is a lot of software that is unnecessary (i.e. bloat) if you intend to use your Pi headless.</p>
<p>While various slimmed down Linux distributions exist for the Raspberry Pi, what if you want to slim down an existing Raspbian install?</p>
<p>I encountered this problem when I hosted a Raspberry Pi with <a class="reference external" href="http://raspberrycolocation.com/">Raspberry Pi
Colocation</a> from <a class="reference external" href="https://www.pcextreme.nl/en">PCextreme</a>. You'll get a Raspberry Pi with stock Raspbian,
complete with X11 and a bunch of other software unnecessary for use in a
datacenter.</p>
<p>Based on the <a class="reference external" href="https://github.com/RPi-Distro/spindle">official Raspbian build scripts</a> (previously <a class="reference external" href="https://github.com/asb/spindle">asb/spindle</a>), you can copy and paste the commands below to uninstall all the extra educational and GUI packages:</p>
<script src="https://gist.github.com/4dda24e14a5b73481e2a.js"></script><noscript><pre class="literal-block">
#!/bin/bash
# GUI-related packages
pkgs="
xserver-xorg-video-fbdev
xserver-xorg xinit
gstreamer1.0-x gstreamer1.0-omx gstreamer1.0-plugins-base
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-alsa
gstreamer1.0-libav
epiphany-browser
lxde lxtask menu-xdg gksu
xserver-xorg-video-fbturbo
xpdf gtk2-engines alsa-utils
netsurf-gtk zenity
desktop-base lxpolkit
weston
omxplayer
raspberrypi-artwork
lightdm gnome-themes-standard-data gnome-icon-theme
qt50-snapshot qt50-quick-particle-examples
"
# Edu-related packages
pkgs="$pkgs
idle python3-pygame python-pygame python-tk
idle3 python3-tk
python3-rpi.gpio
python-serial python3-serial
python-picamera python3-picamera
python3-pygame python-pygame python-tk
python3-tk
debian-reference-en dillo x2x
scratch nuscratch
timidity
smartsim penguinspuzzle
pistore
sonic-pi
python3-numpy
python3-pifacecommon python3-pifacedigitalio python3-pifacedigital-scratch-handler python-pifacecommon python-pifacedigitalio
oracle-java8-jdk
minecraft-pi python-minecraftpi
wolfram-engine
"
# Because of of https://github.com/RPi-Distro/raspberrypi-ui-mods/issues/2 (thanks @robertely)
echo apt-get -y remove raspberrypi-ui-mods
# Remove packages
for i in $pkgs; do
echo apt-get -y remove --purge $i
done
# Remove automatically installed dependency packages
echo apt-get -y autoremove
# Remove all packages marked rc (thanks @symm)
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs dpkg --purge
</pre>
</noscript><p>The above snippet is <a class="reference external" href="https://gist.github.com/samatjain/4dda24e14a5b73481e2a">available in Github as a gist</a>—I'll keep it up to date, and feel free to fork it and add/remove whatever other packages you find necessary.</p>
<p>Download and run it with:</p>
<pre class="code sh"><a name="rest_code_77f873d4db4347b28c2294d51be0cb7e-1"></a>sudo cp /etc/network/interfaces /etc/network/interfaces.bak
<a name="rest_code_77f873d4db4347b28c2294d51be0cb7e-2"></a>wget https://gist.githubusercontent.com/samatjain/4dda24e14a5b73481e2a/raw/5d9bac8ec40b94833b4e9938121945be252fdee1/Slim-Raspbian.sh -O Slim-Raspbian.sh
<a name="rest_code_77f873d4db4347b28c2294d51be0cb7e-3"></a>sh ./Slim-Raspbian.sh <span class="p">|</span> sudo sh
</pre><p>The above backups up <tt class="docutils literal">/etc/network/interfaces</tt> in case it's deleted (see comments).</p>
<p>Coming soon: how to create your own Raspbian image!</p>
<p>UPDATE [19 Aug 2015]: <a class="reference external" href="https://github.com/robertely">Robert Ely</a> pointed out that purging raspberrypi-ui-mods will delete your network config—I've updated the gist so this package is only removed, not purged. I've also added a line from <a class="reference external" href="https://gist.github.com/symm">Gareth Jones</a> that will remove the configuration files for packages no longer installed.</p>
<p>UPDATE [06 Jan 2015]: Raspbian now offers a <a class="reference external" href="https://www.raspberrypi.org/downloads/raspbian/">"lite" image</a> that won't include a lot of this bloat. If you're setting up a new Raspberry Pi, consider using that image.</p></div>Realtek 8188eu-based Wi-Fi adapters on the Raspberry Pihttps://blog.samat.org/2014/12/15/realtek-8188eu-based-wi-fi-adapters-on-the-raspberry-pi/2014-12-15T00:00:00Z2014-12-15T00:00:00ZSamat K Jain<div><p>NOTE: If you're using Raspbian 2015.01 or later, the Raspberry Pi kernel 3.18 now includes this driver—you don't need to compile anything and this tutorial is now irrelevant!</p>
<p>Raspberry Pi enthusiasts like to use Realtek 8188eu-based Wi-Fi adapters.
Known as "micro" Wi-Fi adapters, they are small and inexpensive.
For example, the <a href="http://www.amazon.com/gp/product/B008IFXQFU/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B008IFXQFU&linkCode=as2&tag=samatjainsper-20&linkId=OEF32Q3XV6SSLWYJ">TP-LINK WN725N V2</a> can be found for under $20
(the V1 and V3 use different chipsets.
Thanks for making everything confusing, TP-LINK!).</p>
<p>As of October 2014 and Linux 3.12.29+, the driver for this Wi-Fi adapter isn't available in the Raspberry Pi Linux kernel, so these Wi-Fi adapters are not supported out-of-the-box, despite otherwise you may find on the Internet.
Definitely, they don't work in a plug-and-play manner. </p>
<p>You can get these adapters to work by using an out-of-tree driver (i.e. a driver not included with the Linux kernel).
People on the Internet have resorted to doing all these silly things like <a href="http://www.raspberrypi.org/forums/viewtopic.php?p=462982">downloading random kernel modules</a> or <a href="http://www.raspberrypi.org/forums/viewtopic.php?f=26&t=29752">compiling the vendor Linux kernel trees from scratch</a> trying to get this driver to work. You're probably reading this article because you, like me, thought it was silly to chase files around on some random Internet forum.</p>
<p>The <a href="https://github.com/lwfinger/rtl8188eu">source code for the 8188eu driver</a> is available on GitHub.
Rather than trying to look for random files and hope they work, you can keep the source for the module on your Raspberry Pi and recompile the module as needed.
Below are copy-and-pastable instructions to do this on Raspbian.</p>
<p>Make sure you have a compiler, etc installed.</p>
<pre class="code literal-block"><span></span>sudo apt-get install build-essential git
</pre>
<p>Download the source code for the driver. I prefer to put source code for stuff like this somewhere convenient in my home directory, like ~/src/drivers/.</p>
<pre class="code literal-block"><span></span>mkdir ~/src/drivers
cd ~/src/drivers/
git clone https://github.com/lwfinger/rtl8188eu.git
</pre>
<p>Now you have the source code for the driver, you need to get the source code for the kernel running on the Raspberry Pi. <a href="http://elinux.org/RPi_Kernel_Compilation">Finding the source code for the currently-running kernel on the Raspberry Pi can be a pain.</a> I like to use Hexxeh's rpi-source tool, which you can download, install, and run:</p>
<pre class="code literal-block"><span></span>sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/local/bin/rpi-source && sudo chmod +x /usr/local/bin/rpi-source && /usr/local/bin/rpi-source -q --tag-update
sudo rpi-source
</pre>
<p>If you get an error about GCC, use the "skip-gcc" flag:</p>
<pre class="code literal-block"><span></span>sudo rpi-source --skip-gcc
</pre>
<p>Now, compile the driver:</p>
<pre class="code literal-block"><span></span>cd ~/src/drivers/rtl8188eu
sudo make all
sudo make install
</pre>
<p>Your Wi-Fi should be working, though you'll need to configure it (configuring it is out of scope for this article).</p>
<p>You can double check whether the adapter is recognized by looking at the output of (assuming you've only one Wi-Fi adapter, it will be named wlan0):</p>
<pre class="code literal-block"><span></span>sudo iwconfig wlan0
</pre>
<p>If you see nothing, the driver may have been installed wrong or your Wi-Fi adapter not working.
If you see something like:</p>
<pre class="code literal-block"><span></span>wlan0 unassociated Nickname:"<WIFI@REALTEK>"
Mode:Master Frequency=2.412 GHz Access Point: E8:DE:27:9E:65:D7
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Power Management:off
Link Quality=0/100 Signal level=0 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
</pre>
<p>Then you are good to go!</p>
<p>All of this seemed like a lot of work compared to hunting down the file, right?
Except, it isn't: when you update the kernel on your Raspberry Pi and reboot, the Wi-Fi will stop working because it will no longer have an appropriate driver.
Rather than having to go on a witch hunt for files, you can simply recompile the driver again while offline:</p>
<pre class="code literal-block"><span></span>cd ~/src/drivers/rtl8188eu
git pull # Run this if you have Internet access even though your Wi-Fi is down
make all
sudo make install
</pre>
<p>The above is all you need to turn your Raspberry Pi into a working Wi-Fi client.</p>
<p>If you want to use your shiny new Wi-Fi enabled Raspberry Pi as an access point, there's a gotcha with Realtek Wi-Fi adapters (I've found this true of both the 8188eu and 8192cu chips): they won't work with hostapd as included with Raspbian or Arch Linux.
You'll need to use a custom hostapd, such as <a href="http://jenssegers.be/blog/43/Realtek-RTL8188-based-access-point-on-Raspberry-Pi">this one posted by Jens Segers</a>, to get a working access point.</p></div>