Find out how to Mount a Onerous Drive in Linux Utilizing the Command Line

If you want to use the terminal more often, you can simply learn how to manually mount and unmount a hard drive on a Linux system. If you ever find yourself in a situation that keeps you away from the traditional desktop, knowing how to do it can save a lot of time and research.

Fortunately, modern Linux distributions make this process a lot easier and more intuitive than before.

What is assembly?

In most cases, mounting refers to the process by which your computer can access files stored on various devices such as USB drives or hard drives. Each drive has its own file system or systems that need to be integrated into your PC's ecosystem. Most Linux distributions are often mounted because they consist of multiple file systems in the form of "partitions".

Modern Linux desktops usually take over the assembly process automatically. However, it is good to know how to do it manually if all else fails or if you just got stuck with a terminal and need to back up some data.

Check your available partitions

After you've connected your hard drive or USB, you can view your devices and their separate file systems with this command:

lsblk

As can be seen above, each physical device follows a naming convention of sd (x), the first being named sda, the second sdb, the third sdc, and so on. The sd Name is short for SCSI device. If you are using an older computer, these may be named as well hd (x) instead.

These individual devices are further divided into different partitions: sda1, sda2, sda3, and so on. Simply put, they represent how your hard drive is partitioned. It is these specific partitions that we are going to mount, and not the devices themselves – since that is where the actual data is stored.

You can usually identify your Linux box by its multiple partitions. This is to keep important and unimportant system files like your swap partition separate. Another way to tell is to look under them Mount point Entry. The entries that are part of your Linux box are already mounted.

How to mount a hard drive on Linux

In fact, there are two different command line interfaces you can use to mount devices on Linux: Udisks and mount / umount. We recommend Udisks in almost all situations, but since each use case is different, we'll outline the mount method as well.

Assembly with Udisks

Udisks are important software used in many Linux distributions. It is responsible for managing storage devices like USB flash drives and hard drives. It includes a command line tool called udisksctl. Under this tool, all partitioning commands follow this basic pattern:

udisksctl (command) (options) (location)

Easy isn't it? Use this command to mount the partition you want sdb1 with the name of your partition:

udisksctl mount -b / dev / sdb1

The -b The flag simply indicates that the partition you are mounting is from a device.

You can also use virtual devices, e.g. B. mount disk images with Udisks:

udisksctl loop-setup -r -f example.iso

If your image doesn't complete the assembly process on its own, identify the loop name with lsblk and enter and replace this command loop0 with your loop name.

udisksctl mount -b / dev / loop0

Since we are not providing a physical hard drive, it will be marked as loop rather than sd (x).

The first command will allow you to recognize your disk image as virtual (or loop) Device. The -r Flag standing for read-only, is optional, but double-check that the files you mount are not accidentally overwritten. After that we can continue as usual and provide the now available disk image.

If you check your mounted partitions with the lsblk If you run the command again you will notice some changes.

Note that devices other than your Linux box now also have certain mount points. This means that you can now access the files by changing the directories in the specified locations.

Display with Udisks

Once you are done with your mounted drive, you need to safely remove it from your Linux box to avoid data loss. You can do this by unmounting and then turning off the foreign filesystem and decoupling it from your own.

To undeploy, you can reuse the previous command, but replace it assemble With dismantle::

udisksctl unmount -b / dev / sdb1

Don't forget to change the name at the end with the name of your device, and be aware that virtual devices, such as B. Disk images, are named differently than hard drives and USBs.

When you check your devices with lsblkYou will find that your hard drive is still there even after you unmount it. To completely and safely remove it, you'll need to enter another command that will turn it off:

Turn off udisksctl -b / dev / sdb1

Note that you should never turn off the partitions on your Linux PC as they are part of your system. The same applies to disk images, as they are not supplied with power at all. Instead, you'll need another command to remove them from your device list:

udisksctl loop-delete -b / dev / loop0

Mounting with bracket

For the most part, Udisks should do the job for you. However, it is good to know how to do it alternatively if the first is not an option.

The other option is that assemble Command. The main difference between Udisks and Mount is that under Mount you have to specify where you want to mount your partitions. Also, once you have finished using the mount command, you will not be able to turn off your device.

You also need administrator rights (hence sudo at the beginning of the following commands). Since sudo permissions are very powerful, in most cases we recommend the Udisks method to prevent accidental damage to your system.

If you want to use the mount command, here's how you can do it:

sudo mount / dev / sdb1 / mnt

The last part, / mnt, indicates where you want to place the mounted hard drive on your PC. Traditionally, this is the case on Linux / mnt Directory. For several devices, you can integrate them in sub-folders under / mnt. Just make sure you create these folders with mkdir first.

Like Udisks that assemble The tool also supports disk images. Memorizing how it works, however, can be a bit of a hassle. In contrast to Udisks, you only need to enter a single command when mounting disk images with mount:

sudo mount example.iso / mnt -t iso9660 -o loop

If the contents of your disk image do not display correctly, try replacing them iso9660 With udf. This option specifies the format of the disk image.

Related: How to Clone Your Linux Hard Drive

Hang up with umount

It may seem strange, but the command to unmount a partition is not "unmount", it is umount. In contrast to assembly, you do not have to specify the position of your mounting point. You only need the device name.

sudo umount / dev / sdb1

Note that if you are working with a physical device, you must still use the Udisks turn off Command (explained above) to ensure that no data is lost when disconnected.

For disk images, just name the loop device:

sudo umount / dev / loop0

Don't forget to replace here either loop0 with your device name.

Help with mounting hard drives

Mounting and unmounting drives can get tricky if you're not used to it. If you need to memorize the specific steps for these utilities, remember that you can always enter those Help Order for immediate guidance.

udisksctl help

Assemble help

Fortunately for Linux users, there are plenty of ways to get help for each command in addition to our manuals.

7 Ways to Get Command Line Help on Linux

All the essential commands for learning Linux commands from the command line

Continue reading

About the author

Jordan Gloor
(37 articles published)

Jordan is a tutor and journalist who is passionate about making Linux accessible and stress-free for everyone. He has a BA in English and a thing for hot tea. During the warm season he enjoys cycling on the hills of the Ozarks where he lives.

More
By Jordan Gloor

Subscribe to our newsletter

Sign up for our newsletter to receive tech tips, reviews, free e-books, and exclusive offers!

One more step …!

Please confirm your email address in the email we just sent you.

Leave a Reply

Your email address will not be published. Required fields are marked *