mount

June 8, 2014

As part of my ongoing series of (hopefully informative) posts about basic functions in Ubuntu, I thought I’d talk a little bit about mount. Hard drives and other peripheral devices (well, to be precise, file systems) are connected to a Linux system via the mount command. In Linux this is called “mounting” a drive or partition. If you only have one hard drive, this will already be mounted when you boot up. If you have additional hard drives they’ll either have to be mounted manually after boot or else added to your fstab configuration file (as much as I want to parse that as “F stab”, it stands for “file system table”). Partitions present in fstab will be automatically mounted during boot.

The simple command mount doesn’t actually mount anything, but gives you a list of things that are already mounted. A number of system items will probably show up, but the main things to look for are things like /dev/sda1, which are the kind of partitions that you’ll usually be dealing with. sda is the first hard drive on your system, sdb is the second, sdc is the third, and so on. The numbers following indicate the partition number. If you have only one partition (as many hard drives do), it’ll just have, e.g., sdb1. If you have multiple ones it’ll be sdb1, sdb2, sdb3, etc.

The typical mount command I’ve used is mount -t type dev dir. The -t flag tells it you’re specifying the file system type. For newer Linux systems this will probably be ext4 if it’s a typical data partition (rather than a boot or swap partition). For a Windows system it’ll probably be ntfs. For a USB drive it will probably be vfat, fat32 or possibly fat16. Thus for a standard Linux partition you’d start with mount -t ext4. However, this doesn’t say what to mount or where to mount it. “dev” in the command stands for “device”; you’ll replace that with the partition you want to mount. So if we wanted to mount the first partition on the second hard drive, we would add to the above to create mount -t ext4 /dev/sdb1. Now we have to add the directory (“dir” in the original schema) we’re going to treat the partition as. This can be pretty much anything, but by default things are usually mounted in the “media” folder. So, for instance, if this is a hard drive where you keep all your music (I still love physical CDs, but I have to have everything ripped to my computer as well), you could choose /media/mp3s. So the complete command would be mount -t ext4 /dev/sdb1 /media/mp3s. To unmount something you only have to specify the device, and the command is umount (not a typo, it’s umount rather than unmount; a very easy mistake to make).

Lastly I’ll mention the fstab file again, which automatically mounts drives when you boot the system. I actually don’t use my fstab file much because I like the system to boot with just the main drive; if any problems crop up it’s easier to isolate them. There are GUI systems for editing your fstab file, but a lot of them are lacking, and honestly this is a case where I think it’s actually safer to edit the actual system file than use a front end (note that for many system files the exact opposite is true). It’s hard to do something really catastrophic with your fstab file because all it does is mount drives automatically — in most cases the worst outcome is that something mounts wrong and you have to unmount it, or it fails to mount automatically. However, it’s good to make a backup of your fstab file anyway in case something goes wrong. The first column in the file is the device (e.g., /dev/sdb1), the second is the mount point (the directory you want to mount it to), and the third is the file system type. The fourth column allows you to list options for the device. Typically if you want it to mount automatically and you don’t have any special requirements this column should say “defaults”. The last two columns have to do with system backups and error checking, and in most cases should both be set to 0. Unless it’s your root partition they should NOT be set to 1.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: