📜 ⬆️ ⬇️

Breakdown of disks in Linux for the smallest

Many novice Linux users have doubts about how to properly partition a hard disk. I will try to ease the choice of flour to our colleagues.

We have at our disposal - physical partitioning of disks into sections (fdisk, gparted), sof-RAID (mdadm), logical disk manager (LVM), dm-crypt shearing (the rest should not be forgotten).

The paths of disk breakdown are inscrutable, so we will start with the simplest.

1. Physical disk breakdown
This is the easiest, most reliable and compatible “old-fashioned” method. It allows you to clearly delineate the boundaries of partitions and their mutual position on the disk.
When splitting a disk, you can take into account its physical features and get some performance gains. The fact is that closer to the edge of the disk reading speed can be several times higher than closer to the center. Accordingly, if you arrange for example / boot (128 mb), swap (memory * 2 or 2.5), / (root), then we get a good speed of loading and working with the swap partition. If there are several disks, you can arrange the swap at the beginning of each. But steaming with swap makes sense if you work with large amounts of data - linux does not use swap without extreme need. (check free -m). It is not recommended to refuse to use swap, as linux is a good system, but there are no miracles. By opening the 1GB file, you can lock the system tightly without the possibility of unlocking.
The partitioning of the disk into a large number of sections is justified only if it is done for a particular purpose. In other cases, it is enough to do with the simplest / (root) and swap.
Very often, users separate / home from / (root) - this makes no practical sense in single-user systems. Usually, / (root), / var, / home is shared on servers so that users with malicious intent will not fill in the logs or their home directory. By the way, you can mount / home with noexec without doing a separate partition (man mount).
If you are using windows in parallel, I recommend using FAT32 for music / movie partitions that you want to access in both systems (and in no case do / home or home folder in FAT32 !!). NTFS is well supported, but not enough to use it every day (to remove the unclean shutdown that does not allow to mount the partition, you need to load windows), errors in the file system can cause hangs and data loss (hello to greedy Bill).
')
Remember: over-dimensional breakdown is the root of all ills. Breaking discs in a “special” way is necessary only for a SPECIFIC task.

2. Logical partitioning of disks
Do not be afraid of LVM - it is not so scary. With it, you can repartition disks, expand partitions, add physical devices and expand on them, do shadow copying, backup similar to the “time machine” appeared around 2002. Do not be afraid, make backup and use the flexibility of LVM.
For LVM, MD, DM to work, you need a physical / boot partition that allows the boot loader (grub, Lilo etc) to download the minimum system image (initrd) with the necessary drivers and configs for starting the main system.
With logical breakdown all harder. Nesting of sections can be arbitrary.
For example, how full encryption is done in ubuntu: / boot DM-CRYPT [LVM [/ (root) swap]] - physical partition / boot, then physical partition with dm-crypt, in which is located LVM in which two logical partitions / (root) and swap.
With encryption and raid you can play as you like.
An example from the life of a paranoid:
/ boot DM-CRYPT [LVM [/ root DM-CRYPT-random [/ tmp] DM-CRYPT-random [/ home] DM-CRYPT-random [/ var / log] DM-CRYPT-random [swap]]]
Each time you boot, / tmp / home / var / log and swap are initialized with a random key. Of course, this puts a heavy cross on hibernate but at every boot, the system is absolutely clean of logs and temporary files. It is suitable for students or fans to wander through porn sites.

3. Optimization tips
/ boot can be done in the ext2 file system - it is faster than ext3 and that will be enough.
On an actively used section, you can disable access time - the noatime flag. This is often done on web servers to reduce the load on the hard disk.
As the long-term practice has shown, you should not hope for the reliability of a simple or sophisticated solution. It is worth using the most convenient and doing regular rsync on external media. In this case, questions are sent to the data recovery account, which, with any solution (especially when encrypting), makes life very difficult. For example, the troubles on the partitioned partition in the presence of Luks can disable the system without the possibility of data recovery. Encrypted data is more susceptible to damage than unencrypted data.
(advise, add)

In linux, you can do absolutely anything, and it will work. The main thing is to be guided by common sense and do not disdain to read man instead of quite often harmful and outdated howto.

So, we summarize:
For desktops and laptops the optimal method of breakdown is the complete absence of breakdown.
For those who do not like to be backed up, use "complex methods" like LVM. An option may come up:
swap (memory * 2), / (the rest)
For users, ubuntas are enough to choose: Use all free space under LVM, then you will have many opportunities for growth.
If you break /, / home, then sooner or later you will encounter a shortage of space in one of the sections.

Source: https://habr.com/ru/post/60265/


All Articles