• Home
  • |
  • Blog
  • |
  • How to Partition And Format the Hard Drives on Raspberry Pi?
Partition and Format the Hard Drives on Raspberry Pi

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.

Filesystem Types:

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.

  1. 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.
  2. 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:

  1. 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.
  2. 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).
  3. 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.
  4. 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.
  5. 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.
  6. 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.
See Also  Step-by-Step Guide to Install Conda on Ubuntu Linux

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

  1. Unmount the drive:

    Unmount the drive from its current location by hitting the eject button.

    Unmounting a drive on raspberry pi

  2. 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

    sudo parted

  3. 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

    Read drive information

  4. 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

    Select the drive

  5. 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

    Create a fresh GPT partition table

  6. Type ‘print’ to make sure the new GPT partition is created.

    (parted) print
    Print GPT partition

  7. 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%
    Create new partitions

  8. 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.

    (parted) q
    Exit parted prompt

  9. 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/sda3Format the partitions on raspberry pi

  10. 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.

  11. 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/fstabfstab in linux

  12. 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
    Take PARTUUID value of the partition

  13. 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.

    Mount path
    File System
    default or default, notime: The word ‘notime’ just tells us to keep track of the access time along with created and modified time.
    0Create entry in fstab

  14. 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

See Also  How to Configure FFmpeg as an Introduction Detection System on Your Ubuntu Desktop?

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.

Read More:

About the author

Arun KL

Arun KL is a cybersecurity professional with 15+ years of experience spanning IT infrastructure, cloud security, vulnerability management, Penetration Testing, security operations, and incident response. He is adept at designing and implementing robust security solutions to safeguard systems and data. Arun holds multiple industry certifications including CCNA, CCNA Security, RHCE, CEH, and AWS Security.

To know more about him, you can visit his profile on LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked

  1. Subject: Raspberry Pi 4 Model B, 4GB; BerryBoot; NVMe SATA SSD (via USB 3.0) – How to partition the SSD for use with BerryBoot and multiple OS-es (Linux distros)?

    Greetings! I'm hoping this tutorial post is not so old that no one will read my comment and be able to help/reply.

    I don't think I'm the only person who wants to attempt (or has attempted) this, but after many Google searches and much time researching, I am no closer to an answer, so I am hoping someone out here can offer assistance and/or the solution.

    My setup: Raspberry Pi 4 Model B, 4GB; Argon ONE v2 case with Argon ONE M.2 Expansion Board (NVME).

    My question: can I boot from USB with BerryBoot installed on my NVMe SATA SSD (connected via USB 3.0) and have multiple Linux distros restricted to ONLY the data partition but have the rest of the SSD as NTFS storage?

    I have successfully made bootable FAT32-formatted micro-SD cards for Raspberry Pi OS 64-bit, BerryBoot, and PINN. I want to be able to boot from and use my NVMe SATA SSD (connected via the USB 3.0 port) with BerryBoot or PINN.

    The problem with BerryBoot and PINN is that when run, they automatically create 2 partitions (boot and data), and I'm guessing that the BOOT partition will not change, and the DATA partition stores the OS-es (Linux distros) the user chooses from the BerryBoot menu.

    So, if I want to use BerryBoot to make the data partition large enough to house my 3-4 distros and not have it "fill remaining space" on the SSD (-OR- have it do that), am I able to re-partition that remaining space so that the end result will be with my USB-bootable SATA SSD:

    Partition 1: BOOT: FAT-formatted with the boot loader and kernel files
    Partition 2: DATA: ext4-formatted for the BerryBoot distros installed
    Partition 3: NTFS for general data

    Is this possible? If so, HOW do I accomplish this? Any assistance, help, and suggestions are most welcomed, so please let me know, and thanks in advance!!

    1. Hey Chris,

      Well, I am not a perfect person to answer your question at this point in time since I have never tried using BerryBoot anytime. However, I can try this for you.

      Let me try answering this to my knowledge. Your answer purely depends on how BerryBoot works. If BerryBoot identifies the multiple partitions on the SSD in the device selection phase, it allows formatting only the data partition. If it works only at the device level and failed to identify the partitions, it format everything on the SSD including NTFS. If so, you can’t use the NTFS for other purposes.

      I would suggest you to plug the SSD upon the creation of partitions. See how BerryBoot identifies your SSD. And, please don’t forget to share your results here. This would help others working on the same thing.

  2. Create permanent mount:
    Use your choice of text editor to edit and add the partition information in the /etc/fstab.


  3. Thank you so much for this – I have wasted days trying to get a pi's ssd shared to windows network.
    Your instructions are perfect, for me anyway.
    Now all is working fin.e

  4. Article states "

    For demonstration purpose, 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."

    Now that I have created the disk and edited the fstab I need to boot from the USB where are the instruction to copy the OS from the Micro SD to the SSD with out loosing the partitions created

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Learn Something New with Free Email subscription

Email is also one of the ways to be in touch with us. Our free subscription plan offers you to receive post updates straight to your inbox.