[Войти] [Зарегистрироваться]

Наши друзья и партнеры

Беспроводные выключатели nooLite

Lines Club

Ищем достойных соперников.

Книги по Linux (с отзывами читателей)

Библиотека сайта или "Мой Linux Documentation Project"

4.3. Partitioning Hard Drive(s)

Why partition, anyway? Well, although it is possible to get a perfectly functioning Linux system running on a single-partition system, and, in fact, is a bit easier to configure this way, there are a number of benefits from partitioning one or more of your storage devices into multiple partitions.

While it is true that Linux will operate just fine on a disk with only one large partition defined, there are several advantages to partitioning your disk for at least the four main file systems (root, usr, home, and swap). These include:

First, it may reduce the time required to perform file system checks (both upon bootup and when doing a manual fsck), because these checks can be done in parallel. (By the way, NEVER run an fsck on a mounted file system!!! You will almost certainly regret what happens to it. The exception to this is if the file system is mounted read-only, in which case it is safe to do so.) Also, file system checks are a lot easier to do on a system with multiple partitions. For example, if I knew my /home partition had problems, I could simply unmount it, perform a file system check, and then remount the repaired file system (as opposed to booting my system with a rescue diskette into single-user mode and doing the repairs).

Second, with multiple partitions, you can, if you wish, mount one or more of your partitions as read-only. For example, if you decide that everything in /usr will not be touched even by root, you can mount the /usr partition as read-only.

Finally, the most important benefit that partitioning provides is protection of your file systems. If something should happen to a file system (either through user error or system failure), on a partitioned system you would probably only lose files on a single file system. On a non-partitioned system, you would probably lose them on all file systems.

This little fact can be a big plus. For example, if your root partition is so corrupted you can't boot, you can basically boot from the rescue diskette set, mount your root partition, and copy what you can (or restore from backup; see Chapter 8 for details on how files can be backed up and restored), to another partition such as home, and then reboot once again using the emergency boot disk, typing "mount root=/dev/hda3" (assuming the partition containing your temporary root file system is on the third partition of hda) and boot your fully functional Linux box. Then you can run an fsck on your unmounted corrupt root partition.

I have had personal experience in file system catastrophies, and I was very grateful for having had the damage limited due to the use of multiple partitions.

Finally, since Linux allows you to set up other operating system(s) (such as Windows 95/98/NT, BeOS, or what-have-you), and then dual- (or triple-, ...) boot your system, you might wish to set up additional partitions to take advantage of this. Typically, you would want to set up at least one separate partition for each operating system. Linux includes a decent boot loader (called LILO on Intel-based systems, although much the same thing is available as MILO on Alpha, and SILO on Sparc) which allows you to specify which operating system you want to boot at power on, with a time-out default boot of your favorite operating system (probably Linux, right?)

You should partition a disk (or disks) according to your needs. In my experience on Intel, Alpha, and Sparc platforms, for a fairly loaded system (feature-wise), doing a fair amount of tasks (as a desktop system at home, or as an Internet server at work), I have found the following approximation of space works pretty effectively for determining a partition size.


A given disk of X Mb/Gb          (eg. 2 Gb)
(Or, more than one disk with a combined total of X Mb/Gb)


(swap) about double main RAM     (eg. 64 Mb system gets 128 Mb swap)
/ (root)  about 10% of available (eg. 200 Mb)
/home about 20% of available     (eg. 400 Mb)
/usr any remaining space         (eg. 1272 Mb)

/var (optional -- see below)
/boot (optional -- see below)
/archive (optional -- see below)

Of course, the above amounts are approximate guidelines only. Obviously you are going to want to juggle those percentages around a bit depending on what you are going to use your Linux system for. If you are going to be doing stuff like adding lots of bulky applications such as WordPerfect or Netscape, or perhaps adding Japanese character support, you would probably benefit from a bit more /usr space.

I always seem to have a lot of space available on /home, so if your users aren't doing much (or you have imposed strict quota sizes), or you aren't offering shell accounts and personal web pages, etc., you probably could lower /home space and raise /usr.

Here is a description of the various mount points and file system information, which may give you a better idea of how to best define your partition sizes for your own needs:

  • / (root) - used to store things like temporary files, the Linux kernel and boot image, important binary files (things that are needed before Linux can mount the /usr partition), and more importantly log files, spool areas for print jobs and outgoing e-mail, and user's incoming e-mail. It is also used for temporary space when performing certain operations, such as building RPM packages from source RPM files. Therefore, if you have a lot of users with a lot of e-mail, or think you will need plenty of temporary space, you might want more space available. The partition type should be left as the default of 83 (Linux native). In addition, you'll probably toggle the bootable flag on this partition to allow boot information to be stored here.

  • /usr/ - should be the largest partition, because most of the binary files required by Linux, as well as any locally installed software, web pages, Squid proxy cache, Samba share services, some locally-installed software log files, etc. are stored here. The partition type should be left as the default of 83 (Linux native).

  • /home/ - typically if you aren't providing shell accounts to your users, you don't need to make this partition very big. The exception is if you are providing user home pages (such as school web pages), in which case you might benefit from making this partition larger. Again, the partition type should be left as the default of 83 (Linux native).

  • (swap) - Linux provides something called "virtual memory" to make a larger amount of memory available than the physical RAM installed in your system. The swap partition is used with main RAM by Linux to accomplish this. As a rule of thumb, your swap partition should be at least double the amount of physical RAM installed in your system.

    If you have more than one physical hard drive in your system, you can create multiple swap partitions. This can improve the performance of swapping by taking advantage of parallel disk access. For example, on a 256 Mb system with four drives, I would probably create four 128 Mb swap partitions, for a total of 256 Mb RAM, 512 Mb swap (for a combined total of 768 Mb available as virtual memory). The partition type needs to be changed to 82 (Linux swap).

    Note: Note: It is a common misconception that Linux has a 128 Mb swap size limit. This was true in the past, but in modern Linux distributions, the size depends on your architecture (for example, Intel systems can have swap sizes as large as 2 Gb). Type ``man mkswap'' for more information.

  • /var/ (optional) - You may wish to consider splitting up your / (root) partition a bit further. The /var directory is used for a great deal of runtime storage, including mail spools (both ingoing and outgoing), print jobs, process locks, etc. Having this directory mounted under / (root) may be a bit dangerous because a large amount of incoming e-mail (for example), may suddenly fill up the partition. Since bad things can happen (eg. system crash?) when the / (root) partition fills up, having /var on its own partition may avoid such problems. I've had success in taking whatever space I've allocated to / (root), perhaps doubling it, and then creating separate partitions for / (root) and for /var. The partition type should be left as the default of 83 (Linux native).

  • /boot/ (optional) - In some circumstances (such as a system set up in a software RAID configuration) it may be necessary to have a separate partition from which to boot the Linux system. This partition would allow booting and then loading of whatever drivers are required to read the other file systems. The size of this partition can be as small as a couple Mb; I recommend approximately 10 Mb (which should give you plenty of room to store the kernel, initial RAMdisk image, and perhaps a backup kernel or two). The partition type should be left as the default of 83 (Linux native).

  • /archive/ (optional) - If you have any extra space lying around, perhaps you would benefit from a partition for a directory called, for example, /archive. You can then use the /archive directory to store backup material, large or infrequently accessed files, samba file services, or whatever else you can find a use for it. The partition type can be left as the default of 83 (Linux native), or if you want to access it from both Linux as well as from another operating system, you could change it to a different ID, such as 6 (DOS 16-bit >=32M).

As extra drive(s) are added, further partitions can be added to the new drives, mounted at various mount-points as required -- this means a Linux system never needs to worry about running out of space. As an example, if in the future it is clear that sda6 is starting to get filled up, we could add another drive, set a nicely sized partition with a mount-point at /usr/local -- and then transfer all the information from /usr/local over to the new drive. But no system or application component would "break" because Linux would see /usr/local no matter where it was located.

To give you an example of how one might set up partitions, I have used the following partitioning scheme on an Intel system (dual boot, Windows 95 and Linux):

   Device Boot   Begin    Start      End   Blocks   Id  System
/dev/hda1  *         1        1      254  1024096+   6  DOS 16-bit >=32M
/dev/hda2          255      255      782  2128896    5  Extended
/dev/hda5          255      255      331   310432+  83  Linux native
/dev/hda6          332      332      636  1229728+  83  Linux native
/dev/hda7          637      637      749   455584+  83  Linux native
/dev/hda8          750      750      782   133024+  82  Linux swap

The first partition, /dev/hda1, is a DOS-formatted file system used to store the alternative operating system (Windows 95). This gives me 1 Gb of space for that operating system.

The second partition, /dev/hda2, is a physical partition (called "extended") that encompasses the remaining space on the drive. It is used only to encapsulate the remaining logical partitions (there can only be 4 physical partitions on a disk; in my case I required more than 4 partitions, therefore I had to use a logical partitioning scheme for the others).

The third through fifth partitions, /dev/hda5, /dev/hda6, and /dev/hda7, are all e2fs-formatted file systems used for the / (root), /usr, and the /home partitions, respectively.

Finally, the sixth partition, /dev/hda8, is used for the swap partition.

For yet another example, this time an Alpha box with two hard drives (sole boot, Linux only), I have chosen the following partitioning scheme:

   Device Boot   Begin    Start      End   Blocks   Id  System
/dev/sda1            1        1        1     2046    4  DOS 16-bit <32M
/dev/sda2            2        2      168   346859   83  Linux native
/dev/sda3          169      169      231   130851   82  Linux swap
/dev/sda4          232      232     1009  1615906    5  Extended
/dev/sda5          232      232      398   346828   83  Linux native
/dev/sda6          399      399     1009  1269016   83  Linux native
/dev/sdb1            1        1      509  2114355   83  Linux native
/dev/sdb2          510      510     1019  2118540   83  Linux native

The first partition, /dev/sda1, is a DOS-formatted file system used to store the MILO boot loader. The Alpha platform has a slightly different method of booting than an Intel system does, therefore Linux stores its boot information in a FAT partition. This partition only needs to be as large as the smallest possible partition allowed -- in this case, 2Mb.

The second partition, /dev/sda2, is an e2fs-formatted file system used for the / (root) partition.

The third partition, /dev/sda3, is used for the swap partition.

The fourth partition, /dev/sda4, is an "extended" partition (see previous example for details).

The fifth and sixth partitions, /dev/sda5, and /dev/sda6, are e2fs-formatted file systems used for the /home and /usr partitions, respectively.

The seventh partition, /dev/sdb1, is an e2fs-formatted file system used for the /archive partition.

The eighth and final partition, /dev/sdb2, is an e2fs-formatted file system used for the /archive2 partition.

After you finish setting up your partition information, you'll need to write the new partition to disk. After this, the Red Hat installation program reloads the partition table into memory, so you can continue on to the next step of the installation process.

Эта статья еще не оценивалась
Вы сможете оценить статью и оставить комментарий, если войдете или зарегистрируетесь.
Только зарегистрированные пользователи могут оценивать и комментировать статьи.

Комментарии отсутствуют