Using fdisk utility for partitioning on Linux

Anıl Aşık
adessoTurkey
Published in
6 min readJun 30, 2022

Command Syntax: (fdisk /dev/xxx)(xxx = the drive designation with which you wish to work. Example: sda, sdb)

Common rules for creating multiple partitions

  1. Enter the command line to initiate the dsik utility
  2. Press N to create a new partition
  3. Enter N to create a primary partition.
  4. Choose 1 for the partition number.
  5. Choose which cylinder you want to start the partition at or Press “Enter” to select the default. Enter either the last cylinder of the partition or the size. When entering the size, use the following format: +<size>M or +<size>K (plus is mandatory).
  6. Press N to create another partition.
  7. Choose E for extended.
  8. Choose 2 for the partition number. As with DOS, the extended partition should take up the remaining space on the drive. At this point, it is best to choose the default beginning cylinder.
  9. Press Enter to choose the default end cylinder
  10. Press N to create another partition. (optional)
  11. Enter the first cylinder or press “Enter” to select the default.
  12. Enter either the last cylinder of the partition or the size.

Repeat to use the remaining space on the drive. When you are finished, press W to write the changes and then Q to exit.

  1. Log in to the system with superuser (root) and start fdisk:

fdisk /dev/sda

2. Type m to see all help hints:

3. To see partition table type p and press Enter:

4. To create new partition (number 1) type n and press Enter:

5. First three partitions shall be primary, so type p and press Enter:

6. Choose the number of partition (in this case — 1), press Enter:

7. To specify first sector, which is by default — 1, just press Enter. To specify last sector type desired size of partition in form +<size>M (in megabytes) or +<size>G (in gigabytes), then press Enter

Example: +100M

8. To look at the current partition table type p and press Enter:

Here you can see partition name (/dev/sda1), first and last sectors of partition (2048 and 206847), quantity of blocks (102400), partition type ID (83) and name of the partition type (Linux)

9. You need to add the bootable (active) flag to the first partition. To perform it type a, press Enter, then choose partition number (1) and press Enter again.

10. Look at the partition table (type p and press Enter):

The bootable flag appeared (*) for the partition /dev/sda1.

11. To create secondary primary partition (for root / of main OS) type n, then p again and press Enter:

Then choose 2 and press Enter. The first sector is now 206848(next to the last one from previous partition).

Type desired size of partitin (+<size>M or +<size>G), then press Enter.

12. Look at the partition table (type p and press Enter):

Now we have 2 primary partitions.

13. Create third primary partition (for Rescue system):

Partition table will look like this:

14. Now create the fourth partition. The extended one. Type n, Enter, e (extended), Enter, then 4, Enter. To specify first sector, press Enter. To specify last sector, press Enter again without specifying any size. In this case, the last sector of partition should be the very last one of the entire disk.

The partition table will look like this:

15. Now create the fifth partition, which will be the first logical partition within extended one. Type n, press Enter. Note that fdisk will no more ask what type of partition you want to choose, because all of following partitions will be of only one type which is logical.

Type desired size of partition (+<size>M or +<size>G) the same way you were doing in previous steps, then press Enter.

16. This should be the swap partition, so you need to change its ID. To do it type t, press Enter, then specify the number of partition which ID you want to change (in this case type 5 and press Enter)

To look at all list of IDs, type L and press Enter. Find needed type of System (Linux swap / Solaris) in this list and corresponding number of ID (in this case 82). Type this number and press Enter.

17. The partition table should now look like this:

18. Create the sixth partition (for /var):

19. Create seventh and the last partition (for /forfun). Last sector should be the very last one on the disk. Just press Enter without specifying its size.

20. Now the partitioning process is almost finished. To look at partition table type p and press Enter. Check whether all partitions and its sizes are correct or not. If all is OK write the changes to disk partition table by typing w and pressing Enter. After this, all changes will be saved.

If you want to correct partitions or size (before saving to disk) delete partitions from reverse order (type d, press Enter, specify number of deleted partition, press Enter)

For examle: d Enter 7 Enter, d Enter 6 Enter etc. Then create deleted partition again with corrected size.

--

--