New Raspberry Pis are shipped with powerful computing and faster USB 3.0 ports. It is possible to connect the large-size USB storage drives and share them over the network to create your own file server or NAS. Well, all these are good to know. As thriving technology over time, it gives plenty of storage drive options and several supported formats. In this article, we are going to cover how to partition and format the hard drive on raspberry pi.
Table of Contents
There are more than 100 types of file systems that have developed over the years. We have selected only two main types of file systems. NTFS and EXT4. It is much needed to know as these are very close to the universe.
- NTFS: This file system is developed by Microsoft in the early 90s. All new versions of Windows operating systems will support this file system. Theoretically, NTFS can support hard drives up to just under 16 EB. The individual file size is capped at just under 256 TB, at least in Windows 8 and Windows 10, as well as in some newer Windows Server versions. When it comes to supporting, this file system is universally supported. Although it’s developed by Microsoft, it is supported by most Linux distributions and Mac.
- EXT4: This file system is developed based on the older Minix filesystem, A file system being used by Linux systems for ages. The higher maximum volume size it supports is 1 EB. That’s, again, a mathematical number. I know all these numbers don’t bother you like many of us. After all, who is going to use such a gigantic drive at home with Raspberry Pi!
Prerequisites for partitioning and formatting hard drives on a Raspberry Pi:
- Raspberry Pi hardware: You’ll need a Raspberry Pi device along with associated peripherals like a power supply, SD card, etc. The blog post suggests newer Raspberry Pi models with USB 3.0 ports to connect high-capacity drives.
- External USB hard drives: You’ll need one or more external USB hard drives you want to connect and format to use with your Raspberry Pi. The instructions cover both traditional hard disk drives (HDDs) as well as solid-state drives (SSDs).
- Basics of Linux and the command line: Many of the steps like partitioning, creating filesystems, editing configuration files etc. need familiarity with basic Linux commands and administering the system from the command line interface (CLI). Some prior experience with this would be helpful.
- Administrative privileges: Commands like using parted, creating mount points, editing system files like fstab etc will need you to have administrative (root/sudo) privileges on the Raspberry Pi OS. So you’ll need access to the pi user account or other account with sudo rights.
- Backup any data: As the blog post involves completely wiping any existing partitions and filesystems on the attached USB drives, if you have any data on them already, be sure to have backups available before proceeding. The operations detailed are destructive and will remove previous data.
- Understanding of filesystems: A basic background on common filesystems like NTFS, EXT4 will be helpful to understand the core concepts and select the appropriate ones to create on your external drives.
Let me know if you need any clarification or have additional questions on the prerequisites.
Which File System is Better to Use?
Now you have got some idea of the most popular file systems. The real question is, which format is better for you? The verdict is quite straight here. If you want to connect the storage drive between your Pi and Windows system quite frequently, then you might consider NTFS as your first choice. Because it is supported by most of the windows and non-windows platforms. On the other hand, if you want to stick your drive only with Raspberry Pi, EXT4 would be a better option for you. As it goes well with the Linux system. After all, Raspberry Pi is a custom variant of Debian Linux. We hope this feels you much better in selecting the file system for your file server. Gather up your drive, and let’s get started.
Partitioning and Formatting the Hard Drive on Raspberry Pi:
When you connect a fresh drive that you picked up from the factory. Even though it has nothing on it. It is going to be mounted under /media/pi by default. Again if we remount the drive, it will be mounted again under the same path. This nature is just fine for removable drives. The convention is to mount the drive under /mnt. Let’s see how this work. Note: This is just a demonstration; you may get different results when you try this on your PI and drives; it all depends on the version of hardware and software used.
Time needed: 20 minutes
Partitioning and Formatting the Hard Drive on Raspberry Pi
- Unmount the drive:
Unmount the drive from its current location by hitting the eject button.
- List out the connected drives:
Open the terminal and write the ‘parted’ command to see what drives are connected and how they are partitioned.
$ sudo parted
- Use ‘print all’ to read the drive information:
Type ‘print all’ to see all the drives and their partition Information. If you see the information inside the red box, there are two drives mounted. 120 GB Hard Drive is mounted under /dev/sda with an NTFS file system with a single partition. And, you should see there is an SD card of size 8 GB mounted under /dev/mmcblk0 with two partitions. The first one is the 256 MB boot partition with the FAT32 file system, and the second one is the root EXT4 partition.
(parted) print all
- Select the drive to partition:
Select the drive to format and create new partitions. Type the ‘select’ command with the drive path.
(parted) select /dev/sda
- Create a fresh GPT partition table:
Create a fresh GPT partition table by typing ‘mklabel gpt’ command. You will get a warning to wipe out all your drive. Type ‘yes’ to continue. Please bear in mind, that it’s just a partition table, not the partitions.
(parted) mklabel gpt
- Type ‘print’ to make sure the new GPT partition is created.
- Create new partitions:
For demonstration purposes, we are going to create three partitions on this drive using ‘mkpart’ command: os, data-ntfs, and data-ext4. Later we will show you how to install the Raspberry Pi OS on the hard drive and boot from USB.
Type ‘mkpart’ command to create a new partition. It asks four simple questions to create a partition. Your partition will be created upon supplying the answers. Just pay attention to the commands we used to create three partitions. You can create partitions in a single line command as well, as we show in the below screenshot.
(parted) mkpart data-ntfs ntfs 8gb 50%
(parted) mkpart data-ext4 ext4 50% 100%
- Exit from parted:
All right, everything looks fine. Type ‘q’ to exit from the parted. You can ignore the ‘fstab’ at this point in time. We will look at this in later sessions.
- Format the partitions:
You can’t use the partitions until you format them. Let’s use mkfs commands to format the partitions. Different versions of mkfs commends are there to format NTFS and EXT4 file systems. In this command -L specifies the label of the drive, and -Q specifies quick format, which takes the partition name as a parameter. Note: EXT4 doesn’t take -Q as it doesn’t support the quick format.
$ sudo mkfs.ntfs -L data-ntfs -Q /dev/sda2
$ sudo mkfs.ext4 -L data-ext4 /dev/sda3
- Reboot the Raspberry Pi:
Sometimes, the GUI desktop doesn’t pick this partition information. We recommend rebooting the Pi once.
After reboot, you will see the partitions on your GUI desktop. But, these drives are mounted under /mdia/pi.
- Remount these partitions under /mnt:
To remount these partitions under /mnt.
At first, Unmount the partitions by clicking on their eject button. Refer to the first section to see how to unmount the drive.
Open the terminal and change the directory to /mnt.
$ cd /mnt
Create two directories named ‘data-ntfs’ and ‘data-ext4’ under /mnt.
$ sudo mkdir data-ntfs
$ sudo mkdir data-ext4
Mount the partitions using the mount command. Note: This is just a temp mount. It is not going to work after reboot.
$ sudo mount /dev/sda2 /mnt/data-ntfs
$ sudo mount /dev/sda3 /mnt/data-ext4
Do you remember the fstab? It’s a file system table. This is where you can mount a partition forever. Open the /etc/fstab file and see how it looks. You can only see the SD card at this time.
$ cat /etc/fstab
- Take the PARTUUID value of the two partitions:
You need to add those two partitions to /etc/fstab to mount permanently. Before that, make a note of PARTUUID value of the two partitions.
$ sudo blkid
- Create a permanent mount:
Use your choice of a text editor to edit and add the partition information in the /etc/fstab. You can add the two lines representing each line for a partition. Write this information separated by TAB.
default or default, notime: The word ‘notime’ just tells us to keep track of the access time along with created and modified time.
- Reboot the Raspberry Pi
Reboot to save all the changes and mount the partitions forever. This is how you can partition and format the hard drives on Raspberry Pi
Once the drive is ready to use on the Pi, you can use it locally as extended storage or share it over the network to feel the effect of a personal file server or a NAS. We have shown how to set up a NAS on the Raspberry Pi in a different blog post. Please read the post and leave your comments there.
Thank you for reading this article. Please visit the below links to read more such interesting articles. Peace leave your comments here below and let us know your feedback. This helps us to bring more such articles.
Recommend Products for Raspberry Pi Users
We have some Raspberry Pi accessory recommendations that we think you’ll find useful. These are products we’ve personally selected that we believe are must-haves for any Raspberry Pi owner. Take a moment to look through the list – you can click on any item to view more details or purchase it directly from Amazon. Whether you’re just getting started with your Pi or looking to expand its capabilities, we’re confident you’ll find something helpful among our top picks. Let us know if you have any other questions!
Declaimer: The below products contain affiliate links. We may receive a small commission if you purchase through these links at no additional cost to you. You can read our full affiliate disclosure here.