Linux disk partition (gdisk, fdisk, parted) Additional- partprobe

Pankaj kushwaha
7 min readJun 19, 2020

--

The MBR partition table is partitioned using the fdisk command, the GPT partition table is partitioned using the gdisk command, and parted can be used for partitions of any partition type disk. MS-DOS format is one of the MBR

Important:The following commands should be executed as root

1. gdisk
1.1. Function: used for partition or query of GPT partition table format disk

  1. 2. Format
gdisk device file name

1.3. How to use

The first step: use the gdisk command to select a device to operate, and then the cursor will stay waiting for operation

Step 2: Enter the relevant command options to operate. If you don’t know the command options, you can enter? For help query

  1. 4. Command options
d: delete a partition
n: add a partition
p: print out the partition table (commonly used)
q: Exit gdisk directly without saving the partition
w: leave gdisk after save partition operation
L: Display the Code of the file system . Linux is probably 8200, 8300, 8e00, etc. Windows almost uses 0700

5. Matters needing attention

Note the difference between q and w: q will not save the user’s related operations to exit, w will save the related operations and then exit
The device name used in the command should not be a partition of a disk device: because the disk partition is for the entire disk, not for a partition.

For example: gdisk /dev/sda1 will be wrong

Do not deal with the partition being used . Otherwise, the consequences will be serious
Partitions without mounted directories will not be displayed when viewed with the p option
6. Use the p option to view the information status of the disk

Disk: Disk file name/sector number/total capacity
Logical sector size: the size of a single sector
Disk identifier (GUID): Disk identifier
Number: Partition number, 1 means /dev/sda1, etc..
Start: the starting sector number position of each partition
End: the end sector number position of each partition, and the total capacity of the partition can be calculated from start
Size: the capacity of the partition
Code: The ID of the possible file system in the partition. Linux is 8300 and swap is 8200. However, this Code is just a hint, it may not really represent the file system in the partition
Name: the name of the file system, etc.

Note

As can be seen from the above figure: the starting position number of the total sector is 34, the last position number of the total sector is 83886046, but the fifth partition only uses 83884031
When a new partition is added, the new sector start number is taken at the position where the end sector number of the previous partition is increased by size.
7. Use the n option to add a new partition

Steps: The following steps have default values, you can enter them manually, or you can press Enter to use the default values

Step 1 : Enter n optionsStep 2 : Enter the number of the new partition, the default is 2Step 3 : Enter the starting position number of the new partition, the default is 79693824. Or use [+-][size][unit] to enter the size of the new partition (for example: +1G, +500M, etc. Step 4 will be omitted)Step 4 : Enter the end position number of the new partition, the default is 79695871. Or use [+-][size][unit] to enter the size of the new partitionStep 5 : Enter the Code or GUID of the file system used by the partition (if you forget, you can use the L option to query). The default is Linux (8300)

After performing the above five steps, but not yet saved, use the w option to save. Enter Y (Agree)

Enter p query after adding the partition

8. Use the d option to delete a partition

Method: After entering d, select the partition number to delete

Use the w option to save. Enter Y (agree) to exit later

Second, fdisk
1. Function: Used for partition or query of MBR partition table format disk

2. Format

gdisk device file name

3. How to use

The usage is almost the same as the gdisk method, and many options are the same. Only the query command is different (gdisk enters m for query help)
4. Matters needing attention

The MBR partition table will gradually be eliminated in the future because the capacity of the disk is getting larger and larger. However, there is still space available for old systems and small disks
fdisk sometimes uses cylinders as the smallest unit of partition, gdisk uses sectors by default
5. Examples

The operations of fdisk and gdisk are almost the same, but the way of querying commands is different (gdisk enters m for query help). So no more demo

Three, parted
1. Function:

Can be used to view the partition status of the disk
Can be used to partition/delete disks
Can be used for type conversion of disk partition table (can be achieved, but it is not recommended, it is very dangerous)

2. Format

Syntax: parted [device file name] [command [parameter]]
Commands and parameters

Print disk partition information: parted device file name print
Newly added partition: parted device file name mkpart [primary/logical/Extended] [file system format] partition start memory location partition end memory location
Delete partition: parted device file name rm partition number
Disk partition table type conversion: parted device file name mklabel partition table format

3. Matters needing attention

Parted can add a new partition directly with a single command, which is more convenient to use
Parted can change MBR to GPT partition table, or change GPT to MBR partition table, but this operation is very dangerous

4. Various examples

View the partition information of the /dev/sda disk: parted /dev/sda print

Model: the template name of the disk (manufacturer)Disk: the total capacity of the diskSector size: the size of each logical/physical sector of the diskPartition Table: The format of the partition table (MBR/GPT). msdos belongs to the MBR formatNumber: represents the partition number of this disk. 1 means /dev/sda1… and so onStart: The starting position of this block partition is in the memory of this diskEnd: How much memory is on the end of this block partitionSize: the size of this block partitionFile system: the type of file systemThe above Start and End units are different, in order to unify the unit, you can use the following command: consistent use of MB display parted /dev/sda unit mb print

Conversion of partition table format: change the disk of MBR partition table format to GPT partition table format

Note: This operation is very dangerous. After this step, the file system may be damaged and cannot be restored, so only the commands are introduced, and no more demonstrations.

parted /dev/sda mklabel gpt
③Add a partition /dev/sda6 under /dev/sda: the size is 0.5GB, and format it into the vfat file system format

The partition number of the newly added partition is automatically determined by the system.

parted /dev/sda mkpart primary fat32 36.0GB 36.5GB
Format: Assume that the newly added partition of the system is /sda6
mkfs -t vfat /dev/sda6
The setup period is automatically mounted to the /data/win directory
Add in the /etc/fstab file: UUID=UUID of /dev/sda6 above /data/win vfat defaults 0 0
Update the /etc/fstab file: mount -a
④ Delete the above /sda6 partition
parted /dev/sda rm 6

Partprobe
1. Function: Update partition table information of Linux kernel

2. Format

partprobe [-s]

If you do not add -s, the screen will not display information, it is recommended to add
2. Use scenarios

After you use gdisk/fdisk/parted to add/delete a partition above, when you use lsblk or cat /proc/partitions to view the disk information, you find that the information about the disk addition/deletion has not been updated. Therefore, this disk is in use and the system cannot be loaded into the new partition table. At this time, you can use the partprobe command to update.

Thanks for reading this post, if you like, follow me up.

--

--

Pankaj kushwaha

Database/System Administrator | DevOPS | Cloud Specialist | DevOPS