Pinterest Stumbleupon Whatsapp
Advertisement

If you’re looking to use the Linux terminal more A Quick Guide To Get Started With The Linux Command Line A Quick Guide To Get Started With The Linux Command Line You can do lots of amazing stuff with commands in Linux and it's really not difficult to learn. Read More , learning how to manually mount and unmount your hard disks is a simple place to start. Besides, if you ever find yourself in a situation that leaves you away from the traditional desktop, learning how to do so might save a lot of time and Googling.

Fortunately, modern Linux distributions The Best Linux Operating Systems The Best Linux Operating Systems There are many Linux distributions available for a number of different purposes, which makes it difficult to choose at times. Here's a list of the very best to help you decide. Read More make this process much easier and intuitive than before.

What Is Mounting?

In most cases, mounting refers to a process which enables your computer to access files on different devices, such as USBs or hard disk drives. This is because they originate from separate file systems. Mounting also occurs in most Linux distributions due to how they themselves use multiple file systems in the form of “partitions”.

Usually, modern Linux desktops handle this automatically. However, it’s good to know how to do it manually if all else fails, or if you happen to be stuck with only a terminal and need to back up some data How to Make Data Backups on Ubuntu & Other Distros How to Make Data Backups on Ubuntu & Other Distros How much sensitive data would you lose if your disk drive died? Naturally, you need a backup solution, but making backups in Linux can be tricky if you don't know what you're doing... Read More .

Checking Your Available Partitions

To see your devices and their separate file-systems, simply use this command:

lsblk

lsblk

Advertisement

As seen above, separate devices are split into differently named letters, namely sda, sdb, and sdc. Further hard drives follow this convention, continuing to sdd, sde, and so on. Modern hard disks and USBs all start named with sd(x), short for “serial device”. On older computers, you might see them labelled like hda instead.

These devices are further split into different partitions. Put simply, they represent how your hard disk is divided up. It’s these specific partitions which we’re going to mount, rather than the devices themselves — they are where data is actually stored.

As a thumb rule, your Linux box is the device with more than one partition. This is usually done to split important and unimportant system files from one another, among other things What Is a Linux SWAP Partition, And What Does It Do? What Is a Linux SWAP Partition, And What Does It Do? Most Linux installations recommend that you include a SWAP partition. This may seem odd to Windows users – what is this partition for? Read More . Another way to tell is to look under the “Mountpoint” entry. The entries which are part of your Linux box will be already mounted.

Mounting With Udisks

Udisks is an important piece of software used in many Linux distributions. It is responsible for managing storage devices such as USB flash storage, and hard disk drives. With it comes a command line tool called udisksctl. Under this tool, all of your partitioning commands follow this pattern:

udisksctl [command]

Simple isn’t it? To mount your desired partition, use this command, substituting the last bit with the right partition:

udisksctl mount -b /dev/sd[b1, b2, etc.]

udisksctl

The -b simply denotes that what you’re mounting is from a device.

You can also mount disk images with Udisks, but it takes an extra step:

udisksctl loop-setup -r -f Example.iso
udisksctl mount -b /dev/loop[0, 1, 2, etc.]

udiskctl

The first command allows us to recognize our disk image as a virtual (or loop) device. The -r is optional, but makes doubly sure the files you’re mounting won’t be accidentally overwritten — it’s read only. After that, we can proceed as usual, and mount the now available disk image. Since we’re not mounting a hard disk drive, it’s labelled as loop rather than sd(x).

If you check your mounted partitions with the lsblk command again, you’ll notice a few changes.

Notice how the devices other than your Linux box now also have specific mount points. This means you can now access the files on them by going to their specified locations.

Unmounting With Udisks

Once you’re done with your USB, or any other miscellaneous device, you need to safely remove it from your Linux box to prevent data loss. This is done by unmounting the foreign file-system, decoupling it from your own.

Doing this is as simple as substituting mount with unmount:

udisksctl unmount -b /dev/sd[b1, b2, etc.]

udisksctl unmount short

Keep in mind that your virtual devices such as disk images are named differently to hard disk drives and USBs!

If you check your devices using lsblk, you’ll notice that your USB/hard disk drive is still present, even after unmounting it. To remove it completely and safely remove your device, you need to enter in another command which switches it off:

udisksctl power-off -b /dev/sd[b, c, etc.]

udisksctl power off

Note that this does not apply to your own partitions, as they’re part of your system. The same goes for disk images, as they’re not powered in the first place — instead, you’ll need a different command to remove them from your list of devices:

udisksctl loop-delete -b /dev/loop[0, 1, 2, etc.]

Mounting the Old-School Way

For the most part, Udisks should be able to cover most of your bases. However, it’s good to know how to do it another way. The main difference here is that you need to specify where you’d like to mount your partitions, and you won’t be able to turn off your devices using these commands after you’ve finished with them.

You will also need administrator privileges (hence the “sudo” at the beginning of the following commands), so suffice to say, using Udisks is recommended in most cases to prevent your system from breaking accidentally 9 Lethal Linux Commands You Should Never Run 9 Lethal Linux Commands You Should Never Run You should never run a Linux command unless you know exactly what it does. Here are some of the deadliest Linux commands that you'll, for the most part, want to avoid. Read More !

To mount a partition:

sudo mount /dev/sd[b1, b2, etc.] /mnt

The last part indicates where you’d like to place the foreign file-system in your Linux box. Traditionally, this is the /mnt directory. For multiple devices, you can mount them in sub-folders under /mnt. Just be sure to create these folders first with the mkdir command!

mounting the old school way

Like Udisks, the mount tool also supports disk images. However, memorizing how it works can be a little more cumbersome. On the bright side, you only need to enter a single command compared to the Udisks method:

sudo mount Example.iso /mnt -t (iso9660|udf) -o loop

If the contents of your disk image isn’t showing properly, you may have to alternate between “iso9660” and “udf” (excluding the brackets!) — this indicates the format of the disk image.

Unmounting the Old-School Way

Strangely enough, the command to unmount a partition is not unmount, but umount. Keep that in mind. Unlike mounting, you don’t need to specify the location of your mount point — just the device will do:

sudo umount /dev/sd[b1, b2, etc.]

You can now remove your device without data being potentially lost.

For disk images, the command is a little different:

sudo umount /dev/loop[0, 1, 2, etc.]

Future Referencing

If ever you need to remember the specific steps to mount or unmount your devices with the command line, all you need is to do is to enter this:

udisksctl help

udesksctl help

As seen in the above image, you can also ask for help pertaining to the different udisksctl commands.

So there you have it. With these commands at your side, you’re one step closer to using Linux without the aid of the desktop. If you’re up to it, feel free to navigate through your freshly mounted files through the terminal too How to Manage Files in the Linux Terminal and Desktop How to Manage Files in the Linux Terminal and Desktop Once you make the change to Linux, you'll find a sensible desktop that is easy to use, from installing new apps and launching them to organizing your data. Read More .

What other helpful commands do you think other Linux users should know? Sound off in the comments.

Leave a Reply

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

  1. Joseph Pollock
    December 21, 2016 at 11:48 pm

    Nice. I learned the basics when udisksctl didn't exist.

    I used to use pmount to get things mounted as a regular user. It was nice, but I just looked and I don't even have it installed any more.

    One thing I haven't really used, is a great feature - mount --bind . It allows you to make parts of file systems appear to be parts of other file systems. This is useful if you want to access/process down a file system tree that is really pieces gathered from more than one source. Your program/user doesn't need to deal with all the separate pieces.

    See: http://unix.stackexchange.com/questions/198590/what-is-a-bind-mount#198591 for more info.

  2. spyjoshx
    December 14, 2016 at 3:53 pm

    This clears up a whole lot for me! I've really wanted to use the command line for more, and this is very helpful. I also really like being able to mount to a directory with the MOUNT command. I can see this being very useful. Thank you!

    • Austin Luong
      December 14, 2016 at 11:41 pm

      Happy to have helped!