Jump to content

How to mount hard drive in linux

babadoctor
Go to solution Solved by Electronics Wizardy,
Just now, babadoctor said:

I see. 

oops that command at the end should be mount /dev/sdb2

 

heres how it works

-sudo -s makes you root so you mount a drive(you must be root to mount)

-mkdir /mnt/hdd adds a folder that the drive will be mounted to

 

-mount /dev/sdb2 /mnt/hdd will mount the partition to the folder

 

If you want it to mount on boot add a entry in fstab

I formatted a harddrive in windows, and when I plug it into my headless linux machine, I can see the drive, but I can not cd into it... What commands do I run to make it accessible to me for reading/writing?

3e3905c2737f85a9cd7f5c81f95fec25.png

sdb is the hard drive I would like to use

Do i need to mount it?

http://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal-how-can-i-mount-a-flash-driv

i'm not sure how I would go about doing this for a hard drive, and i would greatly appreciate it if someone could guide me through the steps I would need to take

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

sudo -s && mkdir /mnt/hdd && mkfsmount /dev/sdb2 /mnt/hdd

 

Your hdd is now mounted in /mnt/hdd

 

That /dev/sda is a block device and you can't cd in to that

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Electronics Wizardy said:

sudo -s && mkdir /mnt/hdd && mkfsmount /dev/sdb2 /mnt/hdd

 

Your hdd is now mounted in /mnt/hdd

 

That /dev/sda is a block device and you can't cd in to that

I see. 

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, babadoctor said:

I see. 

 

4 minutes ago, Electronics Wizardy said:

sudo -s && mkdir /mnt/hdd && mkfsmount /dev/sdb2 /mnt/hdd

 

Your hdd is now mounted in /mnt/hdd

 

That /dev/sda is a block device and you can't cd in to that

Can i change the name to anything i want? 

sudo -s && mkdir /mnt/hdd && mkfsmount /dev/sdb2 /mnt/hdd

sudo -s && mkdir /mnt/80GIGHDD && mkfsmount /dev/sdb2 /mnt/80GIGHDD

 

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, babadoctor said:

I see. 

oops that command at the end should be mount /dev/sdb2

 

heres how it works

-sudo -s makes you root so you mount a drive(you must be root to mount)

-mkdir /mnt/hdd adds a folder that the drive will be mounted to

 

-mount /dev/sdb2 /mnt/hdd will mount the partition to the folder

 

If you want it to mount on boot add a entry in fstab

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Electronics Wizardy said:

oops that command at the end should be mount /dev/sdb2

 

heres how it works

-sudo -s makes you root so you mount a drive(you must be root to mount)

-mkdir /mnt/hdd adds a folder that the drive will be mounted to

 

-mount /dev/sdb2 /mnt/hdd will mount the partition to the folder

 

If you want it to mount on boot add a entry in fstab

Got it. Thanks!

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, babadoctor said:

 

Can i change the name to anything i want? 

sudo -s && mkdir /mnt/hdd && mkfsmount /dev/sdb2 /mnt/hdd

sudo -s && mkdir /mnt/80GIGHDD && mkfsmount /dev/sdb2 /mnt/80GIGHDD

 

You can mount to what ever folder you want, just don't mount to a folder with stuff in it. 

I was wrong with names and its mount

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Electronics Wizardy said:

You can mount to what ever folder you want, just don't mount to a folder with stuff in it. 

I was wrong with names and its mount

 

 

sudo -s && mkdir /mnt/80GIGHDD && mount /dev/sdb2 /mnt/80GIGHDD

So this is the correct command?

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, babadoctor said:

sudo -s && mkdir /mnt/80GIGHDD && mount /dev/sdb2 /mnt/80GIGHDD

So this is the correct command?

OOPS using sudo -s won't work, you have to run this. 

 

sudo mkdir /mnt/80GIGHDD && sudo mount /dev/sdb2 /mnt/80GIGHDD

 

Depending on what account you in.

 

If you logged in as root, you don't have to use sudo.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

a145b1866915afca86824cb6396e567d.png

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

0d01e192a5f40d2020859965af0ae6a8.png

nice

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

As others have mentioned, (almost) all of the "files" in the /dev/ directory are provided for convenience by the (IIRC) kernel, so you can have consistent access to devices. Things like hard drives, SSDs, cd drives, and serial devices show up there (as /dev/sdx, /dev/srx, /dev/sdx, /dev/Sx, respectively). Your original link involves Ubuntu, so I'll assume that (though this should work for all *nix environments). Oh, and as a note, the /dev/sdx handle is just the raw device, you won't be able to mount them directly. You have to instead mount one of it's partitions, noted by the 1 or 2 after the handle (/dev/sdx1 or /dev/sdx2).

Linux uses the concept that the /dev/ devices must be "mounted" to somewhere in the filesystem, so it knows what type of partitions are on the device (ntfs, fat32, etc). You can theoretically mount your devices wherever you want. For example, I have a Chromebook that I installed Arch Linux on, and I mount a micro SD card to /opt, so it looks like my OS has a bunch more storage than it does. Anyway, as mentioned by @Electronics Wizardy, the common place to mount them is in the /mnt directory. So, you generall will use the root account (sudo or su) to make a folder in the /mnt directory and mount your drive to that. For reference, to find out which block devices you have, you can use the lsblk command. If that isn't found on your system, you can also use "cat /proc/partitions" in a pinch. So an example output of lsblk on my machine looks like this:

pinguinsan@Z170A-Titanium-PC:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk 
├─sda1   8:1    0   500M  0 part 
└─sda2   8:2    0 232.4G  0 part /mnt/windows
sdb      8:16   0 232.9G  0 disk 
├─sdb1   8:17   0   203G  0 part /
└─sdb2   8:18   0  29.9G  0 part [SWAP]
sdc      8:32   0 931.5G  0 disk 
└─sdc1   8:33   0 931.5G  0 part /mnt/hdd
sdd      8:48   0 931.5G  0 disk 
└─sdd1   8:49   0 931.5G  0 part /mnt/hdd-2
sde      8:64   0   4.6T  0 disk 
├─sde1   8:65   0   128M  0 part 
└─sde2   8:66   0   4.6T  0 part /mnt/ehdd
sr0     11:0    1  1024M  0 rom  

So I have a bunch of devices, mounted to different stuff. My /dev/sda2 is my Windows installation on a separate drive, and my /dev/sdc1 and /dev/sdd1 (/mnt/hdd and /mnt/hdd-2, respectively) are my steam libraries for Windows and Linux. You can also note that I have a /dev/sr0, which corresponds to my CD drive.

So anyway, to answering you question, all you have to do is mount your partition to a known folder. Whether that means creating one or not is up to you. So, an example for you would be

 

sudo mkdir /mnt/hdd
sudo mount /dev/sdb2 /mnt/hdd

And you device would be mounted to /mnt/hdd, where you can now cd into and view the files.

On a last side note, you can of course chain the two together with the && (as @Electronics Wizardy did). What this does is execute the first command, then execute the second command IF AND ONLY IF the first command executes without error (or more accurately returns an error code of 0). You can also use || if you want the second command to execute IF AND ONLY IF the first command fails, so something like:

 

sudo mount /dev/sdb2 /mnt/hdd || echo "The mounting of /dev/sdb2 to /mnt/hdd has failed"

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×