Sunday, November 8, 2009

Mounting Volumes through terminal




In Linux operating systems, partitions of your hard drive are not mounted when you start, you can mount them easily through the normal file manager, anyway this way is not convenient, let's say that I want to open a recent document in Open Office but I forgot to mount the volume where this file exists, this will cause a file not found error to appear. Another thing that mounting volumes in different order causes different paths, so you have to mount volumes every time you start up and in the same order.

Sorry for so much talking, anyway thanks to shell scripts. you can write few lines to mount all volumes for you.

We will see how to do this:

1 - As you should know, every hardware is represented by a file in Linux file system in the folder /dev , so the first thing we need to do is to know the names of the volumes we are going to mount. We can do this by typing this in the terminal.

sudo fdisk -l


This will show us the partitions, their spaces and their names (sda1, sda2, ...)



2 - Let's say I want to mount the partitions sda1, sda5 and sda7, before I call the mount command I must create a mount point which is a folder under the /media folder in the file system. Through this file I will access the contents of the partition.

3 - We will create the folder using
sudo mkdir /media/anyname


4 - I will mount the partition using
sudo mount /dev/sda1 /media/anyname
Note: Partitions that are mounted through terminal must be unmounted through terminal, so if you want to unmount a partition use
sudo umount /media/anyname


It's better if you delete the mount point using
sudo rmdir /media/anyname

These attached files contain the shell script that I wrote to mount and unmount volumes, of course you will change the names of the partitions (sda#) and make them executable using the chmod command.




No comments:

Post a Comment