Linux Administration Bootcamp
Installing and Connecting to a Linux System
Intermediate Linux Skills
Linux Boot Process and System Logging
Disk Management in Linux
LVM - The Logical Volume Manager
User Management in Linux
Networking With Linux
Shell Scripting with Linux
Command Line Kung Fu
In this course, you will learn how to install a Linux system and connect to it, whether that be on Mac or Windows.
In this lesson, you will learn how to use the fdisk utility to create GPT and MBR partition tables. If you're unsure what disks are available run fdisk -l to display a list of devices. This particular server has three disks. The first disk listed here, dev/sdb, does not contain any partition information so it hasn't been partitioned. You can see that this disk, dev/sda, has two partitions, dev/sda1 and dev/sda2. The third disk, like dev/sdb, dev/sdc does not have a partition table.
Let's work with dev/sdb. Let's ask fdisk for some help by typing in m and hitting enter. Let's create a new MBR partition table. We will create three primary partitions. The first one will be a one-gigabyte swap partition. The second will be a 20-gigabyte partition, and the third and final partition will use the remaining space on the disk. To create a new MBR partition, just type n and hit enter. It's going to guide us through a series of questions here and we'll just answer them along the way. We're going to create a primary partition, so you can either hit p and hit enter, or the default answer is p so you can just hit enter. This is our first partition on this disk so we'll just hit enter to create partition number one. And then we'll start at the default. And then here we're going to enter +1G for one gigabyte in size.
You can see that it says, "Partition one of type Linux and of size one gigabyte is set." So the default partition type created by fdisk is Linux, and it's represented by the number 83. To change the partition type we can type in t. And to get a list of partitions we'll type in l. And then we'll see that partition 83, or type 83, is Linux, but we want this to be a swap partition. So 82 represents Linux swap. So we'll enter in 82 here. Let's continue on with the next partition. n for a new partition. This is going to be a primary partition. And the default is two, so this is our second partition. We'll accept that. We'll accept the defaults again.
Now, we wanted a 20-gigabyte partition, so we'll do +20G. And then finally we want the third partition. We'll just do another one here with n. Primary again. Three. And this will set it to the very end of the disk if we accept the default. So we want the remaining space in this third partition, so I'm just going to hit enter. To view the current partition table we'll just use p. We'll just make sure we have everything set the way we want to. And you can see that dev/sdb1, our first primary partition, is of type 82 Linux swap, and that our other two partitions are Linux. So we'll go ahead and accept this and we'll write this to disk with the w command.
Let's create a GPT partition table with fdisk. We'll do this on dev/sdc. Just p to print to show you that there is no partition table currently assigned here. And to create a GPT partition table, we'll just do g. And then to create a new partition, we will type in the letter n for new. And you can see there the partition number range is from 1 to 128, and we're going to just create one. And we're going to accept the defaults here. Just use the first available sector and the last sector here. We're just going to use one big partition. Then we'll print and then you can see that we have one Linux partition that takes up the entire disk. Go ahead and write that with w, and we should be done.
Now if we look back at our fdisk -l command, we should see all these partitions that we've just created. dev/sdb has the three partitions we created. dev/sda is unmodified. It still has the two partitions it had when we started. And dev/sdc here has our one big partition.
QA: A world-leading tech and digital skills organisation
We help many of the world’s leading companies to build their tech and digital capabilities via our range of world class training courses, reskilling bootcamps, work-based learning programmes and Apprenticeships. We also create bespoke solutions, blending elements to meet specific client needs.