• 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 of the 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 as like many of us. after all, who is going to use such a gigantic drive at home with Raspberry Pi!

Which File System Is Better To Use?

Now you have got some idea on the most popular file systems. The real question is which formats 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 does 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 it’s current location by hitting eject button.

    Unmounting a drive on raspberry pi

  2. List out the connected drives:

    Open the terminal and write ‘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 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 to create new partitions. Type ‘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, 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 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.

    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 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, GUI desktop doesn’t pick this partition information. We recommand to reboot the Pi once.
    After reboot you would 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 the first section to see how to unmount the drive.
    Open the terminal and change the directory to /mnt.
    $ cd /mnt

    Create two directory named ‘data-ntfs’ and ‘datta-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 PARTUUID value of the two partitions:

    You need to add those two partition 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 permanent mount:

    Use your choice of 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. 

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

  14. Reboot the Raspberry Pi

    Reboot to save all the changes and mount the partitions for 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 on 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.

About the author

Arun KL

To know more about me. Follow me on LinkedIn Hi All, I am Arun KL, an IT Security Professional. Founder of “thesecmaster.com”. Enthusiast, Security Blogger, Technical Writer, Editor, Author at TheSecMaster. To know more about me. Follow me on LinkedIn

Leave a Reply

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

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