https://wiki.archlinux.org/api.php?action=feedcontributions&user=Jmuzz&feedformat=atomArchWiki - User contributions [en]2024-03-28T16:59:19ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Partitioning&diff=291406Partitioning2014-01-03T00:27:01Z<p>Jmuzz: Grammar fix</p>
<hr />
<div>[[Category:File systems]]<br />
[[ar:Partitioning]]<br />
[[es:Partitioning]]<br />
[[it:Partitioning]]<br />
[[ja:Partitioning]]<br />
[[ru:Partitioning]]<br />
[[zh-cn:Partitioning]]<br />
{{Related articles start}}<br />
{{Related|fstab}}<br />
{{Related|LVM}}<br />
{{Related|Swap}}<br />
{{Related|File Systems}}<br />
{{Related articles end}}<br />
''Partitioning'' a hard drive allows one to logically divide the available space into sections that can be accessed independently of one another.<br />
<br />
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 creating 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. <br />
<br />
Each partition should be formatted to a [[File Systems|file system type]] before being used.<br />
<br />
== Partition table ==<br />
<br />
Partition information is stored in the partition table; today, there are 2 main formats in use: the classic [[Master Boot Record]], and the modern [[GUID Partition Table]]. The latter is an improved version that does away with several limitations of MBR style.<br />
<br />
=== Master Boot Record ===<br />
{{Wikipedia|Master boot record}}<br />
<br />
MBR originally only supported up to 4 partitions. Later on, extended and logical partitions were introduced to get around this limitation.<br />
<br />
There are 3 types of partitions:<br />
<br />
* Primary<br />
* Extended<br />
** Logical<br />
<br />
'''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.<br />
<br />
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.<br />
<br />
=== GUID Partition Table ===<br />
{{Wikipedia|GUID Partition Table}}<br />
<br />
There is only one type of partition, '''primary'''. The amount of partitions per disk or RAID volume is unlimited.<br />
<br />
=== Btrfs Partitioning ===<br />
{{Wikipedia|Btrfs}}<br />
<br />
Btrfs can occupy an entire data storage device and replace the [[MBR]] or [[GPT]] partitioning schemes. See the [[Btrfs#Partitioning|Btrfs Partitioning]] instructions for details.<br />
<br />
=== Choosing between GPT and MBR ===<br />
<br />
[[GUID Partition Table]] (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. <br />
<br />
The choice basically boils down to this:<br />
* If using GRUB legacy as the bootloader, one must use MBR.<br />
* To dual-boot with Windows (both 32-bit and 64-bit) using Legacy BIOS, one must use MBR.<br />
* To dual-boot Windows 64-bit using [[UEFI]] instead of BIOS, one must use GPT.<br />
* If none of the above apply, choose freely between GPT and MBR. Since GPT is more modern, it is recommended in this case.<br />
* It is recommended to use always GPT for [[Unified Extensible Firmware Interface|UEFI]] boot as some UEFI firmwares do not allow UEFI-MBR boot.<br />
<br />
== Partition scheme ==<br />
<br />
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]].<br />
<br />
{{Warning|Don't forget to allow space for the boot-loader. This was not an issue for MBR and GRUB-Legacy, but more modern schemes may require a special, small partition.}}<br />
<br />
=== Single root partition ===<br />
<br />
This scheme is the simplest and should be enough for most use cases. A [[swapfile]] can be created and easily resized as needed. It usually makes sense to start by considering a single {{ic|/}} partition and then separate out others based on specific use cases like RAID, encryption, a shared media partition, etc. Note that installing GRUB on a BIOS system partitioned with GPT requires an additional BIOS boot partition. <br />
<br />
=== Discrete partitions ===<br />
<br />
Separating out a path as a partition allows for the choice of a different filesystem and mount options. In some cases like a media partition, they can also be shared between operating systems.<br />
<br />
=== Mount points ===<br />
<br />
The following mount points are possible choices for separate partitions, you can make your decision based on actual needs.<br />
<br />
==== Root partition ====<br />
<br />
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.<br />
<br />
The {{ic|/}} partition or root partition is necessary and it is the most important. The other partitions can be replaced by it.<br />
<br />
{{Warning|Directories essential for booting (except for {{ic|/boot}}) '''must''' be on the same partition as {{ic|/}} or mounted in early userspace by the [[initramfs]]. These essential directories are: {{ic|/etc}} and {{ic|/usr}} [http://freedesktop.org/wiki/Software/systemd/separate-usr-is-broken].}}<br />
<br />
==== /boot ====<br />
<br />
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).<br />
<br />
A separate {{ic|/boot}} partition is needed if installing a software RAID0 (stripe) system.<br />
<br />
==== /home ====<br />
<br />
The {{ic|/home}} directory contains user-specific configuration files, caches, application data and media files.<br />
<br />
Separating out {{ic|/home}} allows {{ic|/}} to be re-partitioned separately, but note that you can still reinstall Arch with {{ic|/home}} untouched even if it isn't separate - the other top-level directories just need to be removed, and then pacstrap can be run.<br />
<br />
You should not share home directories between users on different distributions, because they use incompatible software versions and patches. Instead, consider sharing a media partition or at least using different home directories on the same {{ic|/home}} partition.<br />
<br />
==== /var ====<br />
<br />
The {{ic|/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.<br />
<br />
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}}.<br />
<br />
{{Note|{{ic|/var}} contains many small files. The choice of file system type should consider this fact if a separate partition is used.}}<br />
<br />
==== /tmp ====<br />
<br />
This is already a separate partition by default, by virtue of being mounted as ''tmpfs'' by systemd.<br />
<br />
==== Swap ====<br />
<br />
A [[swap]] partition provides memory that can be used as virtual RAM. A [[Swap#Swap file|swap file]] should be considered too, as they have almost no performance overhead compared to a partition but are much easier to resize as needed. A swap partition can ''potentially'' be shared between operating systems, but not if hibernation is used.<br />
<br />
==== How big should my partitions be? ====<br />
<br />
{{Note|The below are simply recommendations; there is no hard rule dictating partition size.}}<br />
The size of the partitions depends on personal preference, but the following information may be helpful:<br />
<br />
; /boot - 200 MB : It requires only about 100 MB, but if multiple kernels/boot images are likely to be in use, 200 or 300 MB is a better choice.<br />
; / - 15-20 GB : It traditionally contains 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.<br />
; /var - 8-12 GB : It 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, {{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. 8-12 GB on a desktop system should be sufficient for {{ic|/var}}, depending on how much software will be installed.<br />
; /home - [varies] : It 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.<br />
; swap - [varies] : 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.<br />
: {{Note|If you plan to hibernate into a swap partition/file, you should see [[Suspend and Hibernate#About swap partition/file size]].}}<br />
; /data - [varies] : One can consider mounting a "data" partition to cover various files to be shared by all users. Using the {{ic|/home}} partition for this purpose is fine as well.<br />
<br />
{{Note|If available, an extra 25% of space added to each filesystem will provide a cushion for future expansion and help protect against fragmentation.}}<br />
<br />
== Partitioning tools ==<br />
<br />
*{{App|fdisk|Terminal partitioning tools included in Linux.|https://www.kernel.org/|{{Pkg|util-linux}}}}<br />
*{{App|cfdisk|Terminal partitioning tool written with ncurses libraries.|https://www.kernel.org/|{{Pkg|util-linux}}}}<br />
{{Warning|The first partition created by ''cfdisk'' starts at sector 63, instead of the usual 2048. This can lead to reduced performance on SSD and advanced format (4k sector) drives. It will cause problems with [[GRUB2#msdos-style error message|GRUB2]]. GRUB legacy and Syslinux should work fine.}}<br />
*{{App|gdisk|[[GPT]] version of fdisk.|http://www.rodsbooks.com/gdisk/|{{Pkg|gptfdisk}}}}<br />
*{{App|cgdisk|GPT version of cfdisk.|http://www.rodsbooks.com/gdisk/|{{Pkg|gptfdisk}}}}<br />
*{{App|GNU Parted|Terminal partitioning tool.|http://www.gnu.org/software/parted/parted.html|{{pkg|parted}}}}<br />
*{{App|[[GParted]]|Graphical tool written in GTK.|http://gparted.sourceforge.net/|{{Pkg|gparted}}}}<br />
*{{App|Partitionmanager|Graphical tool written in QT.|http://sourceforge.net/projects/partitionman/|{{AUR|partitionmanager}}}}<br />
*{{App|QtParted|Similar to Partitionmanager, available in [[AUR]].|http://qtparted.sourceforge.net/|{{AUR|qtparted}}}}<br />
<br />
== SSD partition alignment ==<br />
{{Accuracy|Manual SSD alignment may no longer be necessary. See discussion for more information.|Talk:Partitioning#SSD Alignment?}}<br />
'''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.<br />
<br />
{{Note|The EBS is largely vendor specific.}}<br />
<br />
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.<br />
<br />
== Using GPT - modern method ==<br />
<br />
=== Gdisk usage summary===<br />
<br />
Using GPT, the utility for editing the partition table is called ''gdisk''. It 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. The environment provided by the Arch install ISO includes the ''gdisk'' command. If you need it later on in the installed system, ''gdisk'' is available in the {{Pkg|gptfdisk}} package.<br />
<br />
A summary of the typical usage of ''gdisk'':<br />
<br />
* Start ''gdisk'' against your drive as root (''disk-device'' may be e.g. {{ic|/dev/sda}}):<br />
# gdisk ''disk-device''<br />
* If the drive is brand new or if you are wanting to start over, create a new empty GUID partition table with the {{ic|o}} command.<br />
* Create a new partition with the {{ic|n}} command (primary type/1st partition).<br />
* 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.<br />
* 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).<br />
* Use the {{ic|+''x''&#123;M,G&#125;}} format to extend the partition ''x'' mebibytes or gibibytes, if choosing a size that is not a multiple of the alignment size (1024kiB), ''gdisk'' will shrink the partition to the nearest inferior multiple. For example, if you want to create a 15GiB partition, you would enter {{ic|+15G}}<br />
* Select the partition's type id, the default, {{ic|Linux filesystem}} (code {{ic|8300}}), should be fine for most use. Press {{ic|L}} to show the codes list. If planning to use LVM select {{ic|Linux LVM}} ({{ic|8e00}}).<br />
* Assign other partitions in a like fashion.<br />
* Write the table to disk and exit via the {{ic|w}} command.<br />
* Format the new partitions with a [[File Systems|file system]].<br />
<br />
{{Note|<br />
* To boot from a GPT partitioned disk on a BIOS based system you have to create, preferably at the disk's beginning, a [[GRUB2#GUID Partition Table (GPT) specific instructions|BIOS boot 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]], you do not need to create this {{ic|bios_grub}} partition, but you need to have separate {{ic|/boot}} partition and enable {{ic|Legacy BIOS Bootable partition}} attribute for that partition (using ''gdisk'').<br />
* [[GRUB Legacy]] does not support GPT, users must use [[BURG]], GRUB or Syslinux.<br />
}}<br />
{{Warning|If planning to dual boot with Windows in BIOS mode (this is the only available option for 32-bit Windows versions and 64-bit Windows XP), do '''not''' use GPT since Windows does '''not''' support booting from a GPT disk in BIOS systems. You will need to use MBR partitioning and boot in BIOS mode, as described below. This limitation does not apply if booting a modern 64-bit Windows version in UEFI mode.}}<br />
<br />
== Using MBR - legacy method ==<br />
<br />
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.<br />
<br />
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.<br />
<br />
=== Fdisk usage summary ===<br />
<br />
* Start ''fdisk'' against your drive as root (''disk-device'' may be e.g. {{ic|/dev/sda}}):<br />
# fdisk ''disk-device''<br />
* If the drive is brand new or if you are wanting to start over, create a new empty DOS partition table with the {{ic|o}} command.<br />
* Create a new partition with the {{ic|n}} command (primary type/1st partition).<br />
* Use the {{ic|+''x''G}} format to extend the partition ''x'' gibibytes. For example, if you want to create a 15GiB partition, you would enter {{ic|+15G}}<br />
* Change the partition's system id from the default type of Linux ({{ic|type 83}}) to the desired type via the {{ic|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 {{ic|l}} command.<br />
* Assign other partitions in a like fashion.<br />
* Write the table to disk and exit via the {{ic|w}} command.<br />
* Format the new partitions with a [[File Systems|file system]].<br />
<br />
== See also ==<br />
<br />
*[[Ext4#Creating ext4 partitions from scratch|Creating ext4 partitions from scratch]]<br />
*[[Wikipedia:Disk partitioning]]<br />
*[http://www.novell.com/coolsolutions/feature/19350.html Manually Partitioning Your Hard Drive with fdisk]</div>Jmuzz