Skip to content
Step by Step Internet 馃寪 Guides for learning to surf the Net

Linux partitions What are they, what are they for and what types of partitions exist in this OS?

Dividing a hard drive into multiple drives has its advantages. To cite a case, if the software were to present a failure and there are two partitions, one for the operating system and one for your files, your documents will not be lost or suffer any damage, because being isolated will keep them safe.

In many cases, different Linux distributions come with the creation of partitions by default to divide the sector where the operating system goes and the rest of the information that is stored in the computer. And it is not a single division that can be done, it only takes organization and knowledge to have your documents safeguarded.

The course that we are starting will show us the different types of partitions that exist as well as a basic way of doing this job on our PC.

What are partitions in Linux and how do they differ from the ones we have in Windows?

Linux conytra Windows wn four partitions

Linux partitions are segmentations that are made to the hard disk to distribute the space in different functions and they are divided into two: primary and logical. When installing the distribution, a minimum of two divisions must be established, one for the filesystem and one for the swap or also called an exchange area.

According to the needs and the use that will be given to the computer, you can create additional ones, which will be assigned a certain space on the physical drive. In the case of Windows, you can also perform other divisions to the hard drive defined by letters, with the difference that only the operating system can be installed on one of the primary partitions.

What are the main types of partitions that we can find in Linux?

Tools for partitioning disks in Linux

There are those who do not stop to think about the importance of partitions in Linux. But if at any time you want to change the distribution and the operating system along with the rest of the documents are in the same sector, the most likely is that when installing a new distro you lose everything you have stored.

That is why we want to review the two main partitions that exist in Linux:

Data Partition

In this segment they go all the installation files for the Linux distribution you have installed. With them, the operating system starts up once you turn on the computer. According to use and the distro will be allocated the hard drive space.

Partition Combination

This partition is used for increase the virtual memory of the computer. You can pretend that there is more RAM than you actually have and, when you need to use it, the system itself passes processes to the extension.

These are the partitions most used by Linux users that you should know right now

One of the steps to set Linux root keys

Now we will detail some of the directories used by Linux users, which are part of the root that is represented by the slash that we see before the name of the partition. There are some that are compatible with several computers and others that only fulfill their functions in the computer that they are installed.

Let’s review 19 of them:

  • /bin: The binaries that allow the basic functions of the users to work without problems are stored in this directory.
  • /boot– Here are all the executable files that are used in the operating system boot process.
  • /dev: This combination represents the devices connected to the operating system, such as hard drives or USB memory sticks, among others.
  • /etc– Contains no binaries and deals exclusively with the database and system configuration files in general.
  • /home: stores all the general files of a user, music, videos, documents and images, among others.
  • /lib– Contains the essential libraries for the binaries to run correctly along with the drivers for the devices.
  • /lib64: in this case they are the libraries and specific drivers for the devices that work in 64 bits.
  • /media– Mount points for removable disks, hard disk partitions, players, or network shares are generated here.
  • /mnt: its functions are similar to those of the media directory, also containing mount points.
  • /opt– Large packages or programs such as antivirus, web browsers, and other third-party executables. The largest files are installed in this directory instead of in the users directory.
  • /proc: they are virtual files that are not saved and that show the applications that are running on the system at a certain moment.
  • /sbin– Stores the binary files with which the system boots or performs restoration or maintenance tasks. To activate it, you must have superuser credentials.
  • /root: is the root directory of the first partition that was made to the hard disk that has special superuser privileges.
  • /srv: refers to files related to web servers, FTP or any other data on the system.
  • /sys: also refers to virtual character files related to the installed distribution.
  • /tmp– As its name implies, it deals with temporary files such as cache or history of web browsers.
  • /usr: the files and programs visible to all users are stored in this place.
  • /var: is a directory that shows files that change in size, such as details of installed applications or databases.
  • /swap: is the exchange that virtual memory does when it is almost entirely occupied with a partition on the hard disk. This is how RAM is simulated to run processes.

What is a partition scheme in Linux and what is the most basic one that users usually create?

How to manage more memory swap in Linux

When we talk about a partition scheme, we mean the allocation of space that we will give to each directory so that it executes its function without problems.

And although there are many schemes, we are going to introduce you to the most basic one used by Linux users:

  • /home: here all the space will be unoccupied after we make the rest of the partitions.
  • /usr: You must allocate a minimum of 20 GB space.
  • /var: you must put at least 2 GB.
  • /boot, /etc, /sbin, /bin y /dev:– There must be 250MB of space for each.
  • /srv: There must be a minimum of 100 MB.
  • /opt: at least 500 MB.
  • /lib: 5 GB would be enough.
  • /tmp: assign them space according to the one destined for “/ swap”.
  • /swap: at least twice as much RAM as your computer has and depending on the capacity of the hard drive.
  • /media y /mnt: just 8 Kb is enough.

Learn step by step how to create a partition on your Linux computer like an expert

The idea of ​​disk partition is isolate sectors to use them for different purposesEither the installation of more than one operating system or to give it a structure that allows better organization of files.

We are going with the basic steps that must be carried out to be an expert when it comes to partitioning the hard drive on your computer:

Choose the type of partition

The two most commonly used types of partitions are GPT using modern standards or MBR, which is compatible with various operating systems.

If you opt for GPT, type the following command:

  • $ sudo parted /dev/xvdb mklabel gpt.

If you prefer MBR, run the following code:

  • $ sudo parted /dev/sda mklabel msdos.

Create a new partition

Create partitions in Linux

In this step we are going to format the partition taking into account the file system that is required.

The space for the new partition has already been allocated and the file system needs to be created:

  • Run the following command: $ sudo parted -a opt /dev/xvdb mkpart primary ext4 0% 100%
  • There you should see the option “lsbkl” showing a new partition called /dev/xvdb1

If you want to specify or modify the size of the partition, run this command:

  • (parted) mkpart primary ext4 0 1024MB
  • (parted) print

If you want to list the partition information, enter this code:

  • $ sudo parted /dev/xvdb print

Start a file system

On Linux there are different types of file formats, what we are looking for now is to format it “Ext4” to the partition we created earlier.

To do so, we must take the following route:

  • Insert the following command: $ sudo mkfs.ext4 -L databackup /dev/xvdb1
  • To put a new partition label, use this command: $ sudo e2label /dev/xvdb2 storagedata
  • To record the information, use this code: lsblk –fs

Mount the file system

Mount a disk partition in Linux with commands

In this step let’s write the data to the mount point, for this we must have all the inputs configured and updated correctly.

We add this command to temporarily mount the files:

  • $ sudo mount -t auto defaults /dev/xvdb1 /mnt/data.

The key is that the fstab file is updated, for this we use this command:

  • LABEL=databackup /mnt/data ext4 defaults 0 2.

Finally, we verify that it is available and list it with this command:

  • $ df -h -x tmpfs -x devtmpfs -x squashfs.