Pendrive is a very important data storage device in our day to day life. But we often got in hustle to make things work between our pc and pendrive or usb device. That's why today I am going to show you exactly what you should do to make things work with your pendrive and linux pc. Remember, this process also work for any ssd, hdd, mmc etc external drives.
First, type lsblk
to check that your usb device is detected or not. If not detected try inserting again.
lsblk
command gives us a list of partitions of all the drives avaiable to the pc. Suppose you got a 32GB pendrive. So, you should look for the corresponding device. Your usb device will look something like sdx
, where on the place of x, can be a or b or any alphabet.
Now, we need to format the disk. This will wipe all the data you have in that pendrive. To format the usb, type:
sudo mkfs.ext4 /dev/sdx
sudo fdisk /dev/sdx
lsblk
command will show you a partition under your device(eg. sdx1). To format this partion:
sudo mkfs.ext4 /dev/sdx1
sudo mkdir -p /mnt/usb
sudo mount /dev/sdx1 /mnt/usb
lsblk
will show the mount point(/mnt/usb) right beside your device partion.
Congratulations, you have successfully mounted a usb device. Use this as your applications.
Now, if you want to keep this device always mounted, you need to do one more things. Because, shutting down your pc will cause unmount the device. Then you need to mount again(sudo mount /dev/sdx /mnt/usb
). So, if you want to keep this device always attached to your pc, not manually do this again and again, then you need to mount this on /etc/fstab
file. Type this command in the terminal:
sudo blkid /dev/sdx1
/etc/fstab
file. So, open that file with this command:
sudo vim /etc/fstab
UUID=xxxx /mnt/usb ext4 defaults 0 2
blkid
.
Now, save the file and exit the editor.
To, make the sure that everything is ok, type:
sudo mount -a
UUID
again. If no error, then congratulations you have successfully added a usb device or hard drive permanently to your pc.