Este conteúdo não está disponível no idioma selecionado.
Chapter 4. Getting started with partitions
Disk partitioning divides a disk into multiple logical areas so each can be handled independently. The hard disk keeps location and size data in a partition table. The OS sees each partition as a separate logical disk, allowing read and write operations individually.
For an overview of the advantages and disadvantages to using partitions on block devices, see the Red Hat Knowledgebase solution What are the advantages and disadvantages to using partitioning on LUNs, either directly or with LVM in between?.
4.1. Creating a partition table on a disk with parted Copiar o linkLink copiado para a área de transferência!
Create a partition table on a disk to define the layout for organizing storage space into separate, manageable sections. This essential setup step enables you to create multiple partitions for different purposes and operating systems.
Formatting a block device with a partition table deletes all data stored on the device.
Procedure
Start the interactive
partedshell:parted block-device
# parted block-deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Determine if there already is a partition table on the device:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the device already contains partitions, they will be deleted in the following steps.
Create the new partition table:
(parted) mklabel table-type
(parted) mklabel table-typeCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace table-type with with the intended partition table type:
-
msdosfor MBR gptfor GPTFor example to create a GPT table on the disk, use:
(parted) mklabel gpt
(parted) mklabel gptCopy to Clipboard Copied! Toggle word wrap Toggle overflow The changes start applying after you enter this command.
-
View the partition table to confirm that it is created:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow Exit the
partedshell:(parted) quit
(parted) quitCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2. Viewing the partition table with parted Copiar o linkLink copiado para a área de transferência!
Display the partition table of a block device to see the partition layout and details about individual partitions. You can view the partition table on a block device by using the parted utility. For more information, see the parted(8) man page on your system.
Procedure
Start the
partedutility. For example, the following output lists the device/dev/sda:parted /dev/sda
# parted /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow View the partition table:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Switch to the device you want to examine next:
(parted) select block-device
(parted) select block-deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow For a detailed description of the print command output, see the following:
Model: ATA SAMSUNG MZNLN256 (scsi)- The disk type, manufacturer, model number, and interface.
Disk /dev/sda: 256GB- The file path to the block device and the storage capacity.
Partition Table: msdos- The disk label type.
Number-
The partition number. For example, the partition with minor number 1 corresponds to
/dev/sda1. StartandEnd- The location on the device where the partition starts and ends.
Type- Valid types are metadata, free, primary, extended, or logical.
File system-
The file system type. If the
File systemfield of a device shows no value, this means that its file system type is unknown. Thepartedutility cannot recognize the file system on encrypted devices. Flags-
Lists the flags set for the partition. The most commonly used flags are
boot,root,swap,hidden,raid,lvm, orlba. For a complete list of flags, seeparted(8)man page on your system.
4.3. Creating a partition with parted Copiar o linkLink copiado para a área de transferência!
Create new disk partitions to organize storage space efficiently and separate different types of data. This fundamental storage management task allows you to set up dedicated areas for system files, user data, and swap space.
Prerequisites
- A partition table on the disk.
- If the partition you want to create is larger than 2 TiB, format the disk with the GUID Partition Table (GPT).
The required partitions are swap, /boot/, and / (root).
Procedure
Start the
partedutility:parted block-device
# parted block-deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow View the current partition table to determine if there is enough free space:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Resize the partition in case there is not enough free space.
From the partition table, determine:
- The start and end points of the new partition.
- On MBR, what partition type it should be.
Create the new partition:
For MS-DOS:
(parted) mkpart part-type fs-type start end
(parted) mkpart part-type fs-type start endCopy to Clipboard Copied! Toggle word wrap Toggle overflow For GPT:
(parted) mkpart part-name fs-type start end
(parted) mkpart part-name fs-type start endCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Replace part-type with
primary,logical, orextended. This applies only to the MBR partition table. - Replace name with an arbitrary partition name. This is required for GPT partition tables.
-
Replace fs-type with
xfs,ext2,ext3,ext4,fat16,fat32,hfs,hfs+,linux-swap,ntfs, orreiserfs. The fs-type parameter is optional. Note that thepartedutility does not create the file system on the partition. Replace start and end with the sizes that determine the starting and ending points of the partition, counting from the beginning of the disk. You can use size suffixes, such as
512MiB,20GiB, or1.5TiB. The default size is in megabytes.For example, to create a primary partition from 1024 MiB until 2048 MiB on an MBR table, use:
(parted) mkpart primary 1024MiB 2048MiB
(parted) mkpart primary 1024MiB 2048MiBCopy to Clipboard Copied! Toggle word wrap Toggle overflow The changes start applying after you enter the command.
-
Replace part-type with
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:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow Exit the
partedshell:(parted) quit
(parted) quitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the kernel recognizes the new partition:
cat /proc/partitions
# cat /proc/partitionsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.4. Setting a partition type with fdisk Copiar o linkLink copiado para a área de transferência!
You can set a partition type or flag by using the fdisk utility.
Prerequisites
- A partition on the disk.
Procedure
Start the interactive
fdiskshell:fdisk block-device
# fdisk block-deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow View the current partition table to determine the minor partition number:
Command (m for help): print
Command (m for help): printCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see the current partition type in the
Typecolumn and its corresponding type ID in theIdcolumn.Enter the partition type command and select a partition by using its minor number:
Command (m for help): type Partition number (1-3, default 3): 2
Command (m for help): type Partition number (1-3, default 3): 2Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Display the partition types:
For disks with an MBR partition table:
Hex code or alias (type L to list all codes): L
Hex code or alias (type L to list all codes): LCopy to Clipboard Copied! Toggle word wrap Toggle overflow For disks with a GPT partition table:
Partition type or alias (type L to list all): L
Partition type or alias (type L to list all): LCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Set the partition type:
For disks with an MBR partition table:
Hex code or alias (type L to list all codes): 8e
Hex code or alias (type L to list all codes): 8eCopy to Clipboard Copied! Toggle word wrap Toggle overflow For disks with a GPT partition table:
Partition type or alias (type L to list all): 44
Partition type or alias (type L to list all): 44Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Write your changes and exit the
fdiskshell:Command (m for help): write The partition table has been altered. Syncing disks.
Command (m for help): write The partition table has been altered. Syncing disks.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify your changes:
fdisk --list block-device
# fdisk --list block-deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.5. Resizing a partition with parted Copiar o linkLink copiado para a área de transferência!
Using the parted utility, extend a partition to use unused disk space, or shrink a partition to use its capacity for different purposes. For more information, see the parted(8) man page on your system.
Prerequisites
- Back up the data before shrinking a partition.
- If the partition you want to create is larger than 2 TiB, format the disk with the GUID Partition Table (GPT).
- If you want to shrink the partition, first shrink the file system so that it is not larger than the resized partition.
XFS does not support shrinking.
Procedure
Start the
partedutility:parted block-device
# parted block-deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow View the current partition table:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow From the partition table, determine:
- The minor number of the partition.
The location of the existing partition and its new ending point after resizing.
ImportantWhen resizing a partition, ensure there is enough unallocated space between the end of the partition being resized and either the beginning of the next partition, or the end of the disk if it is the last partition. If there is not sufficient space,
partedwill return an error. However, it is best to verify the available space before attempting to resize to avoid partition overlap.
Resize the partition:
(parted) resizepart 1 2GiB
(parted) resizepart 1 2GiBCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Replace 1 with the minor number of the partition that you are resizing.
-
Replace 2 with the size that determines the new ending point of the resized partition, counting from the beginning of the disk. You can use size suffixes, such as
512MiB,20GiB, or1.5TiB. The default size is in megabytes.
View the partition table to confirm that the resized partition is in the partition table with the correct size:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow Exit the
partedshell:(parted) quit
(parted) quitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the kernel registers the new partition:
cat /proc/partitions
# cat /proc/partitionsCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Optional: If you extended the partition, extend the file system on it as well.
4.6. Removing a partition with parted Copiar o linkLink copiado para a área de transferência!
Remove unnecessary disk partitions to reclaim storage space for other purposes. This operation helps you reorganize disk layout, eliminate unused partitions, and optimize storage utilization on your system.
Procedure
Start the interactive
partedshell:parted block-device
# parted block-deviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Replace block-device with the path to the device where you want to remove a partition: for example,
/dev/sda.
-
Replace block-device with the path to the device where you want to remove a partition: for example,
View the current partition table to determine the minor number of the partition to remove:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove the partition:
(parted) rm partition-number
(parted) rm partition-numberCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Replace partition-number with the partition number you want to remove.
The changes start applying as soon as you enter this command.
Verify that you have removed the partition from the partition table:
(parted) print
(parted) printCopy to Clipboard Copied! Toggle word wrap Toggle overflow Exit the
partedshell:(parted) quit
(parted) quitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the kernel registers that the partition is removed:
cat /proc/partitions
# cat /proc/partitionsCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Remove the partition from the
/etc/fstabfile, if it is present. Find the line that declares the removed partition, and remove it from the file. Regenerate mount units so that your system registers the new
/etc/fstabconfiguration:systemctl daemon-reload
# systemctl daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantTo remove a partition mentioned in
/proc/cmdlineor that is part of an LVM, see Configuring and managing logical volumes, and thedracut(8)andgrubby (8)man pages on your system.