DEV Community

Rishit Khandelwal
Rishit Khandelwal

Posted on

How to automount disk drive

Ok, so I have got a secondary 512gb hdd along with my primary ssd.

I can mount my drive like this: sudo mount /dev/sdb5 ~/bigdisk.
But how can I make it so that it happens automatically when I login/start the computer?

Top comments (4)

Collapse
 
moopet profile image
Ben Sinclair

This depends on the system, but the easiest thing is going to be adding it directly to /etc/fstab.
Edit that file and add your disk to the list, something like:

/dev/sdb5                     /home/rishit/bigdisk     ext4    defaults,noatime 0 2
Enter fullscreen mode Exit fullscreen mode

You'll need to change the mount point to whatever you actually use, I'm guessing here :) and also the filesystem. Ext4 is the most common with Linux, and if you get it wrong it won't break anything - it just won't mount.

If you add it to the fstab configuration file you don't need to reboot to try it, make sure it's not mounted (sudo umount /dev/sdb5 if you need to) and run sudo mount -a which tells the system to ensure everything in fstab is mounted. If it works and you see the drive, everything's good. If it doesn't, revert your changes to be safe and let me know what error you got.

Collapse
 
rishitkhandelwal profile image
Rishit Khandelwal

Thanks!

I am surprised u know my home directory is /home/rishit.

Collapse
 
moopet profile image
Ben Sinclair

I am a master hacker! I know eveerything!

Thread Thread
 
rishitkhandelwal profile image
Rishit Khandelwal

lol