From the course: Linux System Engineer: Advanced Disk Systems and System Backup

List, create, and delete partitions on MBR and GPT disks

From the course: Linux System Engineer: Advanced Disk Systems and System Backup

Start my 1-month free trial

List, create, and delete partitions on MBR and GPT disks

- Let's create some partitions now. Power up your VM, log in, and open a terminal. The first thing we want to do is get a list of drives in the system. We can do this by catting proc partitions. In a terminal type in cat space slash proc slash partitions and hit enter. This information comes from the colonel directly. This is the list of drives and partitions that the colonel currently recognizes. Another tool that's useful in determining the available drives is LSBLK. Type in L-S-B-L-K and hit enter. This also gives a visual of the drives and their partitions, or logical volumes. We can see that slash dev slash sda has partitions on it, and their mounted as slash boot and slash but slash dev slash sdb is bare. This is one of our new drives. If you want to read the partition table for all drives directly, you can use fdisk dash l type in clear then type in sudo space fdisk space dash L and hit enter. Type in your password if prompted. This will show all partitions on all drives, also note that this shows what type of a partition table a drive might have. To get a list of all partitions on slash disk slash sdb we will need to specify it. Type in clear, then type in sudo space fdisk space dash l space slash dev slash sdb and hit enter. To partition our bare slash dev slash sdb drive we can use one of three commands. Fdisk, gdisk or parted. Legacy Systems uses a BIOS to boot the machine and the BIOS stores it's partition table in the MBR or Master Boot Record. Fdisk is the Legacy tool for BIOS MBR based systems. MBR systems have a limitation of four real partitions otherwise known as primary partitions and accessible size of two Terabytes. If you want more partitions one of these four needs to be an extended partition. Inside this extended partition we can then create logical partitions. All primary and extended partitions will be numbered one through four. All logical partitions will be numbered five and higher. There are actually three different fdisk programs. Fdisk, Sfdisk and Cfdisk. Fdisk is the interactive tool. Sfdisk is command line only and non-interactive for scripts. All arguments are provided on the command line and carried out. Cfdisk is a curses based application that's somewhat visual. Newer systems use UEFI and with that GUID partition table or GPT. As of this recording, experimental GPT support has been added to fdisk. Gdisk however, was designed for GPD partitions. With GPT you can have virtually unlimited partitions, but some programs only support 128. GPT has an accessible size of 18 exabytes. Also gdisk stores a BIOS partition table along with a GBT table so even non-uefi systems can use the GBT table. Like fdisk we have three gdisk programs. Gdisk, sgdisk for scripts and cgdisk for a curses interface. For this video we'll be using gdisk. Another tool is parted which has additional power which we'll cover in another video. Older version also formatted partitions and repaired them. Some of this functionality has been removed. Let's run gdisk with slash dev slash sdb. Type in clear and then type in sudo space gdisk space slash dev slash sdb and hit enter. Let's press question mark for the Help Menu and hit enter. We can see that we can press N to add a new partition, D to delete a partition, and P to print the partition. Lastly, we can press W to write the partition table. Let's create a new partition by pressing N and hitting enter. For the partition number take the default and hit enter again. For the first sector hit enter again. For the ending sector, I'm going to specify a size. Type in plus 500 capital M for Megabytes. This will create a 500 megabyte partition and leave the rest of the disk free. Hit enter for the default partition ID of 8300. To verify, press P to print your partition table. Lastly, we'll press W to write the partition table and hit enter. Note that until we press W no changes have been saved to the disk. If we decide not to change the partition table we can exit and everything will remain the same. Press Y to commit. Now cap proc partitions to see if the Colonel recognizes the partition. Type in clear and then type in cat space slash proc slash partitions and hit enter. Here we see the sdb 1 partition we just created. We can also use gdisk slash L to list the partitions in the partition table. Type in sudo space gdisk space dash L space slash dev slash sdb and hit enter. Note that gdisk dash L isn't a system wide like fdisk dash l. It only list partitions on the specified drive. Also note, that catting proc partitions shows a partition table according to the Colonel. Gdisk dash L shows what has been saved on the drive in the partition table. TheSe two things are not the same. If for some reason the Colonel doesn't update it's record of the partitions in RAM there will be a discrepancy between what's in proc partitions and what is on the actual disk. Generally the partitioning tool warns you of this. In some cases we can just run the part prob command to force the Colonel to reload the partition table. Type in clear and type in sudo space part probe and hit enter. If you don't get any output from part probe then the partitions tables are in sync. Lastly, let put a file system on a new partition. Type in sudo space mkfs space dash t space ext 4` ` space slash dev slash sdb1 and hit enter. Now this partition is ready to be mounted.

Contents