Enjoying the Hobby: Thinking, Making, and Separating Partitions in Linux (A Gentoo User's Experience)
This article focuses on the experience of a Gentoo user who decided to separate partitions while installing Linux. This article aims to provide a detailed context on the topic, covering key concepts, subtopics, and necessary formatting.
Why Separate Partitions?
Partitioning is an essential step during Linux installation. Separating partitions has several advantages. It helps manage disk space efficiently, improves system performance, and provides better security.
Understanding Partitions
Before we dive into separating partitions, let's first understand what partitions are. A partition is a logical division of a storage device, such as a hard disk or a solid-state drive (SSD), into smaller sections that can be treated as separate logical disks.
Creating Partitions with fdisk
The fdisk utility is a popular choice for creating and managing partitions. To create partitions using fdisk, follow these steps:
# su -
# fdisk /dev/sda
Once inside fdisk, use the following commands:
n - To create a new partition
p - To create a primary partition
1 - To create the first partition
t - To change the partition type
c - To mark the partition as W95 FAT32 (LBA)
a - To toggle between creating an extended partition and a logical partition
1 - To create the first logical partition
t - To change the partition type
8e - To mark the partition as Linux LVM
w - To write the changes to the disk and exit fdisk
Setting Up Logical Volumes with LVM
After creating partitions, we need to set up logical volumes using Logical Volume Manager (LVM). To create logical volumes, follow these steps:
# pvcreate /dev/sda1
# vgcreate my_volume_group /dev/sda1
# lvcreate -n root -L 10G my_volume_group
# lvcreate -n swap -L 1G my_volume_group
# lvcreate -n home -L 50G my_volume_group
# lvcreate -n data -L 50G my_volume_group
Mounting Partitions
Once the partitions and logical volumes are created, we need to mount them. Create the necessary directories and mount the partitions:
# mkdir /mnt/gentoo
# mount /dev/mapper/my_volume_group-root /mnt/gentoo
# mkdir /mnt/gentoo/boot
# mount /dev/sda1 /mnt/gentoo/boot
# mkdir /mnt/gentoo/home
# mount /dev/mapper/my_volume_group-home /mnt/gentoo/home
# mkdir /mnt/gentoo/var/lib/portage
# mount /dev/mapper/my_volume_group-data /mnt/gentoo/var/lib/portage
Installing Gentoo
Now that the partitions are set up, we can proceed with the Gentoo installation:
# stage3-install --m64 --reinstall sys-kernel/linux
# emerge --sync
# emerge --ask --update --newuse --deep --with-bdeps=y --nodeps world
Configuring Fstab
Finally, we need to configure the fstab file to automatically mount the partitions during system startup:
/dev/sda1 /boot ext3 defaults 0 0
/dev/mapper/my_volume_group-root / ext4 defaults 0 0
/dev/mapper/my_volume_group-home /home ext4 defaults 0 0
/dev/mapper/my_volume_group-data /var/lib/portage ext4 defaults 0 0
- Partitioning is essential for managing disk space efficiently, improving system performance, and providing better security.
- Use the
fdiskutility to create and manage partitions. - Set up logical volumes using Logical Volume Manager (LVM).
- Mount the partitions and logical volumes.
- Configure the fstab file to automatically mount the partitions during system startup.