13.2. Creating a Partition
Procedure 13.1. Creating a Partition
- Before creating a partition, boot into rescue mode, or unmount any partitions on the device and turn off any swap space on the device.
# parted /dev/sdaReplace /dev/sda with the device name on which you want to create the partition.
- View the current partition table to determine if there is enough free space:
(parted)If there is not enough free space, you can resize an existing partition. For more information, see Section 13.5, “Resizing a Partition with fdisk”.From the partition table, determine the start and end points of the new partition and what partition type it should be. You can only have four primary partitions, with no extended partition, on a device. If you need more than four partitions, you can have three primary partitions, one extended partition, and multiple logical partitions within the extended. For an overview of disk partitions, see the appendix An Introduction to Disk Partitions in the Red Hat Enterprise Linux 7 Installation Guide.
- To create partition:
mkpart part-type name fs-type start endReplace part-type with with primary, logical, or extended as per your requirement.Replace name with partition-name; name is required for GPT partition tables.Replace fs-type with any one of btrfs, ext2, ext3, ext4, fat16, fat32, hfs, hfs+, linux-swap, ntfs, reiserfs, or xfs; fs-type is optional.Replace start end with the size in megabytes as per your requirement.For example, to create a primary partition with an ext3 file system from 1024 megabytes until 2048 megabytes on a hard drive, type the following command:
mkpart primary 1024 2048
NoteIf you use the
mkpartfscommand instead, the file system is created after the partition is created. However,
parteddoes not support creating an ext3 file system. Thus, if you wish to create an ext3 file system, use
mkpartand create the file system with the
mkfscommand as described later.The changes start taking place as soon as you press Enter, so review the command before executing to it.
- View the partition table to confirm that the created partition is in the partition table with the correct partition type, file system type, and size using the following command:
(parted)Also remember the minor number of the new partition so that you can label any file systems on it.
- Exit the parted shell:
- Use the following command after parted is closed to make sure the kernel recognizes the new partition:
13.2.1. Formatting and Labeling the Partition
Procedure 13.2. Format and Label the Partition
- The partition does not have a file system. To create the
ext4file system, use:
WarningFormatting the partition permanently destroys any data that currently exists on the partition.
- Label the file system on the partition. For example, if the file system on the new partition is
/dev/sda6and you want to label it
e2label /dev/sda6 "Work"By default, the installation program uses the mount point of the partition as the label to make sure the label is unique. You can use any label you want.
- Create a mount point (e.g.
/work) as root.
13.2.2. Add the Partition to
- As root, edit the
/etc/fstabfile to include the new partition using the partition's UUID.Use the command
blkid -o listfor a complete list of the partition's UUID, or
blkid devicefor individual device details.In
- The first column should contain
UUID=followed by the file system's UUID.
- The second column should contain the mount point for the new partition.
- The third column should be the file system type: for example,
- The fourth column lists mount options for the file system. The word
defaultshere means that the partition is mounted at boot time with default options.
- The fifth and sixth field specify backup and check options. Example values for a non-root partition are
- Regenerate mount units so that your system registers the new configuration:
- Try mounting the file system to verify that the configuration works:
- If you need more information about the format of
/etc/fstab, see the fstab(5) man page.