The Raspberry Pi is extremely hacker friendly which makes it a hackers best friend. It also means it is extremely easy to hack both the hardware and the software. In this post I will be talking about hacking an Ubuntu-Mate Raspberry Pi image.
Hacking can mean many things depending on how it is used in the world of tech. In this post when I refer to hacking I mean modifying the way something to work other than it’s original intention.
Why Ubuntu Mate?
There are several images available for the Raspberry Pi. But all of them seem to be built using modified Debian based systems. Since Ubuntu is created by Canonical and is used by NASA and Amazon. It is a system that has a huge community, less bugs, a big name and so on. Since we will be modifying the image to make our own Operating System it makes sense to use Ubuntu.
In order to start hacking the Ubuntu Mate Raspberry Pi image we will need a few things. They will be listed below.
- Raspberry Pi
- A Power Source to Power The Pi
- An Output Device (TV Works Fine As Long As You Can Hook The Pi To It)
- USB or Bluetooth Keyboard and Mouse
- 8GB Plus Micro SD Card (Preferably One That is Recomended For Use with Raspberry Pi)
- A Computer
- The Ubuntu Mate Raspberry Pi Disk Image (Currently I’m using the version 16.04 image)
- A Fully Functional Brain (I’m using Linux and if your using Linux then it is very important you have common sense. Preparing The Image to hack can wipe your Linux System out if your not careful)
If you have all of the above already. Then you can get started preparing the image to hack.
If your using a mainstream Linux Distrobution with the Gnome Desktop Envirnment, chances are you will have the following packages preinstalled on your system.
- Gnome Disks Utility
- Image Writer
- Nautilus Image Writer Plugin
The above packages allow us to use our mouse and simply click our way through the process of burning our image to an SD Card.
First Lets Open Up Gnome Disks Utility And locate the SD Card
Navigate to the location of our image file.
Right Click On The File
Choose Open With Disk Image Writer
Select The Location Write The Image To. Be careful and be sure to write the image to the correct location.
Click Start Restoring. You may be told that your SD Card will appear to be smaller after the process is finished. You will then be prompted to enter your password.
Wait until it is finished writing the image and your done. However before removing the SD Card I always like to be safe and open my terminal up and type the following command.
And to remove the SD Card simply right click on the SD Card and choose Safely Remove Device. Then you can yank the card out of your computer and pop it into the Raspberry Pi.
Note: I’m almost certain KDE, Mate and other Desktop envirenments have their own disk tools as well. But since I use Gnome I will write about that. The process should be similar for other desktop environments. If you can’t figure out how to do it graphically the generic method is from the Terminal by using commands.
Command Line Method
To do this we first need to burn the image to the Micro SD Card. To do this we will type the following command in our Terminal on Linux.
The above command will output something like the following.
fdisk: cannot open /dev/sda: Permission denied fdisk: cannot open /dev/mapper/fedora-root: Permission denied fdisk: cannot open /dev/mapper/fedora-swap: Permission denied fdisk: cannot open /dev/mapper/fedora-home: Permission denied
Keep in mind the output might be slightly different then the above.
Next we will stick our SD Card into our computer. Then we will type the fdisk -l command again. This time we will see a new line.
fdisk: cannot open /dev/sda: Permission denied fdisk: cannot open /dev/mapper/fedora-root: Permission denied fdisk: cannot open /dev/mapper/fedora-swap: Permission denied fdisk: cannot open /dev/mapper/fedora-home: Permission denied fdisk: cannot open /dev/mmcblk0: Permission denied
The new line is our SD Card. Take note of it. In the above output our SD Card is /dev/mmcblk0. Since we now know the name of our SD Card we can burn the image to it. To do this we will type the following.
sudo dd if=/location/of/your/ubuntu-mate-image.img of=/dev/mmcblk0 bs=1M conv=fsync
If you did it correctly nothing will appear to be happening in the terminal for about 15 minutes. Simply wait, if everything goes as planned you will be able to type a command again shortly. If you get a message then you did something wrong.
Once the image has been written we will type the following commands.
sync umount /dev/mmcblk0
Now we will remove the SD Card from the computer, and place it into our Raspberry Pi and power the pi up.
Raspberry Pi Time
Once the pi has been powered up, we will get to the Ubuntu Mate Setup Screen. Here we will follow all the instructions. After we have finished following all of the instructions on the setup screen Ubuntu Mate will restart and you can start to use it.
Note: If we are making an OS image for redistribution then we will be making a very easy password and a very common username that we will be giving to everyone we distribute the image to. And we will encourage them to change the password after they burn the image.
Hack The Config File
First things first lets modify our config.txt file to display on the screen in a manner we like. To do this we will open up the terminal on our Ubuntu Mate Raspberry Pi OS. And type the following.
cd /boot sudo nano -w config.txt
In this file we can change screen settings. Lets change the resolution. To do this we scroll down to line 297 where we will see the following.
We will remove the # and change 0 to a different number. So it will look something like the following.
To determine the appropriate number we can scroll up a short way and see a list of different numbers and settings in the text file. It will look something like the following.
## Value hdmi_group=CEA hdmi_group=DMT ## ------------------------------------------------------------------------- ## 1 VGA 640x350 85Hz ## 2 480p 60Hz 640x400 85Hz ## 3 480p 60Hz H 720x400 85Hz ## 4 720p 60Hz 640x480 60Hz ## 5 1080i 60Hz 640x480 72Hz ## 6 480i 60Hz 640x480 75Hz ## 7 480i 60Hz H 640x480 85Hz ## 8 240p 60Hz 800x600 56Hz ## 9 240p 60Hz H 800x600 60Hz ## 10 480i 60Hz 4x 800x600 72Hz ## 11 480i 60Hz 4x H 800x600 75Hz ## 12 240p 60Hz 4x 800x600 85Hz ## 13 240p 60Hz 4x H 800x600 120Hz ## 14 480p 60Hz 2x 848x480 60Hz ## 15 480p 60Hz 2x H 1024x768 43Hz DO NOT USE
Now we will save our changes. And then we will type the following into our terminal.
Our Raspberry Pi will now reboot. Once it starts up again, we will observe our screen. If we see an ugly black border around the screen we will open up our config file again. And located the lines that say the following.
#overscan_left=0 #overscan_right=0 #overscan_top=0 #overscan_bottom=0
We will remove the # on them so they will appear like the following.
overscan_left=0 overscan_right=0 overscan_top=0 overscan_bottom=0
And using our eye balls to determine how many pixels the borders are we will change the overscan settings. Like so.
overscan_left=-10 #Assuming the left border appears to be 10 pixels in length overscan_right=-20 #Assuming the right border appears to be 20 pixels in length overscan_top=10 #Assuming the top border appears to #not have a border but runs off #about 10 pixels in length overscan_bottom=0 #Assuming the bottom #border is just fine as it is.
Save the changes to the file and then reboot the Raspberry Pi to see the changes.
Update The System
Lets open up the terminal and type the following.
sudo apt-get update
We will be asked to type our password. So we type it in and press enter.
Now we type the following.
sudo apt-get upgrade
If it ask you to type your password in then type it press enter. Then it will ask you if your sure you want to apply the updates. Type y then press enter. Now we just wait for the upgrade to finish.
Change Firefox’s Useragent
Pardon my upcoming rant. But one thing that annoys me about every single Raspberry Pi OS image that I have tried is the way their browsers display images. On my television and my small 3.5 inch screen the way the browsers display websites is in the full desktop view. Which looks fine on a laptop or a full sized monitor but not on my 24 inch CRT TV or my 3.5 inch HDMI screen. Lets change the firefox useragent to be a mobile useragent.
To change the firefox useragent string. We will need to navigate to the /etc/firefox directory and we will see the two following.
- syspref.js (File)
- pref (Directory)
Lets open the syspref.js file as root and add the following line.
pref("general.useragent.override","Mozilla/5.0 (Android 7.0; Mobile; rv:51.0) Gecko/51.0 Firefox/51.0");
Now when we start Firefox pages will appear the same way they appear on an Android tablet or Android Phone.
Removing Junk Software
Ubuntu Mate along with practically every other operating system ships with programs we will never use. Very rarely do we ever use every program that ships with our systems. In this case they are sitting there untouched and taking up valuable disk space. Lets remove those programs. To do this we open up our Terminal and type the following.
sudo apt-get remove program-name -y
Lets assume we want to install a program that is already online in the Ubuntu Repositories. In this example we will install filezilla. To do this we will type the following into our terminal.
sudo apt-get install filezilla -y
If we’re satified with our system changes, and we want others to try out our new system. We can make the system into an image and share the image with people. To do this we will do the following.
Shutdown the raspberry pi by typing the following into our terminal.
shutdown -h now
Remove the power source from the Raspberry Pi. Now we remove the Micro SD Card and insert it into our computer. Once it is inserted into our computer we will make an image of the Micro SD Card. To do this we will type the following commands.
sudo dd if=/dev/mmcblk0 of=our-os-image-name.img bs=1M conv=fsync
The above command will create an image file on your computer. Simply give the image file to anyone you want to try your newly modified system. And enjoy.