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, solid state (SSD) drives and for other Raspberry Pi models as well.

Lets install Raspian Lite

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

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.

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.

[sourcecode language=”shell”]sudo raspi-config[/sourcecode]

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.

[sourcecode language=”shell”]sudo apt update
sudo apt upgrade -y
sudo apt dist-upgrade -y
sudo reboot[/sourcecode]

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.

[sourcecode language=”shell”]sudo fdisk -l[/sourcecode]

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.

[sourcecode language=”shell”]sudo fdisk /dev/sda #Use your device here…[/sourcecode]

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.
[sourcecode language=”shell”]sudo mkfs.ext4 /dev/sda1 #Use your drive here.[/sourcecode]

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.

[sourcecode language=”shell”]sudo apt install rsync -y
sudo mount /dev/sda1 /mnt #Use your drive
sudo rsync -axv / /mnt[/sourcecode]

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.

[sourcecode language=”shell”]sudo blkid[/sourcecode]

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.

[sourcecode language=”shell”]sudo nano /boot/cmdline.txt[/sourcecode]

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.

[sourcecode language=”shell”]sudo nano /mnt/etc/fstab[/sourcecode]

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.

[sourcecode language=”shell”]sudo nano /mnt/etc/dphys-swapfile[/sourcecode]

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.

[sourcecode language=”shell”]sudo reboot[/sourcecode]

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

[sourcecode language=”shell”]sudo df[/sourcecode]

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.

[sourcecode language=”shell”]top[/sourcecode]

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.

[sourcecode language=”shell”]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[/sourcecode]

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

[sourcecode language=”shell”]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[/sourcecode]

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

[sourcecode language=”shell”]sudo raspi-config[/sourcecode]

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!