Tuesday, April 9, 2019

Raspberry Pi: SD Card Formatting, Loading and OS Reinstallation in Linux

SD card image for Raspberry Pi, loaded with NOOBS and Raspbian OS
In my previous post [1], I had mentioned a problem that I ran into during my initial installation and setup of the Raspbian OS on my new Raspberry Pi 3B+. 

During the first boot after install, the boot sequence generated error messages related to inability to read data blocks on the SD card, and failed to the Busybox terminal prompt. It required a soft reboot using the sudo reboot -f command to get the system to boot properly. At the time, I decided to put up with the malfunction and the associated nuisance for a few days until I got an intuitive feeling of Raspbian and its environment, after which I intended to perform a wipe and clean format of the SD card and go through the reinstall process again.

I had noticed that a lot of the tutorials online (including on the official Raspberry Pi Foundation) describe the format and setup process for the SD card for users of Windows and Mac, but not as much for Linux users. Being a Linux user, I thought I'd document my experience with the process for those looking for detailed guidance. I should note from the outset that I'm describing the process on an Ubuntu 18.04 Bionic Beaver system, with all the additional support software that comes with the environment.

The key tool for this process is going to be the GNOME Partion Editor application, or GParted as it is known in colloquial reference. GParted is an extremely important and useful tool that makes the creation, management, cleanup and formatting of onboard or attached storage devices easier to handle. It should be noted that it does require superuser privileges to run, though. In Ubunutu 18.04, it can be found from the main UI by pressing the "window" hotkey on the keyboard, or clicking on the "Show Applications" button on the lower left corner of the screen and typing in "GParted" in the search bar that appears.
Finding GParted in the Applications list in Ubuntu 18.04 using the search function.
Clicking on the icon will launch GParted and bring up the main application window. By default, GParted will show the structure, breakdown and composition of the standard storage device, which will usually be the on-board hard disk drive (HDD).

Since the Raspberry Pi uses a microSD card, in order to mount, view the contents and format the card, a microSD card adapter will be required. This is usually supplied with the microSD card if the kit is purchased with NOOBS preinstalled, as shown in the equipment photo below.
Raspberry Pi 3B+ kit photo with equipment breakdown, including SD card adapter with NOOBS
Similarly, the laptop/desktop computer being used will require an SD card slot, or an adapter capable of accepting one. In my case, my System76 laptop came with an SD card slot built in. With the microSD card and adapter plugged in and GParted started up, the SD card was accessed from the top right hand corner.
Contents of the microSD card shown in the GParted main window and terminal after mounting

With this done, the microSD card contents can be seen mounted, on the desktop, command line and the GParted window. The microSD card will usually be mounted under the /media main folder in the user directory. I noticed that the microSD card was mounted and appeared as four separate partitions - boot, root, SETTINGS and System. This is represented in the GParted window as well. There is also an unmounted partition called RECOVERY that contains the recovery system available on startup to recover a damaged installation.

Before the formatting process can begin, the exisiting partitions need to be deleted. This was accomplished through right clicking on the partition in question, and selecting the Delete option.
Option menu to delete, format and unmount partitions on the microSD card in GParted
Once this has been done for each partition, a list of operations to be performed will appear, which can then be approved for action. This will then result in the deletion of the selected partitions and a confirmation report at the end of the process.
Example scenario of applying operations to delete seletcted partitions after unmounting
Applying of deletion operations for selected logical partions on the microSD card
Final confirmation and report dialog at the end of the logical partition deletion process
With all the logical patitions removed, an overview of the microSD card with blank unallocated space should be seen, as shown in the overview and space breakdown dialog as shown below. Note that this is reflected with all partitions removed from the desktop and the directory listing in the terminal as well.
microSD card with all logical partitions deleted, reflected on desktop and terminal
The next step is to format the microSD card, with all parameters specified, including the filesystem type. This begins with the creation of a new partition, spanning the entire unallocated space, with various parameters selected and confirmed. With the partition created, it can be formatted to create a clean microSD card ready for the NOOBS installer to be loaded.
New partition created on microSD card, spanning entire unallocated space
Formatting beginning with the slection of format operation and filesystem type (fat32)

End result of format: new logical volume created and mounted on desktop and Nautilus explorer
 The final stage, which is similar in both Windows, MacOS and Linux, is to load the NOOBS installer which will run during system startup and install the desired OS. This is accomplished by downloading the necessary compressed NOOBS installer file from the Raspberry Pi Foundation's official site.

In this case, I chose to go with the NOOBS Lite installer. This is a smaller download which requires a network connection to perform the installation, but guarantees the latest version of the OS being installed with all updates. The contents of the NOOBS Lite zip file are shown below.
Contents of the NOOBS Lite Installer zip file
 With the NOOBS Lite zip file opened and extracted, the contents need simply to be copied across to the blank microSD card. With that completed, nothing else needed to be done and a clean installer was ready for the OS installation process on the Raspberry Pi 3B+.
Copying contents of NOOBS Lite installer zip file across to formatted microSD card.
 As shown in the final screenshot below, we have a clean, formatted microSD card with the NOOBS Lite installation files shown in the Nautilus file system explorer, and the space occupied as well. The next step was to redo the OS install process that I described in my previous post, and then move on to the really exciting stuff!
Clean formatted 16GB microSD card with NOOBS Lite installer files on board, seen in Nautilus

See you in the next post. If this has helped you, be sociable and please do share!

REFERENCES:
==========
[1] Initial Product Assessment and Startup: Raspberry Pi 3B+

No comments:

Post a Comment