Linux, unlike Windows, doesn’t have a concept of switching drives. Instead, it treats all connected drives as part of a single file system. This means that to access a different drive, you need to “mount” it to a specific directory in your file system. This article will guide you through the process of accessing different drives in Linux using the terminal.
To switch drives in the Linux terminal, you need to mount the desired drive to a specific directory in your file system. This can be done using the
mount command followed by the drive’s file path and the desired mount point. Once the drive is mounted, you can navigate to it using the
cd command. To unmount the drive, you can use the
Understanding the Linux File System
Before we dive into the process of switching drives, it’s important to understand how the Linux file system works. In Linux, all files and directories stem from a single root directory, denoted by a forward slash (
/). Any connected storage devices, such as hard drives or USB drives, need to be mounted onto this file system to be accessed.
Each storage device is represented as a file under the
/dev directory. For example, the first hard drive is usually represented as
/dev/sda, the second as
/dev/sdb, and so on. Partitions on these drives are represented by appending a number to the end of the drive’s file. For example, the first partition on the first drive is
Listing Connected Drives
To list all connected drives and their partitions, you can use the
fdisk command. The
lsblk command lists all block devices (i.e., storage devices) in a tree-like format by default. Here’s how to use it:
fdisk command, on the other hand, provides more detailed information, including the size of the partitions and the file system type. Here’s how to use it:
sudo fdisk -l
Remember to replace
sudo with the command that gives you administrative privileges on your system.
Mounting a Drive
To access the files on a drive, you need to mount it to a directory in your file system, known as a mount point. This can be any empty directory. For example, to mount the first partition on the second drive (
/dev/sdb1) to the directory
/mnt/my_drive, you would use the following command:
sudo mount /dev/sdb1 /mnt/my_drive
After running this command, any files on the drive will appear under the
Navigating to the Mounted Drive
Once the drive is mounted, you can navigate to it using the
cd command, like so:
Now, you can use commands like
ls to list the files on the drive, or any other commands to work with the files.
Unmounting a Drive
When you’re done with the drive, it’s a good practice to unmount it. This can be done with the
umount command, like so:
sudo umount /mnt/my_drive
Making the Mount Permanent
The above steps will mount the drive only until the next reboot. To mount the drive permanently, you need to edit the
/etc/fstab file. This file contains a list of drives and their mount points, and is read by the system at boot time.
To add a drive to this file, you first need to open it in a text editor. You can use any text editor you like, but for this example, we’ll use
sudo nano /etc/fstab
Then, add a line at the end of the file in the following format:
/dev/sdb1 /mnt/my_drive auto defaults 0 0
Save the file and exit the editor. The drive will now be mounted automatically at boot time.
In Linux, accessing different drives involves mounting them to a directory in your file system. While this is a bit different from how other operating systems handle multiple drives, it offers a great deal of flexibility. With a bit of practice, you’ll find it’s quite easy to switch between drives in the Linux terminal.
You can use the
fdisk command to list all connected drives and their partitions. The
lsblk command provides a tree-like format, while the
fdisk command provides more detailed information.
To mount a drive in Linux, you need to use the
mount command followed by the device file of the drive and the mount point directory. For example,
sudo mount /dev/sdb1 /mnt/my_drive will mount the first partition of the second drive to the
Once a drive is mounted, you can navigate to it using the
cd command followed by the mount point directory. For example,
cd /mnt/my_drive will take you to the mounted drive located at
To unmount a drive in Linux, you can use the
umount command followed by the mount point directory. For example,
sudo umount /mnt/my_drive will unmount the drive that was previously mounted at
To make a drive mount automatically at boot time in Linux, you need to edit the
/etc/fstab file. Open the file in a text editor, add a line in the format of
/dev/sdb1 /mnt/my_drive auto defaults 0 0, save the file, and exit the editor. The drive will now be mounted automatically at boot time.