Skip to main content
LPIC-1 Exam 101

102.1 Design hard disk layout Part 1

By January 19, 2014No Comments
Weight 2
Description Candidates should be able to design a disk partitioning scheme for a Linux system.

Key Knowledge Areas:

  • Allocate filesystems and swap space to separate partitions or disks.
  • Tailor the design to the intended use of the system.
  • Ensure the /boot partition conforms to the hardware architecture requirements for booting.
  • Knowledge of basic features of LVM.

The following is a partial list of the used files, terms and utilities:

  • / (root) filesystem.
  • /var filesystem.
  • /home filesystem.
  • swap space.
  • mount points.
  • partitions.

Creating partitions


To access data on disks generally we first create partitions, some disks will have just a single partition others disks may have 2 or more. The amount and size of partitions that can be on a single disk are controlled by the type of disk, this is known as the disk label. In this example we create swap partitions but the principal and tools are the same.

Linux has the ability to use swap partitions or swap files. If you have available disk space that is currently un-partitioned then you may create a swap partition and format is as a swap file system; if you have no available un-partitioned disk space and can’t add in more local or SAN (Storage Area Network) based disks then swap files may be used.  It is likely that swap files will not perform as well as a dedicated partition as the partition is designed for swap usage and not regular files.

To create partitions we have at least two tools to choose from at the command line:

  • fdisk(/sbin/fdisk)
  • parted(/sbin/parted)

Fdisk can only be used interactively whereas parted can be used both interactively and with arguments provided at the command line.  If using parted on a new disk that is currently un-partitioned then we must initialize the MBR or Master Boot Record. The MBR can have the type of traditional MSDOS which is 32 bit or type GPT (GUID Partition Table) which is 64 bit. Other disk types or labels exist; however are not used in Linux

To boot from a GPT based disk your will need a UEFI computer rather than a standard BIOS, but there is no issue using a GPT disk as second disk in a BIOS based server or PC.

  • MSDOS MBR: Even though we are not using MS-DOS as an OS it has lent its name to a type of Master Boot Record. This traditional MBR takes 512B of disk space and allows for 4 primary partitions, one of which could be an extended partition. The maximum partition size is limited to 2.2 TB coming from a 32 bit system ( 2^31 KiB = 2TiB )
  • GPT: The newer GUID Partition Table MBR allows for much larger partition sizes: 8 ZiB or 9.2 Billion TB, GPT is 64 bit so we can use 2^63 KiB = 8ZiB

Fdisk is designed to work with msdos MBRs and support for gpt MBR is experimental. Parted will work with both.

 

 

In the example we are assuming we have a new up-partitioned second local hard drive /dev/sdb. To initialize the disk with an MSDOS MBR we use the following command as root:

parted /dev/sdb mklabel msdos

NOTE: Always take care when running partitioning tools as your data can be destroyed with one simple typo!

Now we have initialized the partition table we are ready to create a partition on the disk. The partition information is stored in the first 512 bytes of the disk. We will create a swap partition as partition 1 on this disk; when creating a partition we need to provide a starting point in MB and ending point in MB. We can’t start at the beginning of the disk as that is used by the MBR, is we are using a GPT disk we need more space than just the 512B. It is usually safe to start at 1MB on a new un-partitioned disk. We can also use pated to display disk free information:

parted /dev/sdb print free

Parted reports that we can start on 32.3kB but as we use units of 1 MB we will start at 1.  We set the partition ID to 82 with the argument linux-swap, the kernel does not really care about the partition type or id but is used more to identify the purpose of the partition. Of course, parted and fdisk can create partitions for standard file-systems as well as swap in which case we can omit the partition type of linux-swap.  To create the partition and display free space after we can use the following commands:

parted -a cylinder /dev/sdb mkpart primary linux-swap 1 101
parted /dev/sdb print free




The video for part 1 of this objective will step you through MSDOS and GPT label disks and using parted.