Linux · Raspberry Pi

Mounting an external disk using ext3/4 on Raspberry Pi


When we buy a disk from the market, be it a pen drive or a hard disk dive, which are meant to be used as a portable disk, usually comes with msdos file system. In this tutorial, we shall learn how to mount such a disk as a permanent storage. A storage mounted on a specific location on system boot. We used Raspbian as the OS for this tutorial.

If you wanna mount an external drive as it comes out of the box without formatting and keep it compatible with your windows system you can use this article.

1. Listing available disk with lsblk:

First of all once the usb disk is attached to the raspberry Pi. log into the terminal and run the following command to identify the disk. You may identify it with the disk label or the size:

sudo lsblk -f -o NAME,LABEL,SIZE,UUID,MOUNTPOINT

Output:

image

Above command shall list all the attached block device. In this case you can identify the disk looking as the disk label or the disk size.

Alternatively

However the next command shall allow you to see all the disk connected visa USB. Assuming, you dont have more then 4 external disk connected to the Raspberry Pi.

sudo fdisk /dev/sd[abcd] –l

Once we have identified the disk we want to use, we shall run fdisk that drive using the following command. In this case it is “/dev/sda” a 250gb usb drive.

2. Creating a Linux partition on your external usb storage:

Once we have identified the newly attached disk, we shall crate an ext4 partition in place of the existing one. We can just re-label it, however if we have multiple partition, we shall need to delete the old one and re-create the new one and set the partition type to Linux .

Use the following command to delete the old partition and create the new one with partition type of linux

sudo fdisk /dev/sda

image

pressing “d” inside fdisk the command line shall delete only partition /dev/sda1. Is there are multiple partition, it shall prompt for the number of the partition.

Once deleted you may create a new partition inside this disk drive, by entering “n” in the fdisk command line. Steps as per the following screen shot: image

Now we have create another partition “/dev/sda1” with the type “Linux”

We shall now need to save all the changes we made, type

“w” in the fdisk command prompt to save it and exit

3. Formatting your external usb storage using ext4

we shall now format the new partition,

running a fast format with (-E lazy_itable_init) ext4 file system on /dev/sda1

sudo mkfs /dev/sda1

 

 Once asked for the confirmation press "y"

This may take a while to complete, depending on your disk size and speed.

4. Setting label on your ext4 filesystem (external usb storage):

Label the newly created partition, name it “128GB”:

sudo e2label /dev/sda1 128GB

To check the label name run

sudo e2label /dev/sda1

5. Mounting external usb storage using fstab file and Label:

Mount this partition:

To mount this newly created partition create a mount point and add an entry in  /etc/fstab file for mounting on boot time.

Create a folder called 128GB for mounting this newly created partition

sudo mkdir /128GB

add the following entry in your “/etc/fstab” file

LABEL=128GB       /128GB     ext4    defaults        0       1

sudo nano /etc/fstab

Reload the edited fstab file with the following command

sudo mount –a

6. Checking the configuration:

Finally we shall make a list of block device with all the mount points to confirm the chances we made with the following command.

sudo lsblk -f -o NAME,LABEL,SIZE,FSTYPE,MOUNTPOINT

image

alternatively you may also use the following command to confirm to check the file system and mount point etc.

mount

Recap:

1. Listing available disk with lsblk:
2. Creating a Linux partition on your external usb storage:
3. Formatting your external usb storage using ext4
4. Setting label on your ext4 filesystem (external usb storage):
5. Mounting external usb storage using fstab file and Label:
6. Checking the configuration:

Your usd device drive is now mounted. changes are persistent over reboot. The following article may interest you:

How to configure your Raspberry Pi as a NAS box using samba

Setting up a torrent box on your Raspberry Pi using Deluge

Advertisements

3 thoughts on “Mounting an external disk using ext3/4 on Raspberry Pi

  1. awesome. exactly what i was looking for.
    for some reason on copy paste, the character ‘-‘ would be replaced with ‘.’ in my putty terminal. but it could just be my settings.
    Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s