Difference between revisions of "Partitioning"

From ArchWiki
Jump to: navigation, search
(Partitioning tools)
(40 intermediate revisions by 14 users not shown)
Line 2: Line 2:
 
[[it:Partitioning]]
 
[[it:Partitioning]]
 
[[ru:Partitioning]]
 
[[ru:Partitioning]]
 +
[[zh-cn:Partitioning]]
 
{{Article summary start}}
 
{{Article summary start}}
 
{{Article summary text|An overview of disk partitioning tools, best practices, and additional considerations.}}
 
{{Article summary text|An overview of disk partitioning tools, best practices, and additional considerations.}}
Line 8: 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 wiki|File Systems}}
 
{{Article summary end}}
 
{{Article summary end}}
  
''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]].
+
''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 [[GUID Partition Table]] or [[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.
+
An entire hard drive may be allocated to a single partition, or one may divide the available storage space across 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.
 +
 
 +
Each partition should be formatted to a [[File Systems|file system type]] before being used.
  
 
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.''
 
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==
+
==Partition type==
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:
+
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).
* 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 {{ic|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 [[Beginners' Guide#Creating filesystems: General information]].
+
There are 3 types of disk partitions:
  
==Partitioning tools==
+
* Primary
 +
* Extended
 +
** Logical
  
To control the actual partition scheme type:
+
'''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.
# fdisk -l
+
  
*{{App|fdisk|Terminal partitioning tools included in Linux.|https://www.kernel.org/|{{Pkg|util-linux}}}}
+
The customary numbering scheme is to create primary partitions {{ic|sda1}} through {{ic|sda3}} followed by an extended partition {{ic|sda4}}. The logical partitions on {{ic|sda4}} are numbered {{ic|sda5}}, {{ic|sda6}}, etc.
*{{App|cfdisk|A terminal partitioning tool written with ncurse libraries.|https://www.kernel.org/|{{Pkg|util-linux}}}}
+
*{{App|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|{{pkg|parted}}}}
+
*{{App|Partitionmanager|Graphical tool written in QT.|http://sourceforge.net/projects/partitionman/|{{AUR|partitionmanager}}}}
+
*{{App|QtParted|Similar to Partitionmanager, available in [[AUR]].|http://qtparted.sourceforge.net/|{{AUR|qtparted}}}}
+
*{{App|[[GParted]]|Graphical tool written in GTK.|http://gparted.sourceforge.net/|{{Pkg|gparted}}}}
+
  
==Partitions in a GNU/Unix system==
+
===Swap partition===
  
The recommended partitions are '''/ (root)''', '''/boot''', '''/home''' and [[swap]], but you can also add '''/usr''' and '''/var''':
+
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.
  
===/ (root)===
+
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 [[HOW TO: Create swap file|swap file]] after the system is setup.  
The {{ic|/}} partition or root partition is necessary and it is the most important. The other partitions can be replaced by it, even thought have different partitions is recommended.
+
  
===/boot===
+
{{Note|The old rule of matching the swap partition size with the available RAM when using [[Suspend_to_Disk|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.[http://tuxonice.net/features]}}
 +
 
 +
== Partition 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. If you would like to dual boot Arch Linux and a Windows operating system please see [[Windows and Arch Dual Boot]].
 +
 
 +
=== Single root partition ===
 +
This scheme is the simplest; it is quick to setup but lacks flexibility and security. Two simple possibilities are:
 +
* One partition for root and one partition for swap
 +
* Just a single root partition without swap.
 +
 
 +
=== Discrete partitions ===
 +
There are several advantages for using discrete partitions as opposed to placing everything in one partition:
 +
 
 +
* Security: Each filesystem may be configured in {{ic|/etc/fstab}} as {{ic|nosuid}}, {{ic|nodev}}, {{ic|noexec}}, {{ic|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.
 +
 
 +
=== Mount points ===
 +
The following mount points are possible choices for separate partitions, you can make your decision based on actual needs.
 +
 
 +
====/ (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'' {{ic|/}}'', 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'' {{ic|/}} ''are not candidates for separate partitions.
 +
 
 +
The {{ic|/}} 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.
 +
 
 +
{{Note|1=Support for {{ic|/usr}} as a separate partition is not provided by default [https://bbs.archlinux.org/viewtopic.php?pid=1006924#p1006924]. If you have a compelling reason for doing so, read [[mkinitcpio#/usr as a separate partition]].}}
 +
 
 +
====/boot====
 
The {{ic|/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. {{ic|/boot}} is not required for normal system operation, but only during boot and kernel upgrades (when regenerating the initial ramdisk).
 
The {{ic|/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. {{ic|/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, {{ic|/boot}} does not require a journaled file system. A separate {{ic|/boot}} partition is needed if installing a software RAID0 (stripe) system.
 
If kept on a separate partition, {{ic|/boot}} does not require a journaled file system. A separate {{ic|/boot}} partition is needed if installing a software RAID0 (stripe) system.
  
===/home===
+
{{Warning|Unlike {{ic|/boot}}, the other directories essential for booting '''must''' be on the same partition as ''' {{ic|/}}'''. These essential directories are: {{ic|/bin}}, {{ic|/etc}}, {{ic|/lib}}, {{ic|/sbin}} and {{ic|/usr}} [http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken].}}
The {{ic|/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 {{ic|/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.
+
====/home====
 +
The {{ic|/home}} directory contains user-specific configuration files (the so-called "dot files"). Optionally, it can also hold any type of media (videos, music, etc), and if you use Wine, the games/programs will be installed in {{ic|~/.wine/}} by default. So please take this into account if you chose to create a separate home partition.
  
===Swap===
+
While keeping it on a separate partition can be useful in case you reinstall, some prefer to start fresh (because that's usually the reason for a reinstall), instead of reusing old, and possibly deprecated or problematic, configuration files. The main advantage is that, in very rare cases, if the root partition becomes too full, it will not impact your web browser, media player, torrent client, etc. They will keep working uninhibited, and will keep saving new changes to their setting files or to their cache.
The [[swap]] partition provides memory that can be used as virtual RAM. It is recommended for PCs with 1Gb or less of physical RAM.
+
  
===/usr===
+
A home partition can also be shared with other installed Linux distributions, but this is not recommended because of possible incompatibilities between user-specific configuration files. The only exception is if each distribution has its own user dir on the shared home partition.
 +
 
 +
====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 [[HOW TO: Create swap file|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|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.[http://tuxonice.net/features]}}
 +
 
 +
====/usr====
 
The {{ic|/usr}} directory stores file that are shared by all users. A {{ic|/usr}} partition can be useful because it can be shared with others Linux OS.
 
The {{ic|/usr}} directory stores file that are shared by all users. A {{ic|/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]].
 
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===
+
====/var====
The {{ic|/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.  
+
The {{ic|/var}} directory stores variable data such as spool directories and files, administrative and logging data, [[pacman]]'s cache, the [[Arch Build System|ABS]] tree, etc. 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.
 +
 
 +
It exists to make it possible to mount'' {{ic|/usr}} ''as read-only. Everything that historically went into'' {{ic|/usr}} ''that is written to during system operation (as opposed to installation and software maintenance) must reside under'' {{ic|/var}}''.
 +
 
 +
{{Note|{{ic|/var}} contains many small files. The choice of filesystem type (see below) should consider this fact if a separate partition is used.}}
 +
 
 +
==== /tmp ====
 +
Directory for programs that require temporary storage of files such as'' {{ic|.lck}} '', which can be used to prevent multiple instances of their respective program until a task is completed. Upon completion, the'' {{ic|.lck}} ''file will be automatically removed. Programs must not assume that any files or directories in'' {{ic|/tmp}} ''are preserved between invocations of the program and files and directories located under'' {{ic|/tmp}} ''will typically be deleted whenever the system is booted.
 +
 
 +
====How big should my partitions be?====
 +
 
 +
The size of the partitions depends on personal preference, but the following information may be helpful:
 +
 
 +
; {{ic|/boot}} — 100 MB : A {{ic|/boot}} partition requires only about 100 MB.
 +
; {{ic|/}} — 15-20 GB : The root filesystem ({{ic|/}}) '''must''' contain the {{ic|/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.
 +
; {{ic|/var}} — 8-12 GB : The {{ic|/var}} filesystem will contain, among other data, the [[Arch Build System|ABS]] tree and the [[pacman]] cache. Keeping cached packages is useful and versatile as it provides the ability to downgrade. As a result, {{ic|/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 {{ic|/var}} on an HDD and keep the {{ic|/}} and {{ic|/home}} partitions on your SSD to avoid needless read/writes to the SSD. 8-12 GB on a desktop system should be sufficient for {{ic|/var}}, depending on how much software will be installed. Servers tend to have relatively larger {{ic|/var}} filesystems.
 +
; {{ic|/home}} — [very large] : The {{ic|/home}} filesystem is typically where user data, downloads, and multimedia reside. On a desktop system, {{ic|/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 {{ic|/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==
 +
*{{App|fdisk|Terminal partitioning tools included in Linux.|https://www.kernel.org/|{{Pkg|util-linux}}}}
 +
*{{App|cfdisk|Terminal partitioning tool written with ncurses libraries.|https://www.kernel.org/|{{Pkg|util-linux}}}}
 +
{{Note|The first partition created by cfdisk starts at sector 63, instead of the usual 2048. This will cause problems with [[GRUB2#msdos-style error message|GRUB2]]. grub-legacy and syslinux should work fine.}}
 +
*{{App|gdisk|[[GPT]] version of fdisk.|http://www.rodsbooks.com/gdisk/|{{Pkg|gptfdisk}}}}
 +
*{{App|cgdisk|[[GPT]] version of cfdisk.|http://www.rodsbooks.com/gdisk/|{{Pkg|gptfdisk}}}}
 +
*{{App|GNU Parted|Terminal partitioning tool.|http://www.gnu.org/software/parted/parted.html|{{pkg|parted}}}}
 +
*{{App|[[GParted]]|Graphical tool written in GTK.|http://gparted.sourceforge.net/|{{Pkg|gparted}}}}
 +
*{{App|Partitionmanager|Graphical tool written in QT.|http://sourceforge.net/projects/partitionman/|{{AUR|partitionmanager}}}}
 +
*{{App|QtParted|Similar to Partitionmanager, available in [[AUR]].|http://qtparted.sourceforge.net/|{{AUR|qtparted}}}}
 +
 
 +
==Partition Alignment ==
 +
==== High-level Overview ====
 +
'''Proper partition alignment is essential for optimal performance and longevity.''' The key to alignment is partitioning to (at least) the EBS (erase block size) of the SSD.
 +
 
 +
{{Note|The EBS is largely vendor specific; a Google search on the model of interest would be a good idea! The Intel X25-M for example is thought to have an EBS of 512 KiB, but Intel has yet to publish anything officially to this end.}}
 +
{{Note|If one does not know the EBS of one's SSD, use a size of 512 KiB. Those numbers are greater or equal than almost all of the current EBS. Aligning partitions for such an EBS will result in partitions also aligned for all lesser sizes. This is how Windows 7 and Ubuntu "optimize" partitions to work with SSD.}}
 +
 
 +
If the partitions are not aligned to begin at multiples of the EBS (512 KiB for example), aligning the file system is a pointless exercise because everything is skewed by the start offset of the partition. Traditionally, hard drives were addressed by indicating the ''cylinder'', the ''head'', and the ''sector'' at which data was to be read or written. These represented the radial position, the drive head (= platter and side) and the axial position of the data respectively. With LBA (logical block addressing), this is no longer the case. Instead, the entire hard drive is addressed as one continuous stream of data.
 +
 
 +
=== Using GPT - Modern Method ===
 +
[[GPT]] is an alternative, contemporary partitioning style. It is intended to replace the old Master Boot Record ([[MBR]]) system. GPT has several advantages over MBR, which has quirks dating back to MS-DOS times. With recent developments to the formatting tools fdisk (MBR) and gdisk (GPT), it is equally easy to use GPT or MBR and get maximum performance.
 +
 
 +
==== Choosing between GPT and MBR ====
 +
The choice basically boils down to this:
 +
* If using GRUB Legacy as the bootloader, one must use MBR. See [[#Using MBR - Legacy Method]].
 +
* To dual-boot with Windows, one must use MBR. See [[#Using MBR - Legacy Method]].
 +
** A special exception to this rule: dual-booting Windows Vista/7 64 bit, and using [[UEFI]] instead of BIOS, one must use GPT.
 +
* If none of the above apply, choose freely between GPT and MBR. Since GPT is more modern, it is recommended in this case.
 +
 
 +
==== Gdisk Usage Summary====
 +
 
 +
The GPT-able tool equivalent to {{ic|fdisk}}, {{ic|gdisk}}, can perform partition alignment automatically on a 2048 sector (or 1024KiB) block size base which should be compatible with the vast majority of SSDs if not all. GNU parted also supports GPT, but is [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=601813 less user-friendly] for aligning partitions. A summary of the typical usage of {{ic|gdisk}}:
 +
 
 +
* Install {{ic|gdisk}} through the {{pkg|gptfdisk}} package from the '''extra''' repository.
 +
* Start {{ic|gdisk}} against your SSD.
 +
* If the SSD is brand new or if wanting to start over, create a new empty GUID partition table (aka GPT) with the {{keypress|o}} command.
 +
* Create a new partition with the {{keypress|n}} command (primary type/1st partition).
 +
* Assuming the partition is new, gdisk will pick the highest possible alignment. Otherwise, it will pick the largest power of two that divides all partition offsets.
 +
* If choosing to start on a sector before the 2048th gdisk will automatically shift the partition start to the 2048th disk sector. This is to ensure a 2048-sectors alignment (as a sector is 512B, this is a 1024KiB alignment which should fit any SSD NAND erase block).
 +
* Use the {{ic|<nowiki>+x{M,G}</nowiki>}} format to extend the partition {{ic|x}} megabytes or gigabytes, if choosing a size that is not a multiple of the alignment size (1024kiB), gdisk will shrink the partition to the nearest inferior multiple.
 +
* Select the partition's type id, the default, {{ic|Linux/Windows data}} (code {{ic|0700}}), should be fine for most use. Press {{Keypress|L}} to show the codes list. If planning to use LVM select Linux LVM (8e00).
 +
* Assign other partitions in a like fashion.
 +
* Write the table to disk and exit via the {{keypress|w}} command.
 +
* Create the filesystems as usual.
  
==Partitioning during installation==
+
{{Warning|If planning to use the GPT partitioned SSD as a boot-disk on a BIOS based system (most systems except Apple computers and some very rare motherboard models with Intel chipset) one may have to create, preferably at the disk's beginning, a 2 MiB partition with no filesystem and with the partition type as {{ic|BIOS boot}} or {{ic|bios_grub}} partition (gdisk type code {{ic|EF02}}) for booting from the disk using [[GRUB]]. For [[Syslinux]], one does not need to create a separate 2 MiB bios_grub partition, but one needs to have separate {{ic|/boot}} partition and enable {{ic|Legacy BIOS Bootable partition}} attribute for that partition (using gdisk). See [[GPT]] for more information.}}
The partitiong process is clearly explained here: [[Beginners' Guide#Prepare hard drive]].
+
  
That is only a short summary.
+
{{Warning|GRUB legacy does not support GUID partitioning scheme, users must use [[burg]], [[GRUB]] or [[Syslinux]].}}
The available options are:
+
# Auto-Prepare
+
# Manually Partition Hard Drives
+
# Manually Configure block devices, filesystems and mountpoints
+
# Rollback last filesystem changes
+
  
===Auto-Prepare===
+
{{Warning|If planning to dual boot with Windows (XP, Vista or 7) do NOT use GPT since they do NOT support booting from a GPT disk in BIOS systems! Users need to use the legacy MBR method described below for dual-boot in BIOS systems! This limitation does not apply if booting in UEFI mode and using Windows Vista (64bits) or 7 (64bits). For 32-bit Windows Vista and 7, and 32 and 64-bit Windows XP, users need to use MBR partitioning and boot in BIOS mode only.}}
The Auto-Prepare options formats the entire Hard Disk and divides it into 4 partitions:
+
  
* /boot (ext2 file system) with a size of 100Mb (editable)
+
=== Using MBR - Legacy Method ===
* Swap with a size of 256Mb (editable)
+
Using MBR, the utility for editing the partition table is called {{ic|fdisk}}. Recent versions of fdisk have abandoned the deprecated system of using cylinders as the default display unit, as well as MS-DOS compatibility by default. The latest fdisk automatically aligns all partitions to 2048 sectors, or 1024 KiB, which should work for all EBS sizes that are known to be used by SSD manufacturers. This means that the default settings will give you proper alignment.
* /home
+
* /
+
  
For {{ic|/home}} and {{ic|/}} partitions there are a lot of available files system (the same for both). A ext3 or ext4 file system is recommended and at least a size of 5Gb for the {{ic|/}} partition.
+
Note that in the olden days, fdisk used cylinders as the default display unit, and retained an MS-DOS compatibility quirk that messed with SSD alignment. Therefore one will find many guides around the internet from around 2008-2009 making a big deal out of getting everything correct. With the latest fdisk, things are much simpler, as reflected in this guide.
  
{{Warning|Using the "Auto-Prepare" option all files on the Hard disk will be deleted.}}
+
==== Fdisk Usage Summary ====
 +
*Start {{ic|fdisk}}.
 +
*If the SSD is brand new, create a new empty DOS partition table with the {{keypress|o}} command.
 +
*Create a new partition with the {{keypress|n}} command (primary type/1st partition).
 +
*Use the {{ic|+xG}} format to extend the partition {{ic|x}} gigabytes.
 +
*Change the partition's system id from the default type of Linux ({{ic|type 83}}) to the desired type via the {{keypress|t}} command. This is an optional step should the user wish to create another type of partition for example, swap, NTFS, LVM, etc. Note that a complete listing of all valid partition types is available via the {{keypress|l}} command.
 +
*Assign other partitions in a like fashion.
 +
*Write the table to disk and exit via the {{keypress|w}} command.
  
===Manually Partition Hard Drives===
+
When finished, users may format their newly created partitions with {{ic|mkfs.x /dev/sdXN}} where {{ic|x}} is the filesystem, {{ic|X}} is the drive letter, and {{ic|N}} is the partition number.
With this option the user can edit the partitions with the cfdisk tool. This option can be done before the installation, using other tools.
+
The following example will format the first partition on the first disk to ext4 using the defaults specified in {{ic|/etc/mke2fs.conf}}:
 +
# mkfs.ext4 /dev/sda1
  
===Manually Configure block devices, filesystems and mountpoints===
+
{{Warning|Using the {{ic|mkfs}} command can be dangerous as a simple mistake can result in formatting the WRONG partition and in data loss! TRIPLE check the target of this command before hitting the Enter key!}}
With this option the user can manage the partition, setting file system and, overall, the role of each partition ({{ic|/}}, {{ic|/home}}, {{ic|/boot}}, {{ic|Swap}}, {{ic|/var}} or {{ic|/usr}}).
+
  
 
==See also==
 
==See also==
 +
*[[Ext4#Creating ext4 partitions from scratch|Creating ext4 partitions from scratch]]
 
*[[Wikipedia:Disk partitioning]]
 
*[[Wikipedia:Disk partitioning]]

Revision as of 22:28, 20 November 2012

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

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 GUID Partition Table or Master Boot Record.

An entire hard drive may be allocated to a single partition, or one may divide the available storage space across 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.

Each partition should be formatted to a file system type before being used.

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.

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]

Partition 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. If you would like to dual boot Arch Linux and a Windows operating system please see Windows and Arch Dual Boot.

Single root partition

This scheme is the simplest; it is quick to setup but lacks flexibility and security. Two simple possibilities are:

  • One partition for root and one partition for swap
  • Just a single root partition without swap.

Discrete partitions

There are several advantages for using discrete partitions 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.

Mount points

The following mount points are possible choices for separate partitions, you can make your decision based on actual needs.

/ (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.

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.

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

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.

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

The /home directory contains user-specific configuration files (the so-called "dot files"). Optionally, it can also hold any type of media (videos, music, etc), and if you use Wine, the games/programs will be installed in ~/.wine/ by default. So please take this into account if you chose to create a separate home partition.

While keeping it on a separate partition can be useful in case you reinstall, some prefer to start fresh (because that's usually the reason for a reinstall), instead of reusing old, and possibly deprecated or problematic, configuration files. The main advantage is that, in very rare cases, if the root partition becomes too full, it will not impact your web browser, media player, torrent client, etc. They will keep working uninhibited, and will keep saving new changes to their setting files or to their cache.

A home partition can also be shared with other installed Linux distributions, but this is not recommended because of possible incompatibilities between user-specific configuration files. The only exception is if each distribution has its own user dir on the shared home partition.

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 variable data such as spool directories and files, administrative and logging data, pacman's cache, the ABS tree, etc. 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.

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.

/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.

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

  • fdisk — Terminal partitioning tools included in Linux.
https://www.kernel.org/ || util-linux
  • cfdisk — Terminal partitioning tool written with ncurses 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.
  • gdiskGPT version of fdisk.
http://www.rodsbooks.com/gdisk/ || gptfdisk
  • cgdiskGPT version of cfdisk.
http://www.rodsbooks.com/gdisk/ || gptfdisk
  • GNU Parted — Terminal partitioning tool.
http://www.gnu.org/software/parted/parted.html || parted
  • GParted — Graphical tool written in GTK.
http://gparted.sourceforge.net/ || gparted
  • Partitionmanager — Graphical tool written in QT.
http://sourceforge.net/projects/partitionman/ || partitionmanagerAUR
  • QtParted — Similar to Partitionmanager, available in AUR.
http://qtparted.sourceforge.net/ || qtpartedAUR

Partition Alignment

High-level Overview

Proper partition alignment is essential for optimal performance and longevity. The key to alignment is partitioning to (at least) the EBS (erase block size) of the SSD.

Note: The EBS is largely vendor specific; a Google search on the model of interest would be a good idea! The Intel X25-M for example is thought to have an EBS of 512 KiB, but Intel has yet to publish anything officially to this end.
Note: If one does not know the EBS of one's SSD, use a size of 512 KiB. Those numbers are greater or equal than almost all of the current EBS. Aligning partitions for such an EBS will result in partitions also aligned for all lesser sizes. This is how Windows 7 and Ubuntu "optimize" partitions to work with SSD.

If the partitions are not aligned to begin at multiples of the EBS (512 KiB for example), aligning the file system is a pointless exercise because everything is skewed by the start offset of the partition. Traditionally, hard drives were addressed by indicating the cylinder, the head, and the sector at which data was to be read or written. These represented the radial position, the drive head (= platter and side) and the axial position of the data respectively. With LBA (logical block addressing), this is no longer the case. Instead, the entire hard drive is addressed as one continuous stream of data.

Using GPT - Modern Method

GPT is an alternative, contemporary partitioning style. It is intended to replace the old Master Boot Record (MBR) system. GPT has several advantages over MBR, which has quirks dating back to MS-DOS times. With recent developments to the formatting tools fdisk (MBR) and gdisk (GPT), it is equally easy to use GPT or MBR and get maximum performance.

Choosing between GPT and MBR

The choice basically boils down to this:

  • If using GRUB Legacy as the bootloader, one must use MBR. See #Using MBR - Legacy Method.
  • To dual-boot with Windows, one must use MBR. See #Using MBR - Legacy Method.
    • A special exception to this rule: dual-booting Windows Vista/7 64 bit, and using UEFI instead of BIOS, one must use GPT.
  • If none of the above apply, choose freely between GPT and MBR. Since GPT is more modern, it is recommended in this case.

Gdisk Usage Summary

The GPT-able tool equivalent to fdisk, gdisk, can perform partition alignment automatically on a 2048 sector (or 1024KiB) block size base which should be compatible with the vast majority of SSDs if not all. GNU parted also supports GPT, but is less user-friendly for aligning partitions. A summary of the typical usage of gdisk:

  • Install gdisk through the gptfdisk package from the extra repository.
  • Start gdisk against your SSD.
  • If the SSD is brand new or if wanting to start over, create a new empty GUID partition table (aka GPT) with the Template:Keypress command.
  • Create a new partition with the Template:Keypress command (primary type/1st partition).
  • Assuming the partition is new, gdisk will pick the highest possible alignment. Otherwise, it will pick the largest power of two that divides all partition offsets.
  • If choosing to start on a sector before the 2048th gdisk will automatically shift the partition start to the 2048th disk sector. This is to ensure a 2048-sectors alignment (as a sector is 512B, this is a 1024KiB alignment which should fit any SSD NAND erase block).
  • Use the +x{M,G} format to extend the partition x megabytes or gigabytes, if choosing a size that is not a multiple of the alignment size (1024kiB), gdisk will shrink the partition to the nearest inferior multiple.
  • Select the partition's type id, the default, Linux/Windows data (code 0700), should be fine for most use. Press Template:Keypress to show the codes list. If planning to use LVM select Linux LVM (8e00).
  • Assign other partitions in a like fashion.
  • Write the table to disk and exit via the Template:Keypress command.
  • Create the filesystems as usual.
Warning: If planning to use the GPT partitioned SSD as a boot-disk on a BIOS based system (most systems except Apple computers and some very rare motherboard models with Intel chipset) one may have to create, preferably at the disk's beginning, a 2 MiB partition with no filesystem and with the partition type as BIOS boot or bios_grub partition (gdisk type code EF02) for booting from the disk using GRUB. For Syslinux, one does not need to create a separate 2 MiB bios_grub partition, but one needs to have separate /boot partition and enable Legacy BIOS Bootable partition attribute for that partition (using gdisk). See GPT for more information.
Warning: GRUB legacy does not support GUID partitioning scheme, users must use burg, GRUB or Syslinux.
Warning: If planning to dual boot with Windows (XP, Vista or 7) do NOT use GPT since they do NOT support booting from a GPT disk in BIOS systems! Users need to use the legacy MBR method described below for dual-boot in BIOS systems! This limitation does not apply if booting in UEFI mode and using Windows Vista (64bits) or 7 (64bits). For 32-bit Windows Vista and 7, and 32 and 64-bit Windows XP, users need to use MBR partitioning and boot in BIOS mode only.

Using MBR - Legacy Method

Using MBR, the utility for editing the partition table is called fdisk. Recent versions of fdisk have abandoned the deprecated system of using cylinders as the default display unit, as well as MS-DOS compatibility by default. The latest fdisk automatically aligns all partitions to 2048 sectors, or 1024 KiB, which should work for all EBS sizes that are known to be used by SSD manufacturers. This means that the default settings will give you proper alignment.

Note that in the olden days, fdisk used cylinders as the default display unit, and retained an MS-DOS compatibility quirk that messed with SSD alignment. Therefore one will find many guides around the internet from around 2008-2009 making a big deal out of getting everything correct. With the latest fdisk, things are much simpler, as reflected in this guide.

Fdisk Usage Summary

  • Start fdisk.
  • If the SSD is brand new, create a new empty DOS partition table with the Template:Keypress command.
  • Create a new partition with the Template:Keypress command (primary type/1st partition).
  • Use the +xG format to extend the partition x gigabytes.
  • Change the partition's system id from the default type of Linux (type 83) to the desired type via the Template:Keypress command. This is an optional step should the user wish to create another type of partition for example, swap, NTFS, LVM, etc. Note that a complete listing of all valid partition types is available via the Template:Keypress command.
  • Assign other partitions in a like fashion.
  • Write the table to disk and exit via the Template:Keypress command.

When finished, users may format their newly created partitions with mkfs.x /dev/sdXN where x is the filesystem, X is the drive letter, and N is the partition number. The following example will format the first partition on the first disk to ext4 using the defaults specified in /etc/mke2fs.conf:

# mkfs.ext4 /dev/sda1
Warning: Using the mkfs command can be dangerous as a simple mistake can result in formatting the WRONG partition and in data loss! TRIPLE check the target of this command before hitting the Enter key!

See also