Sunday 8 June 2008

Mounting partitions and other devices from the command line

Many Linux users dual-boot with another operating system, and it can be inconvenient if you can't get access to the files you have in that partition. For instance, if you are dual booting Windows XP and Ubuntu, perhaps you'd like to be able to play some music from your hard drive in Rhythmbox, but you can't get at it. Ubuntu is pretty good at mounting new filesystems automatically, but it's not perfect, so it pays to take the time to learn how to do it yourself. Don't worry, it's not that hard!

If it's an external device such as a flash drive that you want to mount, then connect this. Then run the following command in the terminal:
sudo fdisk -l

This will display all the filesystems that your system can detect, whether they are mounted or not. For example, here's mine on my Kubuntu laptop:
matthew@matthew-laptop:~$ sudo fdisk -l

Disk /dev/sda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0008acac

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2918 23438803+ 83 Linux
/dev/sda2 2919 3042 996030 82 Linux swap / Solaris
/dev/sda3 3043 4864 14635215 83 Linux
matthew@matthew-laptop:~$

Don't worry if this looks confusing. All you need to look for is the Device and System columns. The system column shows the filesystem used - this can be handy as different operating systems use different filesystems, so it would be easy to recognise a Windows-formatted partition - it would show as something like FAT or NTFS. The device column shows the device each partition is on - /dev/sda is the hard drive. /dev/sda1 is one partition, /dev/sda2 is another and so on. A different device would show up as something else, such as /dev/sdb, and its partitions might show as /dev/sdb1 and so on.
So you should have no problem identifying which partition it is you want to mount. Once you know this, we can get started. If you remember from an earlier lesson, Linux will happily slot a new partition in anywhere you tell it to, you just have to say where. It's best to put it in the /media directory if it's something temporary like a flash drive, whereas /mnt is better for more permanent things like your Windows partition. You'll need to create a directory in which to mount it to make it easier to manage, something like this:
sudo mkdir /mnt/windows

Then, once that's done, you can issue the command to mount the partition there. If the Windows partition was /dev/sda3, you could mount it in /mnt/windows as follows:
sudo mount /dev/sda3 /mnt/windows

Once this is done, you should be able to browse the newly added partition or device with ease. If you want to remove it manually, issue this command:
sudo umount /dev/sda3

If you'd like to mount something automatically when you boot up, such as your Windows partition, you can install the pysdm package. Then open the new Storage Device Manager, which will enable you to easily set up partitions to mount at boot, and specify where you want them.

No comments: