Monday 13 June 2011

Create and Mount a Partition in Ubuntu

If you didn't allocate all of your hard drive to your Ubuntu installation and find yourself with a few GBs of unallocated storage, you can utilize some (or all) of this extra space as a separate drive and configure it to mount either automatically (at boot up) or manually (by command). There are some advantages to having disparate partitions on your hard disk, for instance, you can use a partition as a backup location or as a file server for your music or photographs: often these data are protected from any catastrophic system failure (short of a mechanical failure) and can be recovered when the OS has been repaired.

However, before outlining the steps to create a mount, it's worth pointing out that playing around with partitions can have disastrous consequences: backup your data to a separate storage device before making changes to your partition table. If you are unfamiliar with the precepts of drive partitioning, familiarise yourself with the information on the Ubuntu help pages.

Perhaps the easiest way to manage partitions is to use a partition manager (also known as a partition editor) - I'll be using GParted for this post and you can download and install the program from the Ubuntu Software Centre. I'm also assuming that you have some unallocated space on your drive and it is not my intention to discuss resizing partitions in this post.

When you open GParted (Main Menu > Administration) you'll see a visual representation of your hard disk - right-click on the unallocated space and select New from the pop-up menu. In the Create new Partition dialog you can set the parameters for your partition, including the size and name (label). I recommend using ext4 for the file system in Ubuntu. Once you've adjusted your settings, click the Add button and then Apply from the main menu.

Now that the partition has been created, you'll need to create a mount point:

"A mount point is a directory (typically an empty one) in the currently accessible filesystem on which an additional filesystem is mounted (i.e., logically attached)."
In other words, the mount point is a gateway to another file system: when the gate is unlocked (the file system is mounted) you have access to the files and directories on that file system; when the gate is locked (the file system is unmounted) you don't have access. Typically, when you plug in an external drive to your system it is automatically mounted under the /media/ directory, so this is where I recommend you create your mount point: however, you don't have to create it here. Open a terminal and type

sudo mkdir /media/partition_name

(Where partition_name is literally the name of the partition as you want it known: for instance, you could call it Jogga's Private Drive or Private Storage.)

Next, Ubuntu needs instructions on how to mount this drive and you'll need to amend the /etc/fstab/ file. To do this properly, you'll need the UUID (Universally Unique Identifier label) of your new drive. This is easily obtained using GParted - right-click your partition and then select Information from the pop-up menu. G Parted allows you to copy text from the Information dialog so avoiding mistakes typing a long UUID number can be avoided!

However, you can also get the same information from the command line:

sudo fdisk -l

With the UUID information, you're ready to make the changes to the fstab file, but first:

sudo cp /etc/fstab /etc/fstab.bak

This command makes a backup copy of the file so that you can restore it if necessary!

Now, open the fstab file with:

sudo gedit /etc/fstab

And, when the file is open, add the following line:

UUID=UUID Number /media/partion_name ext4 defaults 0 0

Change the text to suit your partition UUID and name. This command will automount the partition at boot, but that's not obligatory: by changing the defaults command to noauto you can prevent the drive from auto-mounting. For further instructions on this and other configurations, review the information on the Ubuntu Documentation pages.

Now you can mount the paritition with:

sudo mount -a

All being well, you should see your new partition in the media window of Nautilus and it should mount each time you boot.

Sources & References:

No comments:

Post a Comment