Jump to content

IM-09: Filesystem Layout Partitioning


Recommended Posts

Browse: [About the FAQ Forum] [Table of Contents] [FAQs] [Contribute] [IM: Installing and Configuring Mandrake]

 

IM-09: Filesystem Layout Partitioning

by static

 

Many people wonder how the harddrive should be partitioned at install time. This guide will help you understand the linux directory structure, how it corresponds to the filesystem layout, and help you make an educated decision for which filesystem types to use for the different partitions.

 

Your filesystem is the base of your computer. It is a structure in which all your files are kept, ranging from files that run the operating system to files such as e-mails or mp3 music files. Rather than keep every file in one giant mess, they've been sorted out into groups of files that belong together and kept in directories, or "folders" as they're called in other operating systems. (Think of it this way, if you went fishing and caught a salmon, a pike, a bass, and a minow, you wouldn't want to keep them all in one tub, would you? Of course not! That would be insane! You want a different tub for each fish. The fish are the files, and the tubs are the directories.)

 

Without going into too much detail, here's what you need to know to install linux.

 

/ - Called the "root" (and that is why we usually write directory names preceeded with a / - it's the root of the filesystem. Not to be confused with the system administrative god, who's login name is also root!)

 

/bin - This isn't a bin for trash! This is where system binaries are kept. Binaries are executable files that you can run, and in this case they are for programs that run the operating system. This directory will

 

/boot - Where all the files necessary to boot the system are kept. If you choose to create a separate partition for this directory (explained below), it must be the first partition you create (i.e. at the forefront of the drive). It doesn't need to be larger than 20 megs or so.

 

/dev - All your devices, like CDROMs and floppy drives, are in here.

 

/etc - This is where the system configuration files are kept (the way the OS is setup, so to speak)

 

/home - This is where user's directories are created. For example, /home/static is where files for the user static are kept by default.

 

/usr - This is where general applications usually place their files.

 

- /usr/bin - binaries for apps like office or games

- /usr/etc - configs setup for them

- /usr/src - source code for the apps

 

/sexygirls - I can't tell you what I keep in here (but I can tell you that they don't think I'm funny when I tell them I'd "give them access to my harddrive")

 

/var - If you're running a server, the files (like music or webpages) that you are serving other people on the internet would be contained in here.

 

When installing linux, you have the option of dividing up the space on your hard drive into separate sections (or parts) called partitions. This can be handy, as it can improve the stability and security of your system. Here's an example: Your operating system tends to begin operating poorly if it's running out of space. You could, therefore, take your 10 Gig harddrive and divide it into 2 partitions (let's say 5 gigs each to keep it simple); one for / and one for /home. Considering anything you download will end up in your home directory (/home/joe for example), if you try to download more than 5 gigs of that Amish dance music you like so much, you'll be told you're out of space; however, the operating system is still as happy as a pig in the mud, because his space hasn't been invaded by your gigs of Amish dance music.

 

To take that example and apply it to your own linux installation, let's first consider a few things. First of all, downloading music won't be the only thing you'll want to do with your PC. You will want to install applications and games, and these get put into /usr. You should create separate partitions for the major directories so that you've got a safety net for the OS. This way, you have a partition for / (the OS), one for /usr (for applications and games like Klingon Wheel of Fortune), and one for /home (for the Amish dance music).

 

Also, linux (like other OS's) uses Swap space - which is just used like imaginary RAM. The difference with linux is it likes to keep another partition solely for the Swap. Another OS, we'll call it "wino-dows", just uses a swapfile on the same partition as the OS. Note this can make things unstable, though, if the swapfile needs more space - but that space is already used up by the OS, the wino-dows version of Klingon Wheel of Fortune, and your Amish dance music! So, you see why multiple partitions is a very smart idea (thank you linux, thank you).

 

So, when installing linux, you must decide how big to make these partitions. One of the most common partitioning practices is to have 4 partitions: /, Swap, /usr, and /home. With this sceme, use about a gig for /, twice your RAM for Swap, a third of what space is left over for /usr, and the rest for /home.

 

I personally make /usr a little bigger though, because almost anything I put into /home/static I end up burning onto a CD or DVD anyway, and I'd like to have the extra space for installing apps and games.

 

IMHO it's also good to spread the partitions over different hard drives.

 

For example I have my swap partition on separate harddrive, and I noticed significant speed increase (especially while using VMware with WindowsXP), my hard disks don't "grind" so much anymore. Accessing two hard drives at the same time is much faster than accessing one (I think up to twice as fast).

 

I'll try to explain the filesystem types briefly.

 

First I need to subdivide the fs types into two categories: journaling and non-journaling.

 

Journaling filesystems include: xfs, jfs, reiserfs, and ext3. There might be one more but these are the major ones.

 

Non-journaling filesystems include: ext2, swap. The swap is a special partition type so I don't know if it really counts or not, just threw it in for completeness. It IS, however, it's own fs type, whether you use reiser or whatever, swap is swap.

 

The difference between journaling and non-journaling filesystems is that journaling fs's keep a log, or a journal, of bits written to the disk. This is also called a meta-data system, because in effect, data is stored bout the rest of the data on the disk. The benefit of keeping a log/journal of the rest of the info on the disk is for safety. Look at it this way:

 

Newbie lets his server run all day and all night. Once in a while the power goes out and resets his computer. With a non-journaling fs like ext2 he may lose data and may experience filesystem corruption when the machine resets because the disk isn't properly finalized and unmounted safely. With a journaling filesystem, the filesystem compares the dates on the log with other info on the drive, replaying the log to repair/replace lost data. Did I mention it's really, really fast too? Ext2, in the event of a crash, forces fsck to run. Fsck is the filesystem checker utility that checks/repairs partitions much like scandisk on windows. Journaling filesystems don't require a fsck very often, if at all. They replay their logs and keep going.

 

Now that you understand the benefits, let's examine the advantages/disadvantages of each journaling filesystem. You'd be wise to choose one based on what you need.

Reiserfs:
A. Benefits
1. A very efficient filesystem that journals metadata. It also uses very small blocks so it's even more efficient, because if a tiny text file is just a few bytes, and there are many, they'll all get packed into one block rather than written as separate blocks.
2. Journals metadata. This can be considered a partially true journaling filesystem, because it's not redundant. A true journaling filesystem actually mirrors the data in a sense. Reiser does not.
3. Very fast with huge files. Because of the way it journals, it merely moves pointers in the log rather than physically moving gigantic (1gb or more) files. I'm not 100% sure about this but you can do your own research :smile:
4. Better than ext2 for the filesystem performance and journaling alone.
5. Large maximum file size. Ext2 is limited to 2gb, Reiser is limited to 4gb.
 
B. Disadvantages
1. Not a true journaling filesystem, so it doesn't protect you 100% from losing data.
2. Not good with lots of medium-sized files.
3. Not 110% stable with older 2.4.x series kernels. Personally I have never had a problem with it but other people with other distros have.
4. Not easy to recover data from like ext2, there just aren't any tools.
 
JFS:
A. Benefits
1. A true journaling filesystem. Not only does it log but it more or less mirrors data (jounals).
2. Large filesize support. Again, ext2 can only handle a 2gb file, JFS can handle between 512 terabytes to 4 petabytes. That's a big file. :wink:
3. Developed and supported by IBM, used for many years across many systems and there are lots of server people familiar with it, but...
 
B. Disadvantages
1. Although it's mature on other systems, some linux people believe it's still too cutting-edge. Not a great idea for a primetime server. Still needs work under linux.
2. While it's a true journaling FS, that journal comes at a price. Performance isn't as quick as Reiser or EXT2.
 
XFS:
A. Benefits
1. Very, very fast. SGI has been using XFS on their IRIX boxes for years, and considering what they do for a living, they need filesystem speed above all else. This has made it popular for linux as well.
2. Very large files supported. Again, EXT2 is stuck with a 2gb limit while XFS can handle between 16-64 terabytes. Gigantic. In the future when linux adopts 64bit disk I/O, this number scales to over 1 million terabytes.
3. Dump/restore tools come with XFS and they work as expected.
 
B. Disadvantages
1. Not a true journaling filesystem. Like Reiser, it sacrifices true journaling for speed. Not a bad tradeoff actually.
2. Some people believe SGI isn't serious about Open Source, or at least not as serious as IBM. Their motives are questionable at this point. Not really a disadvantage but support for XFS in the future may/may not continue.

 

I've used Reiser for a couple of years now and have grown to trust it and enjoy its' performance, even on crappy older computers. I've never experienced corruption like others have mentioned on the net so personally I recommend it. I've also used XFS and JFS, and I'm torn on which one to put above the rest. They're all pretty equal IMHO but I've used Reiser for the longest so I can testify to it's reliability.

 

I was reading Afro's great filesystem comparison but he didn't go into detail for ext3, the default (which is basically the old ext2 filesystem with journaling). This makes it a tiny bit slower than ext2, but it's rock solid, and hence the default choice. I use ext3 for the ultra important system partitions and the speedy Reiserfs for data partitions (like /usr and /home).

 

Now you have enough knowledge to successfully and confidently install a linux distribution to your harddrive. We recommend Mandriva linux, of course!

Edited by static
Link to comment
Share on other sites

 Share

×
×
  • Create New...