Translation(s): English - Italiano - Português (Brasil)
Disk partitioning is the creation of one or more storage regions (called partitions), so that each region can be managed separately. It is typically the first step of preparing a newly installed disk, before any file system is created. The disk stores the information about the partitions' locations and sizes in an area known as the partition table that the operating system reads before any other part of the disk. Each partition then appears to the operating system as a distinct "logical" disk that uses part of the actual disk.
Contents
Tools
The following software allows working on disk partitions:
gnome-disk-utility - manage and configure disk drives and media
gparted - GNOME partition editor
Parted - command-line disk partition manipulator
gdisk - collection of command-line partitioning utilities for GPT-format partitions
fdisk - collection of command-line partitioning utilities for legacy MBR-format partition
LVM - manage file systems in a flexible way
Partitioning schemes
There are several ways that partitions can be defined, the most common are called GPT and MBR. You can find which one you are using by running fdisk -l
GPT format partitions
Computers that use UEFI, and some that use a BIOS can use a partitioning format called Globally Unique Identifier (GUID) Partition Table (GPT).
MBR format partitions
Older computers that boot using a BIOS use a partitioning format called MBR. This format was designed for MS-DOS and only supports disks smaller than 2TB.
MBR defines three types of partitions:
- Primary partition: the first 4 partitions on a disk are called primary partitions. To have more than 4 partitions, an extended partition may be used.
- Extended partition: a primary partition can be designated as an extended partition, and then used to define multiple logical partitions. There can be only one extended partition on a disk. This allows the disk to contain more than 4 partitions.
- Logical partition: a partition that resides in an extended partition.
For an end user there is no practical difference between a (non-extended) primary partition and the logical partitions: each can contains a filesystem (like ext4 or vfat) or be used as LVM physical volume, etc. The extended partition itself is not usable, as its space is used to define the logical partitions.
The primary partitions are always numbered 1 to 4.
Here is some annotated output from lsblk on an MBR-partitioned SATA disk.
The disk has a primary partition sda1 used for /boot
The extended partition is sda2. Note it is very small, just 1k
The logical partition sda5 is used as an LVM physical volume
The main partitions used for the system are all in LVM. Note that /boot can also be in LVM but many old documents recommend against this.
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 223.6G 0 disk ├─sda1 8:1 0 243M 0 part /boot # primary (/boot, not in LVM on this machine) ├─sda2 8:2 0 1K 0 part # extended: container for other partitions └─sda5 8:5 0 223.3G 0 part # logical: used as a LVM physical volume ├─vg-root 254:0 0 23.3G 0 lvm / # LVM logical volume for / ├─vg-var 254:1 0 12.3G 0 lvm /var # LVM logical volume for /var ├─vg-swap_1 254:2 0 7.9G 0 lvm [SWAP] # LVM logical volume for swap ├─vg-tmp 254:3 0 1.9G 0 lvm /tmp # etc ├─vg-home 254:4 0 151G 0 lvm /home └─vg-srv 254:5 0 25G 0 lvm /srv
Changing partitions
LVM
If you're not sure what size to make your partitions, using LVM is a good idea as it makes it easier to resize partitions. This is supported by the DebianInstaller. In LVM, each logical volume is treated as if it were a separate disk in which you make partitions.
The LVM page has examples of how to grow or shrink a logical volume.
Updating configuration files after changing partitions
Another advantage of LVM is that you can refer to logical volumes by name, which means you can make changes without needing to update configuration files.
If you change the underlying disk partitions in a way that changes the partition numbers then you may need to update a number of configuration files in /etc:
The fstab file may need to be updated to refer to the new names (it is recommended to refer to filesystems by their UUID, which is less likely to change)
If the partition number for a swap partition changed, the /etc/initramfs-tools/config.d/resume needs to be edited. This file indicates the partition, usually swap, used for hibernation. update-initramfs -u needs to be ran afterwards to update the initramfs.
If you change the /boot or root partition you should run update-grub so that Grub2 knows how to boot the system
Note that even unaltered partitions may change. For example, a partition that used to be identified as /dev/sda7 may change to /dev/sda6 if an earlier partition is deleted.
See Also
SoftwareRAID on Debian
External Links
http://www.tldp.org/HOWTO/Partition/index.html The Linux partition ?HowTo.
http://www.salingfamily.net/trav/linux/lost_partition.html Recovering a Lost Partition Table
