Linux Partitions

A guide for how to show, create and resize partitions

Create Partition [^1]

This tutorial is copied from the tutorial from Satish Tiwary slashroot.in. Don't give me any credit.

We will use the program fdisk for the following steps.

Show Partitions

This following command will show all partition and the disk (with information about the size).

fdisk -l

Create new partition

Select the disk you want to use, here we are using /dev/sda

fdisk /dev/sda
  1. Then hit n for creating a new partition.

  2. Select the partition number (just hit enter for the default)

  3. Select the first sector, just hit enter

  4. Then select the last sector. Here you can set the size of the partition. We are going to +100G which is 100 Gigabyte.

  5. Then use insert w to write the changes, save them and exit

Use partprobe to update the changes of the partition table without restart.

partprobe

Adding a file system for the partition

We will create the file system ext4 for the partition /dev/sda5

mkfs.ext4 /dev/sda5

Mount the partition to a directory

Create a new partition

mkdir /new

Mount the parition (/dev/sda5) to the new directory.

mount /dev/sda5 /new

To check if it's mounted you can use df -h

Make the file system permanent

Append to the file /etc/fstab

/etc/fstab
/dev/sda5     /new     ext4    defaults  0 0

Resize Partitions [^2]

This tutorial is copied from the tutorial from Søren Løvborg askubuntu.com. Don't give me any credit.

This is only to enlarge the parition, shrinking won't work

Delete the to resized partition

We first delete the partition you want to resize.

We select the device, where the partition is located, in this example it is /dev/sda.

fdisk /dev/sda

Please copy the sector information about the parition. Then you can start the new created parition where the deleted one started. This means no data will be lost.

  1. Type p to show the partitions

  2. Type d to delete a partition

  3. Select the partition number you want to resize (for example the last one)

Then we are going to create the partition again

  1. Type n to create a new partition

  2. Type select the partition number (for us we just hit enter)

  3. Select the first sector (hit enter for default)

  4. Select the last sector (here you can increase or decrease the partition)

  5. remove the ext signature

  6. Type w to save the changes

Use partprobe to update the changes

partprobe

Resize the file system

Resize the file system, for this example we use the resized partition /dev/sda3

resize2fs /dev/sda3

List of resources

Last updated