The Hacker’s Blog

Your friendly neighborhood hacker!

Saturday, July 5, 2008

A Guide to Linux Partitions and File Systems

Without partitions or filesystems, you wouldn’t be able to do a whole lot with your computer. In fact, you really wouldn’t be able to do anything. Partitions come in many shapes and sizes, just as filesystems do. So what exactly are these mysterious things?

What is a partition?

A partition is a section of a harddrive mapped off to be seperated from other parts. There are two different kinds of partitions: primary and logical. A primary partition is identified with a number from 1 to 4. Logical partitions only exist if you designate a partition as extended. When a partition is marked as being extended, you can create more partitions (logical) that allow you to have up to a total of 16 partitions on that given harddrive.

A partitions name consists of the harddrive and the partitions number. These are referenced (in Linux) as being a file in /dev. SCSI and IDE drives are shown by sdX and hdX respectively where X is a letter assigned by the operating system based on the order and location of the harddrive(s). So, for example, if I had 3 partitions and an extended partition with 2 more partitons on an IDE drive, the partitions would be listed as

  • /dev/hda1
  • /dev/hda2
  • /dev/hda3
  • /dev/hda4 — extended
  • /dev/hda5 — logical
  • /dev/hda6 — logical

OK, but what is a filesystem?

A filesystem makes a partition useable by the operating system. Some of the major filesystems include EXT3, XFS, JFS, REISERFS, NTFS, HFS+ and more recently, ZFS. Filesystems allow partitions to hold files. Different operating systems, or OSs, require that you use certain filesystems. Windows requires you to use NTFS, Mac OS X requires HFS+ but Linux allows you to choose from a myriad of filesystems. You create a filesystem after creating a partition. If I wanted to create an EXT3 filesystem on my first partition, I would use this command:


mke2fs -j /dev/hda1

After a filesystem is created on a partition, the partition can be mounted to a mount point on your system. For example, if I created a 30 gigabyte partition for my root ( / ) directory, I would mount that partition to /.

So, how do I benefit from knowing this?

Knowing how partitions work, along with fireworks, can make your computer a great deal faster than normal. However, it really varies based on your distro and what the use of the computer is. Partitioning schemes (what your partitions are) are going to be different on servers than on desktops and some distros use different folders than others. Gentoo uses portage which resides in /usr/portage and can benefit from using ccache to speed up compile times. By setting the ccache directory and the portage directory to reside on their own partitions, you can speed up both of those (as long as your choice of filesystem is a good one).

One of the disadvantages is the loss of space. If you set aside 4 gigabytes for a /var partition and you only use 1 gigabyte, you’re really wasting a bit of space there.

Related Posts

posted by prime at 12:00 am  

1 Comment »

  1. Nice tut!

    They usually are not so clean cut.

    Comment by HackerNo Gravatar — December 30, 2008 @ 12:44 am

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress