Home Wiki > SDB:Partitioning
Sign up | Login

SDB:Partitioning

tagline: From openSUSE

Icon-cleanup.png This article is in need of attention because it does not follow our wiki guidelines.
If you want to contribute, please read the rules for this wiki and if you have any questions, don't hesitate to contact the wiki team, we are more then willing to help you! :-)
Icon-expand.png This article is a stub!
This article needs to be expanded. You are welcome to help in line with the Style Guidelines.

Tested on openSUSE Recommended articles Related articles
Icon-checked.png

Icon-manual.png Icon-help.png

Partitioning Schemes

Linux requires at least one partition, assigned to /, which is the root filesystem. But it is common to have separate partitions for particular directories, like /home. The different partitions you create, are connected to the / partition, by mounting them to mountpoints that you choose. The partitioning scheme in Linux depends on the purpose of your installation. For a standard, general use installation, you can have a /, a /boot, a /home and a swap partition. However, there are many different setups for different purposes, so here is a list of some directories that can be a separate partition:

/boot - The partition mounted on /boot contains the operating system kernel, along with files used during the bootstrap process. For most users, a 500MB boot partition is sufficient.

swap - Should normally be twice the size of the RAM installed on your system.

/home - It’s useful to put users’ home directories on a separate partition. Even if the root partition is corrupted or destroyed, user data has a good chance of remaining intact. Conversely, the system can continue to operate even after a user’s /home directory fills up.

/usr - Holds the bulk of the system’s libraries and data. Creating /usr as a separate partition makes updating the system easier if you need to reinstall the system from the beginning.

/opt - If you install third-party products, you may want to have /opt in a separate partition. This will keep the third-party apps during system upgrades.

/srv - If you use your system as a server, create a /srv partition, since it contains the web and the FTP servers.

/tmp - Putting /tmp on a separate filesystem limits temporary files to a finite size and saves you from having to back them up.

/var - Since log files are kept in /var, it’s a good idea for it to be a separate disk partition. Leaving /var as part of a small root partition, makes it easy to fill the root and brings the machine to a halt.

Note: The filesystem structure may differ in different distributions, so you may need to consult the web site of the distribution of your choice, for details on usage of a specific directory. Here, the /srv directory is used in the openSUSE distribution, to serve web content. Other distributions, like Debian, Ubuntu, RHEL, use the /var/www directory for serving web content.


Partition Tables

MBR

MBR (Master Boot Record) lives in the first sector (512 bytes) of the Hard Drive. It consists of 3 parts:
1 - The bootloader, which resides in the first 446 bytes.
2 - The partition table resides in the next 64 bytes (4 entries of 16 bytes each, one entry for every primary partition).
3 - The last 2 bytes contain the boot record signature (55 AA).

MBR is limited to 2TB Drive size. You can have only 4 primary partitions, or 3 primary partitions and an extended partition, which you can partition further on, to your needs (up to 24 logical partitions). It is used in computers that have BIOS (Basic Input/Output System).

Partitioning under MBR

The partitioning tool used under MBR, is called fdisk.

Note: In order to perform this procedure, you need to have administrative permissions.

First, if you don’t know your drive name, you can list all drives in the system like this:

# fdisk -l

If you know your drive name, select it with fdisk , to edit its partitions:

# fdisk /dev/sdX
Welcome to fdisk (util-linux 2.28).                                   
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):

Note: There is no (sdX) device, but is used here conventionally. SATA drives are listed as /dev/sdX, for example /dev/sda, /dev/sdb, etc., and the partitions inside a drive, are listed as sda1, sda2, or sdb1, sdb2, and so on. IDE drives are listed as /dev/hdX, for example /dev/hda, /dev/hdb, etc., and the partitions inside an IDE drive, are listed as hda1, hda2, or hdb1, hdb2, and so on.

Once you are in the fdisk prompt, it is recommended that you first see the current partitions. In the example below is shown a 15 GiB USB, which contains two partitions, /dev/sdb1 and /dev/sdb2:

Command (m for help): p
Disk /dev/sdb: 15 GiB, 16131293184 bytes, 31506432 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc8e0e6ee

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1  *        0 1638399 1638400  800M  0 Empty
/dev/sdb2       13200   37775   24576   12M ef EFI (FAT-12/16/32)

If you want to delete a partition, type d. If you want to add a new partition, without touching the existing ones, type n. After pressing n, you can choose what partition type you want, primary (p) or extended (e). Than you enter the partition number (press Enter to accept the default). Next you can select the first sector of the partition (it is safe to accept the default, because fdisk selects the next sector that comes after the last partition in the disk). Than, for the last sector, accept the default if you want the partition to take all the remaining space on the disk, or specify the amount of space in sectors or KiB, MiB, GiB, etc. In the example shown, a primary partition is created and is assigned 5GiB of space.

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p

Using default response p.
Partition number (3,4, default 3): 
First sector (1638400-31506431, default 1638400): 
Last sector, +sectors or +size{K,M,G,T,P} (1638400-31506431, default 31506431): +5G

Created a new partition 3 of type 'Linux' and of size 5 GiB.

Now, if you want to change the partition type, you can do so by typing t. Than specify the number of the partition you want to change. Afterwards, specify the partition type. In the example, the partition no.3 is changed to Windows FAT32.

Command (m for help): t
Partition number (1-3, default 3): 
Partition type (type L to list all types): L

Partition type (type L to list all types): b

Changed type of partition 'Linux' to 'W95 FAT32'.

In this example, the remaining space is assigned to an extended partition. The procedure is similar with that of a primary partition. After creation, you can continue to add more logical partitions.

Command (m for help): n
Partition type
   p   primary (3 primary, 0 extended, 1 free)
   e   extended (container for logical partitions)
Select (default e): 

Using default response e.
Selected partition 4
First sector (12124160-31506431, default 12124160): 
Last sector, +sectors or +size{K,M,G,T,P} (12124160-31506431, default 31506431): 

Created a new partition 4 of type 'Extended' and of size 9.2 GiB.

Command (m for help): n
All primary partitions are in use.
Adding logical partition 5
First sector (12126208-31506431, default 12126208): 
Last sector, +sectors or +size{K,M,G,T,P} (12126208-31506431, default 31506431): +3.2G

Created a new partition 5 of type 'Linux' and of size 3.2 GiB.

Now, the partition table for the USB, looks like this:

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sdb1  *           0  1638399  1638400  800M  0 Empty
/dev/sdb2          13200    37775    24576   12M ef EFI (FAT-12/16/32)
/dev/sdb3        1638400 12124159 10485760    5G  b W95 FAT32
/dev/sdb4       12124160 31506431 19382272  9.2G  5 Extended
/dev/sdb5       12126208 18827263  6701056  3.2G 83 Linux

After finished creating partitions, you have to write the partition table to the disk, by typing w.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

If you see a message like the following: WARNING: Re-reading the partition table failed with error 16: Device or resource busy, the most likely reason is that a partition from the disk is still mounted. Unmount the partition (in this case /dev/sdb), and try running the following command to sync the disk partition table with the kernel:

# umount /dev/sdb
# partprobe /dev/sdb
Warning If you make a mistake partitioning your disk with fdisk, just type (q) to exit without saving your changes. If you are stuck in the middle of an operation, such as adding a partition, just complete that operation, and then type (q) after you see the command prompt (Command (m for help): q).

Now that the partitions are created and the partition table written to disk, the last step is to write a filesystem on those partitions. For this task, the mkfs command is used, together with the name of the filesystem (if you don't specify a filesystem, mkfs creates an ext2 filesystem by default). In this example, the two partitions (in this case /dev/sdb3 and /dev/sdb5) will be formatted, one as a FAT32 partition and the other as an ext4 partition.

# mkfs -t vfat /dev/sdb3
# mkfs -t ext4 /dev/sdb5

Note: A primary partition, is a partition used to boot an operating system. An extended partition, is a partition which holds logical partitions. A logical partition, is any partition beyond the 4(MBR)/128(GPT) primary partitions, which use space from an extended partition.


GPT (GUID)

Warning From this point and on, the article is still being edited, as it contains errors. You are not advised to follow the guide from here and on.

The GPT (GUID) partition table is stored in multiple locations on the disk. It’s called GUID Partition Table because every partition on your drive has a “globally unique identifier,” or GUID. GPT-based drives can be much larger, with size limits dependent on the operating system and its file systems. You can have up to 128 primary partitions and than, extended partitions. In the GPT partitioning, the backup partition table is stored at the end of the disk. GPT is used on computers that have UEFI (Unified Extensible Frimware Interface). On computers that have BIOS, GPT acts like MBR (BIOS sees GPT as a drive with a single MBR partition).

Partitioning under GPT

The partitioning tool used under MBR, is called gdisk.

Note: In order to perform this procedure, you need to have administrative permissions.

In this example, the 15GiB USB is used again. Currently, the USB contains an MBR partition table and has a single partition. The procedure of partitioning, is similar with that of the fdisk. First, it is recommended that you start by listing the drives, by typing gdisk -l, to check your drive name.

Note: If you try to list the drives on a system that has an MBR table, you may encounter an error.

GPT fdisk (gdisk) version 0.8.8

Problem opening -l for reading! Error is 2.
The specified file does not exist!

To get around this, just use fdisk to list your drives.

Than, select the drive with gdisk.

Note: In this case, the USB has an MBR partition table, so gdisk throws a warning! First, gdisk scans for partition tables. Below, the scan show that there is an MBR table.

Warning If you type w (write) in the command prompt, it will just convert the MBR table to GPT. This action is destructive and causes data loss, so first, you may want to backup any important data.
# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.8

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present


***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************


Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

Now, lets select the USB again, to create some partitions! In the example, the USB will have a single partition. To see a list of options, type ? and to create a new partition, type n. It is safe to accept the default first sector. For the last sector, you can specify the amount of space in KiB, MiB, GiB, (for example +2G, for 2GiB) etc. After that, type L, to specify the filesystem type. In this case, the selected code is 0700, which is an exFAT filesystem. Afterward type w to write the partition table (if you want to check the partition table first, type p) and quit gdisk.

# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.8

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-31506398, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-31506398, default = 31506398) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 0700                                                                                                                         
Changed type of partition to 'Microsoft basic data'                                                                                                                            

Command (? for help): p
Disk /dev/sdb: 31506432 sectors, 15.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 1D24896C-7AA3-4713-80E0-7DAEA507DD0F
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 31506398
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        31506398   15.0 GiB    0700  Microsoft basic data

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

Now, that the partitions are created and the partition table written to disk, the last step is to write a filesystem on those partition. For this task, the mkfs command is used, together with the name of the filesystem (in this case /dev/sdb1).

# mkfs.exfat /dev/sdb1
mkexfatfs 1.2.4
Creating... done.
Flushing... done.
File system created successfully.



Examples

Simple

Device Type Size Filesystem Mount
/dev/sda - 200gb - -
/dev/sda1 Primary 100mb EXT4 /boot
/dev/sda2 Primary 20gb EXT4 /
/dev/sda3 Primary 178.49gb EXT4 /home
/dev/sda4 Primary 1.5gb Swap swap

One thing to notice is that you could just as easily create just a single 200gb root--or "/"--partition and that would work just fine (provided you had enough physical memory to avoid requiring a swap partition).

The reasoning for this is that if, for example, you ever wanted to do a clean (re)installation of openSUSE, you wouldn't have much, if anything, to backup prior to formatting the root partition, as it is all stored in /home. On the other hand, if /home was on the root partition, this would probably require that you migrate /home to another physical volume prior to formatting the root partition. Creating a separate /boot in this scenario could be considered somewhat unnecessary, but usually is a good idea.


Dual Boot/Extended

Device Type Size Filesystem Mount
/dev/sda - 200gb - -
/dev/sda1 Primary 100gb ntfs-3g /windows/C
/dev/sda2 Primary 100mb EXT4 /boot
/dev/sda3 Extended (Primary) 20gb - -
/dev/sda5 Extended 20gb EXT4 /
/dev/sda6 Extended 78.49 GB EXT4 /home
/dev/sda7 Extended 1.5gb Swap swap

Note the device numbering, paying special attention to sda3.

/boot ends up being more than a few gigabytes from the beginning of the drive in this case. This, in general, is not a very good practice, and in some circumstances (on older/crappier BIOS's) will cause the system not to boot; YaST warn you about this too. However, on modern systems, the BIOS will still be able to find the boot partition, and you'll never notice the difference once you accept the partition scheme. For more information: SDB:Sandbox#Boot_Volume

This is where the advantages of separating /boot from the root partition become more evident. /boot, in most cases, needs to be located on a primary partition (and this is true of any operating system). It would be inconvenient (but still possible), in this case, to make a primary root partition, and keep /home and swap in the extended partition. This would make even more sense if you added in the a windows recovery partitions that are becoming more common in OEM Windows installations. If you had one of those systems with both a "system" partition (presumably containing the NTLDR) and a recovery system, you now only have room for one more primary partition.

It would also cause minimal disruption of your Windows partition to shrink it by 100mb instead of 20+gb to add a /boot partition, and then place the root partition on another physical volume, thereby avoiding having to reconfigure your BIOS to boot from the secondary PV as an additional bonus.


LVM

Creating a LVG really only makes sense when you're dealing with multiple physical volumes with which you want to span a single partition across. One of the most brilliant partition schemes I can think of would involve having one small, high-speed SSD, and two larger HDD's. The partition scheme would look thus:

Device Type Size Filesystem Mount Stripes
/dev/sda - 4gb - - -
/dev/sda1 Primary 100mb EXT4 /boot -
/dev/sda1 Primary 3.9gb Swap swap -
/dev/sdb - 200gb - - -
/dev/sdb1 LVM (Primary) 200gb - - -
/dev/sdc - 200gb - - -
/dev/sdc1 LVM (Primary) 200gb - - -
/dev/lvg1 LVG 400gb - - -
/dev/lvg1/root LV 20gb EXT4 / 2
/dev/lvg1/home LV 380gb EXT4 /home 2

Telling the LVM that you want two stripes on lvg1/root and lvg1/home on the same two physical volumes is just barely scratching the surface of the power of the LLVM.

Warning Critical: Do not add two (or more) physical partitions on the same physical volume to the same logical volume group.

The LVM physical partitions work somewhat similarly to how extended partitions work, not directly containing any filesystem information. The interesting thing here is that instead of creating another device on that parent node, an entirely new device node structure is created: /dev/lvg1 (you actually select what you want the device to be called, "lvg1" is completely arbitrary, as well as "lvg1/root" and "lvg1/home").

You don not need /boot to be on a physical volume not used in LVM. The following is just as valid:

Device Type Size Filesystem Mount Stripes
/dev/sda - 200gb - - -
/dev/sda1 Primary 100mb EXT4 /boot -
/dev/sda2 LVM (Primary) 199.9gb - - -
/dev/sdb - 200gb - - -
/dev/sdb1 LVM (Primary) 200gb - - -
/dev/lvg1 LVG 399.9gb - - -
/dev/lvg1/root LV 20gb EXT4 / 2
/dev/lvg1/home LV 379.8gb EXT4 /home 2

To explain: if you want to have multiple stripes, it is a good idea to make your physical LVM partitions the same size. Otherwise, the maximum size of a striped logical volume would be limited to the maximum size of smallest physical volume/partition in the logical volume group multiplied by the number of physical volumes/partitions in the group. The above table is an example of this, where 100mb of the lvg1 is unused. If lvg1/home or lvg1/root only had 1 stripe, then the maximum size of the logical volume would be 379.9gb or 20.1gb, respectively. Neither lvg1/home or lvg1/root is particularly closer to any portion of either disk, but explaining the actual mechanics of how the LLVM decides where to store what extent is far outside the scope of this article.


Advanced

Boot Volume

If another operating system is already present on the boot volume (Windows), you may want to free 100MB to make room for a proper /boot partition. However, sadly, the YaST partitioning module doesn't support moving partitions around like that, so if you wish to do that, you'll need to get a more advanced tool like SDB:Gparted


See also