adding a new hard drive or accessing an external USB drive, mounting a drive in Linux is a basic yet essential skill. Mounting a drive means making its file system accessible to the operating system. In this post, we’ll walk through the steps of mounting a drive in Linux, step-by-step.
What Does Mounting a Drive Mean?
In Linux, mounting is the process of attaching a storage device (like a hard drive, USB stick, or external drive) to a specific directory, known as the mount point. After mounting, you can access the files on that drive just like any other directory on your system.
Step 1: Find the Drive
Before you can mount the drive, you need to identify it. You can use the lsblk
command, which lists all block devices (disks and partitions) connected to your system.
Run the following command in the terminal:
lsblk
You might see something like this:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 100G 0 part /mnt/mydrive
sdb 8:16 0 500G 0 disk
├─sdb1 8:17 0 500G 0 part
In this example:
sda
andsdb
are the drives.sda1
andsdb1
are partitions on those drives.- The
MOUNTPOINT
column shows where the drive or partition is mounted (if it’s already mounted).
Step 2: Create a Mount Point
Next, you’ll need a directory where the drive will be mounted. This is known as a mount point. You can create a new directory using the mkdir
command:
sudo mkdir /mnt/mydrive
In this case, we’ve created a directory called mydrive
in /mnt
. You can choose any path and name that fits your preference.
Step 3: Mount the Drive
Now you’re ready to mount the drive. Use the mount
command to mount a partition (e.g., sdb1
) to the mount point directory (/mnt/mydrive
):
sudo mount /dev/sdb1 /mnt/mydrive
After running this command, the partition sdb1
is now accessible at /mnt/mydrive
. You can navigate to this directory and interact with the files stored on the drive.
Step 4: Verify the Mount
To check if the drive has been successfully mounted, you can use the df -h
command, which displays all mounted file systems:
df -h
You should see something like this:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 30G 40% /mnt/mydrive
This confirms that the drive is mounted and available.
Step 5: Unmount the Drive
When you’re done using the drive and want to safely remove it, you should unmount it. Use the umount
command followed by the mount point or the device name:
sudo umount /mnt/mydrive
Alternatively, you can use the device name:
sudo umount /dev/sdb1
After unmounting, you can safely disconnect the drive from your system.
Step 6: Automate Mounting (Optional)
If you want the drive to mount automatically every time your system boots, you can edit the /etc/fstab
file. This file lists all file systems that should be mounted automatically.
- Open the file in a text editor:
sudo nano /etc/fstab
- Add a line for your drive at the end of the file. For example:
/dev/sdb1 /mnt/mydrive ext4 defaults 0 2
This assumes that the drive is formatted with theext4
file system. If you’re using a different file system (likentfs
orvfat
), replaceext4
with the appropriate type. - Save and close the file. Now, every time the system boots, the drive will automatically be mounted to
/mnt/mydrive
.