Difference between revisions of "Partitioning"

From ArchWiki
Jump to: navigation, search
m (Add zh-cn)
(Add page link.)
Line 9: Line 9:
 
{{Article summary wiki|LVM}}
 
{{Article summary wiki|LVM}}
 
{{Article summary wiki|Swap}}
 
{{Article summary wiki|Swap}}
 +
{{Article summary wiki|Format a device}}
 
{{Article summary end}}
 
{{Article summary end}}
  

Revision as of 04:45, 28 July 2012

Summary help replacing me
An overview of disk partitioning tools, best practices, and additional considerations.
Related
fstab
LVM
Swap
Format a device

Partitioning a hard drive allows one to logically divide the available space into sections that can be accessed independently of one another. Partition information is stored within a hard drive's Master Boot Record.

An entire hard drive may be allocated to a single partition, or one may divide the available storage space amongst multiple partitions. A number of scenarios require creation multiple partitions: dual- or multi-booting, for example, or maintaining a swap partition. In other cases, partitioning is used as a means of logically separating data, such as creating separate partitions for audio and video files. Common partitioning schemes are discussed in detail below.

Users may create up to four primary partitions per hard drive. If additional partitions are required, a single extended partition can be created instead (that is, up to three primary partitions and one extended partition). An extended partition can be further divided into an unlimited number of logical partitions.

File system

From Wikipedia:File system:

A file system (or filesystem) is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device(s) which contain it. A file system organizes data in an efficient manner and is tuned to the specific characteristics of the device.

Some common file systems are:

  • ext2/ext3/ext4 - File system used for GNU/Unix partitions
  • FAT32 - File system used to store files, used by most USB or removable Devices. Mountable with mount or other utilities (e.g Thunar#Thunar Volume Manager)
  • NTFS - File system used by windows. Mountable with many utilities (e.g. NTFS-3G)

See also File Systems.

Partition type

Partitioning a hard disk drive defines specific memory storage areas. These are called partitions. Each partition behaves as a separate disk and is formatted with a specific filesystem type (see below).

There are 3 types of disk partitions:

  • Primary
  • Extended
    • Logical

Primary partitions can be bootable and are limited to four partitions per disk or RAID volume. If a partitioning scheme requires more than four partitions, an extended partition containing logical partitions is used. Extended partitions can be thought of as containers for logical partitions. A hard disk can contain no more than one extended partition. The extended partition is also counted as a primary partition so if the disk has an extended partition, only three additional primary partitions are possible (i.e. three primary partitions and one extended partition). The number of logical partitions residing in an extended partition is unlimited. A system that dual boots with Windows will require that Windows reside in a primary partition.

The customary numbering scheme is to create primary partitions sda1 through sda3 followed by an extended partition sda4. The logical partitions on sda4 are numbered sda5, sda6, etc.

Swap partition

A swap partition is a place on the drive for virtual RAM. This allows the kernel to access disk space for data that does not fit into physical RAM.

Historically, the general rule for swap partition size was to allocate twice the amount of physical RAM. As computers have gained ever larger memory capacities, this rule has become deprecated. On machines with up to 512MB RAM, the 2x rule is usually adequate. If a sufficient amount of RAM (more than 1024MB) is available, it may be possible to have a smaller swap partition or even eliminate it. With more than 2 GB of physical RAM, one can generally expect good performance without a swap partition. There is always an option to create a swap file after the system is setup.

Note: The old rule of matching the swap partition size with the available RAM when using suspend-to-disk no longer applies. The default suspend method uses an image the size of 40% of the currently available RAM by default. Even with TuxOnIce the atomic copy generally only takes about 70% after compression.[1]

Selecting a partitioning scheme

There are no strict rules for partitioning a hard drive, although one may follow the general guidance given below. A disk partitioning scheme is determined by various issues such as desired flexibility, speed, security, as well as the limitations imposed by available disk space. It is essentially personal preference. Two simple possibilities are: i) one partition for root and one partition for swap or ii) just a single root partition without swap. Read through the following discussion and examples to understand the benefits and tradeoffs in making the decision. If you would like to dual boot Arch Linux and a Windows operating system please see Windows and Arch Dual Boot.

The following mountpoints are possible choices for separate partitions:

/ (root)
The root directory is the top of the hierarchy, the point where the primary filesystem is mounted and from which all other filesystems stem. All files and directories appear under the root directory /, even if they are stored on different physical devices. The contents of the root filesystem must be adequate to boot, restore, recover, and/or repair the system. Therefore, certain directories under / are not candidates for separate partitions (see the warning below).
Note: Support for /usr as a separate partition is not provided by default [2]. If you have a compelling reason for doing so, read mkinitcpio#/usr as a separate partition.
/boot
This directory contains the kernel and ramdisk images as well as the bootloader configuration file and bootloader stages. It also stores data that is used before the kernel begins executing user-space programs. This may include saved master boot sectors and sector map files. This directory is essential for booting, but is unique in that it may still be kept on its own optional partition.
Warning: Unlike /boot, the other directories essential for booting must be on the same partition as /. These essential directories are: /bin, /etc, /lib, /sbin and /usr [3].
/home
Provides subdirectories for each system user. It holds miscellaneous personal data as well as user-specific configuration files for applications.
/tmp
Directory for programs that require temporary storage of files such as .lck , which can be used to prevent multiple instances of their respective program until a task is completed. Upon completion, the .lck file will be automatically removed. Programs must not assume that any files or directories in /tmp are preserved between invocations of the program and files and directories located under /tmp will typically be deleted whenever the system is booted.
/var
Contains variable data such as spool directories and files, administrative and logging data, pacman's cache, the ABS tree, etc. It exists to make it possible to mount /usr as read-only. Everything that historically went into /usr that is written to during system operation (as opposed to installation and software maintenance) must reside under /var.
Note: /var contains many small files. The choice of filesystem type (see below) should consider this fact if a separate partition is used.

There are several advantages for using discrete filesystems as opposed to placing everything in one partition:

  • Security: Each filesystem may be configured in /etc/fstab as nosuid, nodev, noexec, readonly, etc.
  • Stability: A user, or malfunctioning program can completely fill a filesystem with garbage if they have write permissions for it. Critical programs residing on a different filesystem remain unaffected.
  • Speed: A filesystem that gets re-written too frequently may become fragmented. Separate filesystems remain unaffected and each can be defragmented separately. Fragmentation can be avoided by ensuring that each filesystem is never in danger of filling up completely.
  • Integrity: If one filesystem becomes corrupted, separate filesystems remain unharmed.
  • Versatility: Sharing data across several systems becomes more expedient when independent filesystems are used. Separate filesystem types may also be chosen based upon the nature of data and usage.

How big should my partitions be?

The size of the partitions depends on personal preference, but the following information may be helpful:

/boot — 100 MB 
A /boot partition requires only about 100 MB.
/ — 15-20 GB 
The root filesystem (/) must contain the /usr directory, which can grow significantly depending upon how much software is installed. 15-20 GB should be sufficient for most users with modern hard disks.
/var — 8-12 GB 
The /var filesystem will contain, among other data, the ABS tree and the pacman cache. Keeping cached packages is useful and versatile as it provides the ability to downgrade. As a result, /var tends to grow in size. The pacman cache in particular will grow as the system is expanded and updated. It can, however, be safely cleared if space becomes an issue. If you are using an SSD, you may wish to locate your /var on an HDD and keep the / and /home partitions on your SSD to avoid needless read/writes to the SSD. 8-12 GB on a desktop system should be sufficient for /var, depending on how much software will be installed. Servers tend to have relatively larger /var filesystems.
/home — [very large] 
The /home filesystem is typically where user data, downloads, and multimedia reside. On a desktop system, /home is typically the largest filesystem on the drive by a large margin. If it becomes necessary to reinstall Arch, all the data on your /home partition will be retained if it is setup on its own partition.
Note: If available, an extra 25% of space added to each filesystem will provide a cushion for future expansion and help protect against fragmentation.

Partitioning tools

To control the actual partition scheme type:

# fdisk -l
  • fdisk — Terminal partitioning tools included in Linux.
https://www.kernel.org/ || util-linux
  • cfdisk — A terminal partitioning tool written with ncurse libraries.
https://www.kernel.org/ || util-linux
Note: The first partition created by cfdisk starts at sector 63, instead of the usual 2048. This will cause problems with grub2. grub-legacy and syslinux should work fine.
  • GNU Parted — It allows to resize or to copy a partition (fdisk and cfdisk don't have this feature)
http://www.gnu.org/software/parted/parted.html || parted
  • Partitionmanager — Graphical tool written in QT.
http://sourceforge.net/projects/partitionman/ || partitionmanagerAUR
  • QtParted — Similar to Partitionmanager, available in AUR.
http://qtparted.sourceforge.net/ || qtpartedAUR
  • GParted — Graphical tool written in GTK.
http://gparted.sourceforge.net/ || gparted

Partitions in a GNU/Unix system

The recommended partitions are / (root), /boot, /home and swap, but you can also add /usr and /var:

/ (root)

The / partition or root partition is necessary and it is the most important. The other partitions can be replaced by it, even though having different partitions is recommended.

/boot

The /boot directory contains the kernel and ramdisk images as well as the bootloader configuration file and bootloader stages. It also stores data that is used before the kernel begins executing user-space programs. /boot is not required for normal system operation, but only during boot and kernel upgrades (when regenerating the initial ramdisk).

If kept on a separate partition, /boot does not require a journaled file system. A separate /boot partition is needed if installing a software RAID0 (stripe) system.

/home

The /home directory stores personal files in different folders. Keeping it in a separate partition can be very useful for backup: it often requires the most disk space (for desktop users) and may need to be expanded at a later date.

A /home partition can also be shared with other Linux systems installed in multi boot, although this is not recommended becuase of possible incompatibilities between user configuration files.

Swap

The swap partition provides memory that can be used as virtual RAM. It is recommended for PCs with 1GB or less of physical RAM.

Historically, the general rule for swap partition size was to allocate twice the amount of physical RAM. As computers have gained ever larger memory capacities, this rule has become deprecated. On machines with up to 512MB RAM, the 2x rule is usually adequate. If a sufficient amount of RAM (more than 1024MB) is available, it may be possible to have a smaller swap partition or even eliminate it. With more than 2 GB of physical RAM, one can generally expect good performance without a swap partition. There is always an option to create a swap file after the system is setup.

Note: The old rule of matching the swap partition size with the available RAM when using suspend-to-disk no longer applies. The default suspend method uses an image the size of 40% of the currently available RAM by default. Even with TuxOnIce the atomic copy generally only takes about 70% after compression.[4]

/usr

The /usr directory stores file that are shared by all users. A /usr partition can be useful because it can be shared with others Linux OS.

In order to have a separate /usr partition, a mkinitcpio hook is required, as /usr is expected to be available at boot: see Mkinitcpio#/usr as a separate partition.

/var

The /var directory stores cache and log files. It is used for example for caching and logging, and hence frequently read or written. Keeping it in a separate partition avoids running out of disk space due to flunky logs, etc.

See also