disk partition for the head-start: dive into the partitioning of the HDD
There is no "perfect" layout. A lot of it depends on your personal preferences. As others have mentioned the most basic layout contains:
- EFI System Partition (ESP)
- /boot partition - traditionally, or just use the ESP as /boot is no longer strictly required on an EFI system
- / - the root (OS) partition
- Data storage partition - could be mounted as /home or elsewhere
Data should absolutely be separated from the root (OS) partition as "best practice", e.g. reinstalling of the OS does not interfere with your data.
Obviously, there are nuances with increasing complexity:
-
If you envisage the possibility of running out of RAM, you might need a swap partition.
- This can also be configured as a swap file instead, so it's not critical if you don't have one at the start. A swap file has the advantage of being easy to adjust its size.
-
If you envisage the possibility of adding more "partitions" to better organise your data, you might want to consider formatting one partition as LVM and making multiple virtual partitions within the LVM container.
- This has the benefit of making re-sizing of the partitions relatively easy, unlike "physical" partitions which is often far more tedious to deal with.
- Note that some filesystems also allow for virtual volumes on a filesystem level, I believe btrfs is one of them (I haven't yet used it so not sure).
-
If you want to make use of disk encryption then things become a bit more complicated:
-
For just the data partition, you might want to format that as a LUKS (Linux Unified Key Setup) encrypted volume, and a filesystem within it.
Some filesystems support encryption on the filesystem level, but LUKS can provide you with better "zero leak" protection as not even the underlying filesystem type will be exposed without unlocking the partition first. -
If you want to encrypt the OS itself as well, then you have two options:
- format as LUKS volume first, and then the filesystem within - this has the downside is it you will have to unlock two partitions separately.
- have a LUKS formatted partition, an LVM container within, and virtual partitions inside the LVM container.
-
For just the data partition, you might want to format that as a LUKS (Linux Unified Key Setup) encrypted volume, and a filesystem within it.
As an example, a layout of an NVMe drive identified by "/dev/nvme0n1" that takes advantages of all of the above and includes the [optional] "/boot" partition could look something like:
/dev/nvme0n1 ├─/dev/nvme0n1p1: EFI System Partition ├─/dev/nvme0n1p2: /boot └─/dev/nvme0n1p3: LUKS Encrypted └─LVM Volume Group ├─LVM Volume: / └─LVM Volume: /home
The layout above shows only 3 "physical" GPT partitions. The 3rd one is an encrypted container, within which there is a Logical Volume container, within which there are two Logical Volumes (or virtual partitions) - one for "/" and one for "/home". If you don't want a "/boot" partition you will need to make sure the ESP partition is large enough to store at least two kernels and their associated init images (1 GB should suffice).
I would strongly encourage something like the above, especially on a laptop that can be at risk of being lost or stolen.
It sounds complicated and, unfortunately, in many cases tuning it exactly the way you like may require a bit of manual intervention. But since you asked about doing things 'the CLI' way, this could be something to explore. If you're new to Linux, I would recommend that you start simple - forget about LUKS and LVM - and work your way up. Use disposable virtual machines to play around and get familiar with how to do it. It's not complicated, but may seem very intimidating the first time and familiarity is key. There's a lot to absorb here, I know. But this is part and parcel of the amazing flexibility that you have on Linux. And, if you're the tinkering type, practice makes perfect.
As to organising files... that is something you'll have to figure out yourself. Find what works for you. But keep in mind that if you have a habit of dumping things in "/home", even if you later re-organise them, then you most certainly will need to make sure "/home" is on a separate partition or allocate enough storage to "/" so that you don't run out of space on "/" which could interfere with system updates.
Bind mounts, as mentioned by Ralphred, are a good way to "alias" this. Think of them as a folder shortcut on Windows, except it doesn't appear as a shortcut and behaves just like a regular folder. You can, for example, create a directory on "/mnt/your-storage-partition/home" and bind it to "/home". Thus everything you put under "/home" will effectively be stored under "/mnt/your-storage-partition/home". Ralphred's "MyDocuments" directory is an example.
Bind mounts are also very versatile for storing things that otherwise would go on your root partition somewhere else. An example of this is Flatpak applications. They normally go under "/var/lib/flatpak" and these can quickly fill up your root partition, depending on its size. A good way around this is a bind mount such as:
# /etc/fstab # Syntax follows this pattern: # <source> <mount point> <filesystem> <options> <dump> <pass> /mnt/data/flatpak /var/lib/flatpak none bind 0 0
Personally, I don't like having a large OS partition - it's pointless. In 20y+ of using Linux, while requirements have sloooowly grown, I find a 30GB root partition is enough for all of my needs and I have rarely gone over 60%. For isolated cases, like Flatpak, I just use a bind mount which also has the benefit of making the size requirements for an OS partition more predictable.
Symbolic links (symlinks), also mentioned by Ralphred, are also very handy. They are more akin to the Windows shortcuts as they present themselves as such, and can simply be created or deleted like any other file.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now