Monday, 17 March 2008

Partitions and Filesystems in Linux

A computer with Microsoft Windows installed will normally have only one partition on the hard drive, which contains the entire operating system (actually, many computers will actually have a separate diagnostic or recovery partition so you can reinstall easily - don't do what I did and delete that!). By comparison, Linux will always have at least two partitions, and can have more depending on how you have set up your system, but you don't have to keep track of this as the operating system does this for you. This also applies to additional hard drives - whereas Windows will show the primary hard drive as C, the next as D and so on, Linux makes no distinction between different hard drives, and is happy to slot them into the filesystem where ever you see fit.

If you used Guided partitioning when you installed Ubuntu, then it will have created two partitions - your main partition and a swap partition. If you're dual-booting with Windows, these will coexist with your Windows partition and possibly your recovery partition. By using manual partitioning, you can add extra partitions, and decide where to mount these within your filesystem. For instance, many people will set up their /home directory on a separate partition. Although this is a bit more fiddly than using Guided partitioning, it has the advantage that if you do a fresh install, as long as you don't overwrite the /home partition, you can keep everything saved to this directory.

The same applies to additional hard drives - you could have the main partition on one drive, and your /home directory on another, for instance. Linux does recognise the actual hard drives as being separate devices though - they're in the /dev directory, which as you may recall, contains device drivers. These act as a shortcut to the device for the sake of convenience. Typically, they will be described using the following system:
  • /dev/cdrom - The CD-ROM drive (though you may also see cdrom1, cdwriter, dvd, or even a hard drive designation)
  • /dev/fd0 - Floppy drive 1
  • /dev/fd1 - Floppy drive 2
  • /dev/hda - First IDE hard drive
  • /dev/hda1 - First IDE hard drive, first primary or extended partition
  • /dev/hda2 - First IDE hard drive, second primary or extended partition
  • /dev/hdb - Second IDE hard drive, with numbers denoting the partitions as for hda
  • /dev/sda - First SCSI hard drive
  • /dev/sda1 - First SCSI hard drive, first primary or extended partition. Can also refer to USB devices ranging from flash drives to iPods, which you'd probably want to mount to /media.
Don't worry too much if you're struggling to understand this. Next time, we'll be demonstrating how to set up your /home directory on a separate partition - a very useful thing to know!

No comments: