Do it your self hobby code

Raspberry Pi: How to mount USB Drive

Raspberry pi is not the same as Windows computer where you can plug your USB drive and open your files without configuring your computer.

In Linux including raspberry pi, you have to manually mount it to use it in a specific location of your choice.

Step 1: Find the device first

sudo fdisk -l

In my computer, I used 64gb usb drive. It shows like this:

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1  *       32 123174911 123174880 58.8G  7 HPFS/NTFS/exFAT

Here, the device name is /dev/sda1

Step 2: Mount the device.

Before we mount it, let’s create folder first on mnt directory:

sudo mkdir /mnt/usb-drive

Now, lets mount it in usb-drive folder

sudo mount /dev/sda1 /mnt/usb-drive/

How to unmount the usb drive?

Enter this command:

sudo umount /mnt/usb-drive

How to unmount your drive?

sudo umount /dev/sdb1

or

sudo umount /mnt/usb-drive

How to format a USB drive?

Be aware that this will erase your files on your usb. Here is the command

For vfat format

sudo mkfs -t vfat /dev/sda1

Ext4 format

sudo mkfs -t ext4 /dev/sda1

To have NTFS filesystem, we have to install this first:

sudo apt-get install ntfs-3g

This is the command to format:

sudo mkfs.vfat /dev/sda1

To create filesystem with a volume-label

sudo mkfs.ntfs -L volume_label /dev/sdb1

To create filesystem with specific UUID:

sudo mkfs.ntfs -U UUID /dev/sdb1

This is the command for Fat and Ext4

sudo mkfs.vfat /dev/sda1
sudo mkfs.ext4 /dev/sda1

Leave a Comment

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