User:Carlduff/Partition tables

From ArchWiki

Prepare the storage devices

In this step, the storage devices that will be used by the new system will be prepared. Read Partitioning for a more general overview.

Warning: Partitioning will destroy existing data. Before proceeding, you must backup all data that needs to be preserved.

Identify the devices

The first step is identify the devices where the new system will be installed. The following command will show all the available devices:

# lsblk

This will list all devices connected to your system along with their partition schemes, including that used to host — and boot — the live Arch installation media (e.g. a USB drive). Not all devices listed will therefore be viable or appropriate mediums for installation. To filter out inappropriate results, the command can optionally be amended as follows:

# lsblk | grep -v "rom\|loop\|airoot"

Devices (e.g. hard disks) will be listed as sdx, where x is a lower-case letter starting from a for the first device (sda), b for the second device (sdb), and so on. Existing partitions on those devices will be listed as sdxY, where Y is a number starting from 1 for the first partition, 2 for the second, and so on. In the example below, only one device is available (sda), and that device uses only one partition (sda1):

sda               8:0    0    80G  0 disk 
└─sda1            8:1    0    80G  0 part

The sdxY convention will be used in the examples provided below for partition tables, partitions, and file systems. As they are just examples, it is important to ensure that any necessary changes to device names, partition numbers, and/or partition sizes (etc.) are made. Do not just blindly copy and paste the commands.

If the existing partition scheme needs not be changed, skip to #Create filesystems, otherwise continue reading the following section.

Partition table types

If you are installing alongside an existing installation (i.e. dual-booting), a partition table will already be in use. If the devices are not partitioned, or the current partitions table or scheme needs to be changed, you will first have to determine the partition tables (one for each device) in use or to be used.

Warning: If Arch and Windows are dual-booting from same device, then Arch must follow the same firmware boot mode and partitioning combination already used, or Windows will fail to boot. See Windows and Arch Dual Boot#Important information for more details.

There are two types of partition table:

  • MBR: Intended for BIOS systems (also referred to as "msdos")
  • GPT: Intended for UEFI systems

Any existing partition table can be identified with the following command for each device:

# parted /dev/sdx print

Partitioning tools

For each device to be partitioned, a proper tool must be chosen according to the partition table to be used. Several partitioning tools are provided by the Arch installation medium, including:

  • parted: MBR and GPT
  • fdisk, cfdisk, sfdisk: MBR and GPT
  • gdisk, cgdisk, sgdisk: GPT
Warning: Using a partitioning tool that is incompatible with your partition table type will likely result in the destruction of that table, along with any existing partitions/data.
Tip: The devices may also be partitioned before booting the Arch installation media, possibly using alternative live systems with other partitioning tools. For example beginners might find it easier to use a graphical partitioning tool such as GParted, which is also provided as a live CD and works with both MBR and GPT partition tables.

Using parted in interactive mode

All the examples provided below make use of parted, as it can be used for both BIOS/MBR and UEFI/GPT. It will be launched in interactive mode, which simplifies the partitioning process and reduces unnecessary repetition by automatically applying all partitioning commands to the specified device.

In order to start operating on a device, execute:

# parted /dev/sdx

You will notice that the command-line prompt changes from a hash (#) to (parted): this also means that the new prompt is not a command to be manually entered when running the commands in the examples.

To see a list of the available commands, enter:

(parted) help

When finished, or if wishing to implement a partition table or scheme for another device, exit from parted with:

(parted) quit

After exiting, the command-line prompt will change back to #.

Create new partition table

Warning: If dual-booting with an existing installation of Windows on a UEFI/GPT system, do not erase the partition table. Doing so will destroy all existing data on the device, including the UEFI partition with the Windows .efi stub required to boot it.

If you want to start from scratch — and do not intend to keep existing partitions on a device — its existing partition table can be completely erased. This simplifies the creation of new partitions and avoids problems if converting disks from MBR to GPT or vice versa. Use the following command:

# sgdisk --zap-all /dev/sdx

Now open each device whose partition table must be (re)created with:

# parted /dev/sdx
Warning: MBR is designed specifically for use with BIOS systems, and GPT is designed for UEFI. It is not recommended for less experienced users to break this convention as both have features and/or limitations that may be incompatible with your hardware (e.g. MBR cannot cope with devices larger than 2 TiB). If for any reason you do not wish to follow this convention, see and for more information and possible workarounds.

To then create a new MBR/msdos partition table for BIOS systems, use the following command:

(parted) mklabel msdos

To create a new GPT partition table for UEFI systems instead, use:

(parted) mklabel gpt

Partition schemes

You can decide the number and size of the partitions the devices should be split into, and which directories will be used to mount the partitions in the installed system (also known as mount points). The mapping from partitions to directories is the partition scheme, which must comply with the following requirements:

  • At least a partition for the / (root) directory must be created.
  • Depending on the motherboard's firmware interface, the chosen #Partition table type, and in some cases also the chosen boot loader, the following additional partitions will must be created:

In the examples below it is assumed that a new and contiguous partitioning scheme is applied to a single device. Some optional partitions will also be created for the /boot and /home directories: see also Arch filesystem hierarchy for an explanation of the purpose of the various directories; if separate partitions for directories like /boot or /home are not created, these will simply be contained in the / partition. Also the creation of an optional partiton for swap space will be illustrated.

If not already open in a parted interactive session, open each device to be partitioned with:

# parted /dev/sdx

The following command will be used to create partitions:

(parted) mkpart part-type fs-type start end
  • part-type is one of primary, extended or logical, and is meaningful only for MBR partition tables.
  • fs-type is one of the supported file systems listed in the manual. The partition will be properly formatted in #Create filesystems.
  • start is the beginning of the partition from the start of the device. It consists of a number followed by a unit, for example 1M means start at 1MiB.
  • end is the end of the partition from the start of the device (not from the start value). It has the same syntax as start, for example 100% means end at the end of the device (use all the remaining space).
Warning: It is important that the partitions do not overlap each other: if you do not want to leave unused space in the device, make sure that each partition starts where the previous one ends.
Note: parted may issue a warning like:
Warning: The resulting partition is not properly aligned for best performance.
In this case, read Partitioning#Partition alignment and follow GNU Parted#Alignment to fix it.

The following command will be used to flag the partition that contains the /boot directory as bootable:

(parted) set partition boot on
  • partition is the number of the partition to be flagged (see the output of the print command).

BIOS/MBR examples

For a minimum single primary partition using all available disk space, the following command would be used:

(parted) mkpart primary ext3 1M 100%
(parted) set 1 boot on

In the following instance, a 20Gib / partition will be created, followed by a /home partition using all the remaining space:

(parted) mkpart primary ext3 1M 20G
(parted) set 1 boot on
(parted) mkpart primary ext3 20G 100%

In the final example below, separate /boot (100MiB), / (20Gib), swap (4GiB), and /home (all remaining space) partitions will be created:

(parted) mkpart primary ext3 1M 100M
(parted) set 1 boot on
(parted) mkpart primary ext3 100M 20G
(parted) mkpart primary linux-swap 20G 24G
(parted) mkpart primary ext3 24G 100%

UEFI/GPT examples

In every instance, a special bootable EFI System Partition is required.

Warning: If dual-booting with an existing installation of Windows on a UEFI/GPT system, the existing UEFI partition must not be recreated. Doing so will destroy the Windows .efi stub required to boot it.

If creating a new EFI System Partition, use the following commands (the recommended size is 512MiB):

(parted) mkpart ESP fat32 1M 513M
(parted) set 1 boot on

The remaining partition scheme is entirely up to you. For one other partition using 100% of remaining space:

(parted) mkpart primary ext3 513M 100%

For separate / (20GiB) and /home (all remaining space) partitions:

(parted) mkpart primary ext3 513M 20.5G
(parted) mkpart primary ext3 20.5G 100%

And for separate / (20GiB), swap (4Gib), and /home (all remaining space) partitions:

(parted) mkpart primary ext3 513M 20.5G
(parted) mkpart primary linux-swap 20.5G 24.5G
(parted) mkpart primary ext3 24.5G 100%

Create filesystems

Once the partitions have been created, each must be formatted with an appropriate file system. All available partitions on the intended installation device can be listed with the following command:

# lsblk /dev/sdx

With the exceptions noted below, it is recommended to use the ext4 file system:

# mkfs.ext4 /dev/sdxY
Warning: If dual-booting with an existing installation of Windows on a UEFI/GPT system, do not re-format the UEFI partition. Doing so will destroy all existing data on that partition, including the Windows .efi stub required to boot it.
  • If a new UEFI system partition has been created on a UEFI/GPT system, it must be formatted with a fat32 or vfat32 file system. Failure to do so will result in an unbootable installation:
# mkfs.vfat -F32 /dev/sdxY
  • If you plan to use GRUB on a BIOS/GPT system, please note that the BIOS Boot Partition has nothing to do with the /boot mountpoint. It will be used by GRUB directly. Do not create a filesystem on it, and do not mount it.

Activate swap

If a swap partition has been created, it must be set up and activated with:

# mkswap /dev/sdxY
# swapon /dev/sdxY

See Swap#Swap file for an alternative.

Mount the partitions

Note: Swap partitions must not be mounted here.

The / (root) partition must be mounted first: this is because any directories such as /boot or /home that have separate partitions will have to be created in the root file system. The /mnt directory of the live system will be used to mount the root partition, and consequently all the other partitions will stem from there. If the root partition's name is sdxR, do:

# mount /dev/sdxR /mnt

Once the / partition has been mounted, any remaining partitions may be mounted in any order. The general procedure is to first create the mount point, and then mount the partition to it. If using a separate /boot partition:

# mkdir -p /mnt/boot
# mount mount /dev/sdxB /mnt/boot
Note: Using /boot is recommended also for mounting the EFI System Partition on UEFI/GPT system. See EFISTUB and related articles for alternatives.

If using a separate /home partition:

# mkdir -p /mnt/home	
# mount mount /dev/sdxH /mnt/home

Once all the remaining partitions, if any, have been mounted, the devices are ready to install Arch.