Make the disk active from Linux. Hard disk partitioning in Linux Ubuntu during installation. Using fdisk in bash scripts

Before installing the operating system, it is necessary to partition the hard drive, during which the disk is divided into partitions and formatted. Installers of modern operating systems can perform this operation automatically, but they usually do this not in the most optimal way. In certain cases, it makes sense to carry out this operation manually using special programs. The need for manual disk partitioning arises if:

  • It is planned to install several operating systems on the computer, for example, Windows and Linux;
  • operating system or file system has limitations on maximum size volumes, so a large disk must be divided into several small logical drives.

There are also some benefits that can be achieved by using proper disk partitioning. When performing a backup, you can archive not the entire disk, but only part of it, with important data. For example, you can create separate archives for the user and system sections. At the same time, in the event of a system crash, user data may remain intact. And the time required for archiving and recovery will be reduced. You can also use different file systems and different cluster sizes. For example, a small cluster size will significantly save space on a partition where many small files are stored.

File systems

File system defines the way information is organized and stored on disks. IN journaled The file system, in the so-called “log”, records file changes that are planned to be made, so in the event of failures, the likelihood of data loss is significantly reduced.

Ext- the first file system in Linux. Currently practically not used.

Ext2- non-journaling file system. Can be used for data that rarely changes. For example, for boot sectors of disks, for working with SSDs and flash cards that have a limited resource of write cycles. Characterized by high speed, however, the read speed is lower than that of the more modern journaled system - ext4.

Ext3- is a journaled version of ext2. Widely used before the advent of ext4.

Ext4- developed based on ext3, has more high performance, allows you to work with very large disks and files. This is the most popular file system for Linux today, which is used for system files and user data.

ReiserFS- The first journaling file system for Linux. It can pack files into one block, which improves performance and saves disk space when working with small files. Reiser4 is the fourth version of ReiserFS, which improves performance and reliability of data processing. Added the ability to use plugins that can, for example, compress or encrypt data on the fly. Recommended for working with small files.

XFS- a journaled system with high performance can be recommended for working with large files.

JFS is another journaling file system developed by IBM. The developers sought to achieve high reliability, performance and scalability for running on multiprocessor computers.

Tmpfs- designed to place temporary files in the computer's RAM. This is especially relevant when working with an SSD and having free random access memory.

FAT And NTFS- MS-DOS and Windows file systems, which are also supported by Linux. Linux user can access partitions with FAT and NTFS. Used for installing appropriate systems, for transferring and sharing data.

Swap- can be either a separate disk partition or a regular file. Used exclusively to create virtual memory. Virtual memory is necessary when there is insufficient main memory (RAM), but the speed of operation when using such memory is significantly reduced. Swap is necessary for computers with a small amount of memory; in this case, it is recommended to create a swap partition or file 2-4 times larger than the computer's RAM. Swap is also necessary to go into sleep mode; in this case, you need to allocate a memory amount equal to the computer's RAM or a little more. If the computer has sufficient memory and does not require sleep mode, then swap can be disabled altogether. A modern personal computer usually needs 4 GB of RAM. But when processing large amounts of data, for servers with big amount users may require significantly larger amounts of memory.

Disk structure in Linux

The disk can be divided into four physical partitions. One of these sections may be extended. An extended partition can be divided into an unlimited number of logical partitions. Disks in Linux are designated by the letters sd?, where instead of a question mark, letters of the Latin alphabet are used, starting with “a”. That is, the first disk in the system is called sda, the second - sdb, the third - sdc, etc. On older computers, with IDE disks the names may be used: hda, hdb, hdc, etc. In turn, disk partitions are indicated by numbers: sda1, sdb5, sdc7. The first four digits are reserved for physical partitions: sda1, sda2, sda3, sda4. Even if the disk has fewer than four physical partitions, the first logical partition will be called sda5.

Directory structure

Here we will consider only those directories that make sense to be placed on a separate section.

/ - the root of the disk. Created anyway. Recommended file systems: ext4, JFS, ReiserFS.

/boot- serves to boot the system. The recommended file system is ext2.

/home- contains user files. Recommended file systems: ext4, ReiserFS, XFS (for large files).

/tmp- used to store temporary files. Recommended file systems: ReiserFS, ext4, tmpfs.

/var- used to store frequently changed files. Recommended file system: ReiserFS, ext4.

/usr- contains files of programs and libraries installed by the user. The recommended file system is ext4.

Disk partitioning using fdisk

Fdisk is a markup utility hard drives with a text interface. All devices in Linux are located in the /dev directory. You can view a list of disks using the command:

ls /dev | grep sd

If the sda ​​disk is already partitioned, then information about the partitions can be found using the command:

sudo fdisk -l /dev/sda

You can also get information about partitions using the command:

Let's say we want to get the following disk structure:

1 (sda1) partition for Windows with a capacity of 100 GB.

2 (sda5) partition for booting Linux - /boot 100 MB

3 (sda6) swap partition - 4 GB.

4 (sda7) root partition - / 20 GB.

5 (sda8) partition /home - the entire remaining disk.

Launch fdisk:

sudo fdisk /dev/sda

If you need to partition the second or third disk, instead of sda we write sdb or sdc.

After starting the program, press “m” to view the list of commands.

We look at the partition table by pressing “p”.

If the disk is not empty, delete old partitions with the “d” command, after which we indicate the partition number. If there are several partitions, you will have to run the command several times.

Create a new section physical Windows by pressing the “n” key and then “p”. Next, indicate the section number - “1”. The first sector is the default - press “Enter”. And at the end, enter the disk size “+100G”.

In the terminal it will look like this:

Command (m for reference): n

e extended

Select (default p): p

Section number (1-4, default 1): 1

First sector (2048-976773167, default 2048):

Default value 2048 is used

Last sector, +sectors or +size(K,M,G) (2048-976773167, default 976773167): +100G

Command (m for reference): n

e extended

Select (default p): e

Section number (1-4, default 2): 2

First sector (209717248-976773167, default 209717248):

Uses default value 209717248 Last sector, +sectors or +size(K,M,G) (209717248-976773167, default 976773167):

The default value is used 976773167

The next partition is swap, with a capacity of 4 Gigabytes. Sequentially “n”, “l”, “Enter” and at the end we enter +4G.

In the same way, create a root partition of 20 Gigabytes by pressing “n”, “l”, “Enter” and +20G.

And the /home partition, which will take up all the remaining disk space: “n”, “l”, “Enter”, “Enter”.

After which, pressing “p”, we will see something like the following:

/dev/sda1 2048 209717247 104857600 83 Linux

/dev/sda6 209926144 218314751 4194304 83 Linux

Since we plan to install Windows on the sda1 partition, we will change the type file system. Press “l” and see that NTFS corresponds to id=7. To change the type, press “t”, then the section number “1” and the code “7”, in the terminal it will look like this:

Command (m for reference): t

Section number (1-8): 1

Hexadecimal code (enter L for a list of codes): 7

System partition type 1 changed to 7 (HPFS/NTFS/exFAT)

In the same way, change the id of the paging file for the sda6 partition: press “l”, “6” and enter code 82.

Let's see what happened with the "p" command:

Device Load Start End Blocks Id System

/dev/sda1 2048 209717247 104857600 7 HPFS/NTFS/exFAT

/dev/sda2 209717248 976773167 383527960 5 Extended

/dev/sda5 209719296 209924095 102400 83 Linux

/dev/sda6 209926144 218314751 4194304 82 Linux swap / Solaris

/dev/sda7 218316800 260259839 20971520 83 Linux

/dev/sda8 260261888 976773167 358255640 83 Linux

If everything is in order, then to write partitions to the disk, press “w”. Until we enter the “w” command, only preliminary operations are performed and no data is written to the disk. After recording the partitions, we reboot and install the systems.

Disk partitioning using GParted

GParted or GNOME Partition Editor is a program for editing disk partitions with a graphical interface. It is essentially a wrapper around the GNU Parted text utility. GParted has a simple and intuitive interface. It allows you not only to create and delete partitions, but also to resize, copy and move them. The program supports working with many popular file systems.

Attention: subsequent actions may lead to complete loss of information from computer disks. Before using GParted, be sure to make copies important information. It is also advisable to charge the laptop battery using a UPS. Some operations may take a long time and data may be lost if the power is turned off.

We launch the program with the command:

You need to run it as a privileged user; to do this, first run the command su, or sudo:

sudo gparted

If the command does not work, then you need to install this program, although many distributions include it by default.

If the disk is already partitioned, we will see something like this:

Rice. 1. GParted program

There is a text menu at the top. Below are buttons to perform basic actions. On the right side of the icons is the disk selection window. The partitions of the selected disk are shown below in the form of rectangles. Even lower, the same disk partitions are in the form of a table, with a more detailed description. If you right-click on any of the sections, a menu will appear with a list of operations that can be performed with the selected section. You can also select a disk partition with the left mouse button, and then select an operation in the top text menu or by clicking on the icon.

If the disk is unpartitioned, you can immediately begin creating partitions. Otherwise, delete unnecessary partitions - right-click (RMB) on the partition name and select “Delete” from the menu.

If the partition is used by the system (mounted), then before performing operations you need to unmount it - right-click on the partition and select “Unmount” from the menu.

If the disk has the partitions you want, you can resize them to make room for new partitions. Let's say there is a Windows partition that occupies the entire disk. You must leave Windows and install Linux. To do this, right-click on the Windows partition and select “Resize/Move” from the menu. Then we indicate the new size of the Windows partition, or the free space before or after the partition. After that, click the “Resize or Move” button.

Rice. 2. Resizing the partition

Naturally, for this operation the Windows partition must have sufficient free space. After resizing the partition, there will be unallocated space that can be used to create Linux partitions.

To create a new partition, you need to right-click on the unallocated space and select “New” from the menu. Next, in the “New size” field, indicate the size of the partition. We indicate the partition type (primary, extended, logical) and file system, as well as the disk label, for example “home”.

Rice. 3. Create a new partition

We create all the necessary partitions (see above for the description of working with fdisk).

At the very end, to perform all selected operations, you need to select “Perform all operations” in the top “Edit” menu, or click the corresponding button in the form of a green checkmark on the toolbar. You just have to wait a while while the program partitions the disk.

Marking Linux disk breaks it down logically into smaller parts that will be used different programs. On solid-state devices, the word "partition" refers to space. Typically Linux is installed on the first one. This arrangement on a PC can be represented in a simplified form as a library. The operating system is a librarian that provides a tree of directories as available files.

On computers, each OS has its own type of file system, which is not accessible to others because they cannot read it. This has nothing to do with Linux, which is universal and understands files used in Windows 95/98, as well as many other modern operating systems.

Each distribution's installation guide contains a section on Linux disk partitioning. The KISS (Keep It Simple Stupid) principle is used for beginners. Desktop systems for personal use do not have the same complexity, requiring many partitions to be installed. For proper placement of Linux, three mandatory ones are recommended: swap, root and home. These are logical rather than physical separations, so they can be edited and manipulated for different purposes.

Despite the many types of file systems, only 3 are used: basic, extended and logical. There is a limitation for Linux disk partitioning - it must have no more than four parts. This requirement is related to the capabilities that tell the PC the boot location and main partitions for the OS. But if you still need more, then perform extended Linux disk partitioning.

It will serve as a hollow container for any number of smaller ones logic elements. You can create as many as you need, and also execute it as a non-OS part. However, despite this positive, extended partitions have not received widespread use, because the user cannot boot directly from this disk. There are ways around this requirement, but it is better to coordinate the underlying system properly.

Linux mount points

It's common to partition the disk when installing Linux, which works by putting everything into a tree. The next partition is mounted as a branch in a specific folder, usually media or mnt. The directory in which to mount is called the mount point. This method works better with a tree system, but you can create folders anywhere you like.

The standard disk partitioning scheme when installing Linux looks like this:

  1. The 12-20 GB partition for the OS is called root.
  2. A small partition for increasing RAM, called swap.
  3. Great for personal use - home.

The exact size requirements of Linux disk partitioning depend on your needs. If the user edits a lot of multimedia or has little RAM, he should use a larger swap volume. The rule of thumb is to choose twice the amount of RAM as space and place it in the location quick access, for example, at the beginning or end of the disc.

Even if the user installs a “ton” of software for the root partition, when partitioning the disk for Linux, a maximum of 20 GB is enough. Distributions use ext 3/4 as a file system that has an independent self-cleaning mechanism and does not require defragmentation. However, for this there must be a free space of 25-35% of the volume. Home stores personal documents and programs. It is functionally equivalent to the Users directory in Windows. It is useful to have it in a separate element because during an OS update or reinstallation, the data in this directory will not be changed.

"Swap" is the partitioning of a Linux hard drive to provide the paging function, which exists in the form logical area on disk or just in a file. Instead of using physical space in RAM, it grabs disk space to store temporary files, thereby reducing RAM usage. The combined set of RAM and swap creates virtual memory larger than the default on the computer. This way, the Linux kernel can run processes that require more memory than is physically available.

The swappiness function represents the kernel's preference to use swap. The permutation can have a value from 0 to 100, but the default value is 60. To be clear, this value may not be equally effective in all cases as it will depend on individual usage. technical characteristics equipment and user needs.

The user needs one gpt-partitioned Linux disk, used as virtual swap space. For simplicity, create a file with a size of 50% to 100% of the physical memory in the OS. If the PC has little RAM and a large amount of disk space, then increase the volume.

Represented as a forward slash (/). This top of the directory tree contains Linux and everything installed on the system and is equivalent to the DOS or Windows "C:" drive. The user creating a partition for the root directory should not confuse it with account root, which is a system administrator function.

The layout of Kali Linux disks and the size of the root element will depend on what is being installed or planned to be placed. Pre-read the documentation for the distribution and reserve enough space for maximum installation, as well as at least 100 MB for temporary space.

If the user plans to download and try a lot software, leave more space. If your PC is small HDD, you can trim installed packages to save space. In general, if a PC has a root partition between 2 GB and 8 GB, then this is quite enough for the operational operation of the system.

The third and final stage, which is performed when marking disk partitions for Linux installations, - creating a home directory. This is the place where user files, in other words, data are stored. This is equivalent to the My Documents folder on the MS Windows desktop if MS Office is installed.

In a multi-user system, each user has his own home directory. The contents of the home directory are protected by file permissions and are accessible to all authenticated subscribers. Any user with administrative privileges has the right to access the protected file, including other users' home directories.

Separating user data from system-wide data avoids redundancy and greatly simplifies backup important documents. Malicious programs and viruses running under the user's name and with his privileges can only change files in the home directory and workgroup files of which the user is a part, but not actual system files.

Strictly speaking, there is no need to create a separate place for home. If this is not done, it will be located in the root partition, like all other system directories. If you don't have enough space, you may need to configure your computer to create a separate storage, which will later allow you to reinstall Linux without losing personal data.

Typically, to create partitions and partitions, use the Partition Magic program, which can be found on the BOOTABLE CD. Launch BootCD and the first option - Disk Partition Tools.

Algorithm of actions:

  1. Select a hard drive and press an additional button in the form of a “menu”, where you assign a GB volume for Linux.
  2. Next, a section will appear that you will have to create Unallow.
  3. Click the button on it and select “Create”.
  4. The setup menu appears. The Linux partition must be primary and formatted in Ext3 or Ext2.
  5. The LABEL is labeled Ubuntu, because the distribution will be installed.
  6. The cluster size is left as default.
  7. Once it is configured, confirm with the “OK” button on the screen.

To create a disk layout layout for Linux Mint change the installer page to "something else" and then they will show up on the hard drive.

The process of creating new partitions:

  1. Click the "+" button to add a new one and adjust the size in which you want to create Linux Mint.
  2. Set the mount point to root and leave the file system as ext4.
  3. Create a swap and select a “swap area”.
  4. Open a terminal application and enter the following: sudo su.
  5. Enter your current password to receive root rights. The command will change from the ~ symbol to #.
  6. Activate the swap file, open the file with the Nano editor: # nano / etc / fstab.
  7. Write the following text: /swapfile none swap defaults 0 0.
  8. Pressing Ctrl + O together confirms saving the /etc/fstab file.
  9. By pressing together Ctrl keys+ X confirm exit from Nano.
  10. After reboot, the operating system will use /swapfile as the swap file.
  11. To check this, enter the following command in the terminal: $ cat / proc / swaps.
  12. The user will see which device, partition or file is being used for sharing purposes and how it is being used.

Similarly, you can create any Linux Mint partition.

Ubuntu 14.04 setup steps:

  1. In the LiveCD assistant, select the installation; in the fourth paragraph, check the “Advanced options” option to create a separation. A 500 GB hard drive will appear.
  2. Click “Create Table” and a warning will appear indicating that all content will be lost.
  3. Click “Continue”, an empty configuration table will open.
  4. Select free space and click on the “+” icon to add a partition, for example: Size: 1024 MB (1 GB) > Type: Primary > File system: ext4 > Mount point: boot.
  5. Create a partition for SWAP: Size: 8192 MB (8 GB) > Doubles the computer's 4 GB RAM > Type: Logic > File system: Swap area > Attachment point.
  6. Create for OS and work programs: Size: 51,200 MB (50 GB) > Type: Logic > File system: ext4 > Attachment point.
  7. Create home where users usually save torrent downloads, movies, music, thousands of photos: Size: 476,454 MB (more or less what's left of the disk) > Type: Logic > File system: ext4 > Mounting point: home.

Sometimes you need to install Linux on a Windows PC. To do this, you need to allocate disk space. It is recommended to use the GParted partitioning tool to resize Windows and create new partitions for Linux.

In general, Linux distributions have good hardware support. But precautions are necessary. Whenever the correct Linux disk partitioning is not applied, there is a risk of data loss, regardless of what OS is installed. It is important to ensure that critical data is stored on external media and that backups not damaged and can be restored.

Ubuntu, like many others Linux distributions, comes as a bootable LiveCD. This means you can download it and check your hardware compatibility without making any changes to your existing installations.

Process for planning hard drive layout for Linux installation:

  1. After clicking the Install button, the Linux installation will begin. You should not use a small system Windows partition, but you can resize the NTFS partition to free up space.
  2. The default installation choice is to install Win and Linux side by side.
  3. Linux requires three partitions (root, swap, home). Windows already uses two. Only four main ones are allowed on a disk. This means that you will need to enable the extra space gained from shrinking Windows 7, otherwise you will have to forego using a separate swap or home partition on Linux.
  4. Change the occupied size of Windows (sda2). Create an extended one - it will be called sda3.
  5. Create logical root, swap, home inside Extended - will be called sda5, sda6 and sda7.
  6. Change the section.
  7. Use GParted to create the layout. GParted comes with Ubuntu. It can be found in System > Administration > Editor.
  8. The next step is to create an extended partition that will take up all the free space, including the new 2 GB freed up by Windows.
  9. GParted is quite friendly and will start working. The compression task will be run first, then a simulation will be run to ensure that the marker can perform the desired task. It will then check NTFS consistency and fix errors if it finds any. Afterwards it will resize and copy all the data.

There are many programs that can help you manage disk partitions in Linux. But often such a huge number of alternatives becomes a problem for beginners in the field and makes them doubt which one to choose.

Managing hard drive partitions is a high-risk practice because if the user doesn't know exactly what he's doing, he can render the system inoperable. Beginners are advised to start with the graphical options of the tools and forget about the command line.

  1. Fdisk is a powerful tool command line with a text mode interface that allows you to manage partitions. Help makes it easier to work with it, each command of its interactive menu can be called by one letter, such as m - for help, n - for creating new ones, p - for displaying a table, t - for formatting, w - for writing.
  2. Parted is a tool in text mode, the main difference from the previous one is that all actions of sent commands will be applied immediately. Therefore, it must be handled even more carefully than the previous one.

The three most relevant GUI tools are:

  1. GParted is recommended for all users because it GUI simple and intuitive, allows you to perform many operations from creating a new one, formatting, creating tables, resizing.
  2. GNOME - by default, its own disk tool is installed, its interface is simple, but, to be honest, many still recommend GParted.
  3. KDE - provided its Plasma desktop environments with another tool for creating default partitions. In this case, the interface is more similar to GParted and simpler, so it could be another good option for power.

Some distributions, such as Ubuntu, offer GParted as a LiveCD utility. Therefore, if the user learns how to use the program, he will be able to properly partition the disks in order to have two or more operating systems on the PC, while the information on it will be better organized.

The first part of the fourth part of the series of tutorials for beginners talks about block devices, partitions and file systems. You will learn how to partition a hard drive using the fdisk utility, create file systems, and mount them. Get to know the syntax configuration file fstab.

Thanks to andrewww for translating this part. To be continued...

About the authors

Daniel Robbins

Daniel Robbins is the founder of the Gentoo community and creator of the Gentoo Linux operating system. Daniel resides in New Mexico with his wife Mary and two energetic daughters. He is also the founder and CEO of Funtoo, and has written numerous technical articles for IBM developerWorks, Intel Developer Services, and C/C++ Users Journal.

Chris Houser

Chris Houser has been a UNIX advocate since 1994, when he joined the administrative team at Taylor University (Indiana, USA), where he received a bachelor's degree in computer science and mathematics. He has since worked in a variety of areas, including web applications, video editing, UNIX drivers, and cryptographic security. Currently working at Sentry Data Systems. Chris has also contributed to many free projects, such as Gentoo Linux and Clojure, and co-authored the book The Joy of Clojure.

Aron Griffis

Aaron Griffis lives in Boston, where he spent the last decade working at Hewlett-Packard on projects such as UNIX network drivers for Tru64, Linux security certification, Xen and KVM virtualization, and most recently, the HP ePrint platform. When he's not programming, Aaron likes to think about programming problems while riding his bike, juggling bats, or cheering on the Boston Red Sox professional baseball team.

Today we will learn on our own create disk partitions in Linux Ubuntu in the process of installing the distribution on a computer, in other words, manually create hard disk partitions in Ubuntu that are necessary for the normal functioning of the operating system on a home computer, and we’ll also talk a little about which partition is needed for what.

So, as an example, we will use the current one on this moment version of Linux Ubuntu 17.04, i.e. let's imagine that you are installing Ubuntu 17.04 ( or any other derivative distribution, such as Kubuntu, Lubuntu, Ubuntu MATE and others) and reached the step where you need to select “ type of instalation", i.e. disk partition type, for example: automatic - this is the first item " Erase disk and install Ubuntu", or " Another variant" - this is exactly the type in which we can mark up the disk ourselves; we will now consider it.

Note! In this article we will look at the initial layout of a blank disk, i.e. on which there are no partitions and data yet.

Creating disk partitions during Linux Ubuntu installation

To create a disk partition yourself during the installation of Linux Ubuntu, you must select the installation type " Another variant" and press " Continue».

If you have several physical disks ( I have one) select the one you need and press “ New table sections».


We are then warned that a new empty partition table will be created, we click " Continue", i.e. confirm your action.


The first thing we must create is the root partition, i.e. basic ( systemic) section for installing the system. For this we indicate:

  • Size– for the root partition, a minimum of 15 gigabytes; in the future, of course, it is better to specify more, for example, 50 gigabytes. I have a small disk for testing, so I specify 15 gigabytes;
  • New partition type– indicate “ Primary", because this type must be on disk;
  • – indicate “ The beginning of this space»;
  • Use as– here we need to select the file system type, leave the default Ext4 file system - this is a journaled file system for operating systems Linux systems, which is currently most suitable for the file system of the root partition ( yes and for user data);
  • Mount point– we indicate “/”, since this is our root partition.

Click " OK».


Then, in almost the same way, we create a section for user data, i.e. home section. Creating such a section will allow you to store your data ( documents, music, photos and so on) in a separate place that will not need to be copied in any special way ( reserve) during reinstallation ( updates) distribution or even its change.

In this case, we need to specify:

  • Size– maximum possible, i.e. all the remaining space, as I already said, my test disk is small, so there is little space left;
  • New partition type– indicate “ Logical»;
  • Location of the new section– indicate “ The beginning of this space»;
  • Use as– also select the Ext4 file system;
  • Mount point– specify “/home”.

Click " OK».


Swap partition (swap) we will not create, since in Ubuntu, starting from version 17.04, a swap file is used instead of a swap partition ( like in Windows). By default, its size is 5% of the free disk space, but not more than 2 gigabytes. After installation, the paging file size can be changed at any time.

This completes the disk layout, which is suitable for a home computer, click “ Install now».


Confirm making changes to the disk, click “ Continue" and continue installing the distribution.


That's all for me, I hope the material was useful to you, bye!

I recently got a 3TB (terabyte) hard drive. I will use it to store data. I want to tell you how to create a partition table, partition and format a new hard drive in Ubuntu. I will create two partitions on the disk, format them with the EXT4 file system, increase the free space on the disk, and change the owner of the disk (from root to regular user).

I connected the hard drive to a SATA connector next to the existing one on which Ubuntu 11.10 was installed. To format and create partitions on your hard drive, we will use the GParted program. If you don't have it installed, then you can install it through the Ubuntu Application Center or from the command line by running the command:

Sudo apt-get install gparted

Launch GParted (the program must be run with superuser rights, you will need to enter a password when starting). From the command line, you can run GParted with the following command:

Sudo gparted

The program opens your main hard drive by default, for me it is /dev/sda. On the menu GParted->Devices a list of available media is presented, you must select the one you are going to format. My new hard drive is called /dev/sdb, so I need to select this menu item (make sure you make a mistake, otherwise you will format the wrong drive).

When you switched to required disk, then if you select the item in the menu Section->New Section, a message will appear stating that the partition table has not been created:

Create a partition table on the disk

What is a disk partition table (GPT table)

A partition table is a service area on a disk that stores a table with information about disk partitions. Partition tables come in different types, for example, GParted allows you to create tables of the following types: msdos, aix, amiga, bsd, dvh, gpt, mac, pc98, sun and loop. They differ in different structure, reliability and capabilities. Some are not supported on one operating system but are supported on another. Linux hard drives typically use MSDOS (sometimes called MBR) and GPT partition tables. The main drawback of MSDOS tables is that they do not support disks larger than 2.2TB. We will be interested in the GUID Partition Table (GPT) type; it is supported by Linux and has several important advantages. GPT supports very large disk sizes, allows you to give symbolic labels (names) for partitions, allows you to create 128 primary partitions (more precisely, for GPT there is no division of partitions into primary, logical and extended). The main disadvantage of GPT is that GPT is not supported by everyone operating systems. For example, versions of Windows lower than Vista cannot read these discs. Also Windows cannot boot from a GPT disk, which means that if you are going to install on this Windows disk, then you better choose MSDOS partition table. I plan to use the disk as a second one in the system and only for data storage. I will use a GPT partition table.

Create a GUID Partition Table (GPT)

So we need to create a partition table. Select the GParted menu item Device->Create Partition Table. In the window that opens, select the item from the list gpt and press the button Apply.

Partitioning and formatting

Now we need to create partitions on the hard drive. For example, I will create two partitions, one with a capacity of 2TB, and the second ~800GB (Gb). Select a menu item Section->New.

A window will open to create a new partition. In it, I specified the disk size in megabytes - 2048000MB, selected the EXT4 file system (note that the EXT4 file system is not readable under Windows) and labeled the disk BURGER (arbitrary name). The result was the following (click the button Add):

Now let's create a second partition that will take up all the remaining free space. Select the menu item again Section->New. The window for creating a second partition with a volume of ~800GB and labeled CAT looks like this (here you press the button again Add):

After completing the steps described above, the program window will display what the disk will look like after applying all the operations. To perform specified operations, select a menu item Edit->Execute All Operations or click on the button with a green check mark.

The program will display a warning message. Think again if you have indicated everything correctly and click the button Apply.

The process of creating partitions and formatting will begin.

At the end you should receive a message stating that all operations were completed successfully. The resulting Gparted program window will look like this.

Increasing free disk space

Now if you open file manager Nautilus, new drives named BURGER and CAT will appear in the list of devices. If you click on them, then they are mounted.

In Ubuntu, disks are mounted in the /media directory. Since our disks have labels, they are mounted in the /media/BURGER and /media/CAT directories. Now we need to determine the name of the device used for the created partitions (disks). To do this, run the command in the terminal:

In the command output you will be able to see the names of the devices that are used for our BURGER and CAT drives. For me it is /dev/sdb1 and /dev/sdb2:

Open the drive in Nautilus, right click on free space and in the menu that opens, click Properties(or press Ctrl+Enter). The disk properties will open.

As you can see, 42 and 107 GB are already occupied on the disks! This is because the system reserves 5% of the total disk space for the root user. In particular, it is assumed that when there is not enough space on the disk, then the system will use this 5% and correctly perform all operations. But this is only true for system partitions, such as the root filesystem partition / or, for example, the /boot partition (if you have one). And if you only use the drive for data storage, then 5% of the space will simply be wasted and will never be used. You can simply disable seat reservations, or you can reduce its number. To reduce the amount of reserved space from 5% to 1%, run the command (the number after the key -m determines the amount of interest used for reservation):

Sudo tune2fs -m 1 /dev/sdb1

To completely disable seat reservation, run the commands (first command for BURGER, second for CAT):

Sudo tune2fs -r 0 /dev/sdb1 sudo tune2fs -r 0 /dev/sdb2

Now if you look at the disk properties then we should get the following:

Changing the owner of the disk

By default, in Ubuntu, my disk is mounted under the root group and the root user (the superuser is the owner of the disk) and you cannot write or create anything on it as a regular user. As a good idea, you need to make an entry in the fstab file for each disk so that they are automatically mounted in the required directories, but I will talk about this in one of the following articles, and here I will give a link. For now we will simply change the disk owner (user and group) so that the disks are mounted under your user. Run the commands in the terminal (instead of yuriy, enter your username):

Sudo chown yuriy:yuriy /media/BURGER sudo chown yuriy:yuriy /media/CAT

Now these disks will always be mounted under the user yuriy.

At this point, the process of creating partitions and formatting the disk can be considered complete. Constructive additions and advice are accepted in the comments.