Install Mate Desktop on the Raspberry Pi using an External Hard Drive

by | Nov 15, 2019 | Technology

Now with the introduction of the Raspberry Pi 4 we now have the power to make a desktop computer. In this guide we are going to create a working desktop computer using raspian lite, mate desktop, and optionally, an external hard drive. Once we are finished we should have a working desktop computer fast enough for non heavy computing tasks that runs off our external hard drive.

Because at time of writing the Raspberry Pi 4 doesn’t support USB booting we will need our SD card for the boot sequence, but once running everything will run off of our external hard-drive. Make sure you have everything you need removed from the hard drive as we are going to wipe it for the sole purpose of our desktop.

This will work for regular USB hard drives, and SSD drives as well as other Raspberry Pi models as well.

Lets install Raspian Lite

Lets grab the latest release version of Raspian Lite from here.

https://www.raspberrypi.org/downloads/raspbian/

Once downloaded, write the image to your SD card. If your new to writing images, there is a great cross-platform program called Etcher you can use to write to the SD card. It can be found here.

https://etcher.io/

Once your have written to the SD card, lets insert and start our Raspberry Pi.

Configure Raspian Lite

On first boot, we will need to do some initial configuration on the Raspberry Pi. First we need to log into the system with the following.

User: pi
Pass: raspberry

This will log us in with the default user/pass. Now at the command prompt, enter the following.

sudo raspi-config

Change your default password. (You may want to set your keyboard layout first under localization options)
Configure your network options.
Configure your Localization settings.
Under Interfacing Options, set SSH to be active.

Once complete, select Finish to reboot the system.

Once restarted, lets now login to our Raspberry Pi again using SSH or the console again with

User: pi
Pass: (new password)

Now lets see if there are any updates for Raspian using the following commands.

sudo apt update
sudo apt upgrade -y
sudo apt dist-upgrade -y
sudo reboot

Lets Set up our External Hard Drive

Now lets plug in our external hard drive. Make sure there is nothing you want to keep on it, we are going to wipe it! Lets identify our newly added drive.

sudo fdisk -l

This will give us a list of our current drives. By checking the Disk, we can tell what we are looking at. Disk /dev/mmc…. will be our SD card. There will be two devices listed, these are our two partitions on our SD card. One is for the boot code, with the Type W95 Fat32 partition. The second is for the root operating system with a type listed as Linux.

We should now also see another device listed below. Likely the Disk is /dev/sda but may vary. Look at the size, it should correspond to your external hard drive size. Note this /dev/sda label, we will be using it next when we re-partition the drive.

sudo fdisk /dev/sda #Use your device here...

Press D, and select the partition to delete. Do this for all partitions until you get a No partition is defined yet! message. This means we have cleared all partitions.

Press N for new partition,
Press P for primary,
Press enter to accept default partition number 1,
Press enter again for default start sector,
Press enter once more for default end sector
And finally to remove device signature.
Now press W to write the changes and to exit.

Lets Format our Hard Drive.

Now lets create the ext4 linux file system on newly created partition.

sudo mkfs.ext4 /dev/sda1 #Use your drive here.

This will format our external drive to the ext4 file system.

Lets Move Root to the External Drive

Now that our external drive is ready, lets move everything over to the external drive.

sudo apt install rsync -y
sudo mount /dev/sda1 /mnt #Use your drive
sudo rsync -axv / /mnt

Here we have mounted our external drive to location /mnt, and instructed rsync to copy all files from / (root) to /mnt (our external drive). This will take a little time to copy everything.

Now, lets instruct our Raspberry Pi to run from our external hard drive instead of our SD card. Enter the following command to get the unique ID of our external drive.

sudo blkid

Note the PARTUUID of your /dev/sda1 (your hd) device. It will look like this xxxxxxxx-xx. Once noted, lets instruct our boot code to use this drive as root instead.

sudo nano /boot/cmdline.txt

Once the editor opens, located the PARTUUID, and replace whats there with your hard drives PARTUUID. If your using a spin up external hard drive, add rootdelay=5 to the end of the line as well. This will allow our drive to spin up before attempting to boot from it. Once finished, press CTRL+x, y to confirm saving, and enter to save.

Next we will need to change our root location once again in our fstab file.

sudo nano /mnt/etc/fstab

Locate the line with the PARTUUID=xxxxxxxx-xx / ext4 information, and replace the PARTUUID with your external drives PARTUUID. Once completed, press CTRL+x, y and enter to save the file.

Now we should be ready to boot to our external hard drive. But before we do, lets increase our swap file size. Swap files don’t work well on SD cards or USB sticks, but will work with our Hard Drive. Typically you want to size your swapfile the same size as the amount of ram your system has.

sudo nano /mnt/etc/dphys-swapfile

Scroll down, and set your CONF-SWAPSIZE=512, 1024, or 2048 depending on how much ram you have. Once finished, press CTRL+x, y and press enter.

Now after all our changes, lets reboot our system.

sudo reboot

Once restarted, lets check our root size to see if its our external drive.

sudo df

Our /dev/root should have a size corresponding to our external drive. Next we can check our swapfile size to make sure it adjusted as well.

top

Look for MiB Swap: at the top. It should correspond to our new swapfile size. Press CTRL+c to exit.

Lets Install our Desktop Environment

Now that we are working off our external drive, lets install the packages needed to get our desktop up and running. We will keep it light so you can add what you would like.

sudo apt install mate-desktop --no-install-recommends
sudo apt install mate-desktop-environment-core
sudo apt install mate-themes
sudo apt install mate-session-manager
sudo apt install xinit
sudo apt install mate-terminal 
sudo apt install mate-applets
sudo apt install pluma
sudo apt install software-properties-gtk
sudo apt install xserver-xorg
sudo apt install lightdm

That will get our desktop installed. Now we can install some additional software if we like.

sudo apt install mate-tweak #Mate desktop tweak tool.
sudo apt install engrampa #Archive manager for Mate Desktop
sudo apt install galculator #Calculator
sudo apt install gucharmap #Font browser and unicode picker
sudo apt install mate-utils #Mate desktop utilities.
sudo apt install mate-power-manager #Mate power manager
sudo apt install mate-system-monitor #Mate system monitor
sudo apt install mate-screensaver #Mate Screensaver
sudo apt install system-config-printer #Printer software
sudo apt install chromium-browser #Chromium Browser
sudo apt install firefox-esr #Firefox browser
sudo apt install libreoffice #Libre Office Suite
sudo apt install vlc #VLC Media player

Once finished, lets instruct our Raspberry Pi to boot to desktop.

sudo raspi-config

Select 3 Boot Options, B1 Desktop / CLI, and select either B3 Desktop, or B4 Desktop Autologin, whichever you prefer. Now select finish and allow your Raspberry Pi to boot to desktop.

All finished!

Now when you have rebooted, you should go directly into your Mate Desktop. A simple setup, but a good start for you to customize and configure as you like. Now you can add software and customize as you like!

If you found this guide helpful please leave me some encouragement below in the comments! If your really happy, you can always gift me a coffee, I can never say no to coffee!

I have also by request added a bitcoin donation address. If you want to show your appreciation I would be grateful, but under no means do you need to feel obligated. This is a fun hobby for me. 🙂

BTC: 1GzagpXcAkELhU5emJFMLZpp7J5ayfcNQF

And for those that have, thank you for enabling my addiction! You all know who you are!