Standard Partitions Install, Configure, Manage Part-1
It enables efficient disk and volume management, data storage and access operations in Linux operating systems. This process enables system administrators and users to make the best use of disk space, plan ahead, ensure data security and increase performance. Disk and volume management, partitioning of disks, creation of file systems, logical volume management (LVM), (RAID) configurations, etc. It includes various operations such as.
📁File Systems:
- Ext4: It is an updated version of the ext3 file system. The most widely used Linux file system today.
- Ext3: It is an updated version of the ext2 file system. Provides backward compatibility.
- Ext2: A legacy file system for Linux, with basic features.
- Btrfs: A modern file system with high performance and scalable features.
- XFS: A file system used for large data storage and systems requiring high performance.
- JFS: A journal file system developed by IBM.
- ZFS: A file system known for its high data integrity, data compression, and snapshot features.
- .etc
Comparative: ext4, xfs, btrfs
Major Basic components of file system structure:
- Superblock: contains information about the partition, starting and ending addresses, empty block table, inode table, root (/) directory index number. (the inode number of the root directory is always 2)
- Inode (file node): Contains file permission information, owner information and the addresses of data blocks belonging to the file. They do not contain file names. Additionally, if the file is in use, it is placed in lock status. i.e. file
metadata is kept in the file node. - Datablock: It is the part where the data of the files is stored.
- Directories: They are special files. They hold the inode numbers and names of the files and directories under them. They are kept in the Datablock (data) section of the disk. (normal file datablocks hold file data, but directories
datablocks keep the names and inode numbers of the directories and files under them.)
🛢️🛢️ Disks and Partitions:
In Linux, disks are physical devices that represent storage space. In Linux, disks and partitions are often referred to by representatives such as /dev/sdXY, where "X" is a letter or "Y" is a number. In short, it refers to the Y partition of the X disk.
- /dev/sdc4 = partition 4 of disk c
- /dev/nvme0n1p2 = 2nd partition of 1st NVMe disk
- .etc
lsblk -p
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 280G 0 disk
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 1M 0 part
├─sdb2 8:18 0 513M 0 part /boot/efi
└─sdb3 8:19 0 9,5G 0 part /var/snap/firefox/
/
sdc 8:32 0 50G 0 disk
├─sdc1 8:33 0 1M 0 part
├─sdc2 8:34 0 513M 0 part
└─sdc3 8:35 0 4,5G 0 part
├─vgubuntu-root /storage/logs
│ 253:0 0 4G 0 lvm
└─vgubuntu-swap_1 /storage/www
253:1 0 504M 0 lvm
sdd 8:48 0 300G 0 disk
sde 8:64 0 325G 0 disk
nvme0n1 259:0 0 500G 0 disk
#In this command output, the connected disks and partitions in the system
# 5 sd (SATA(Serial Advanced Technology Attachment)
# 1 NVMe(Non-Volatile Memory Express)
📜Tutorials / Information:
⦁ Disks can be divided into partitions.
⦁ Partitions are logical sections within a disk. Each section can be formatted with a separate file format.
⦁ Formatting must be done separately for each partition after partitioning. otherwise you will lose all partitions.
⦁ If Linux systems do not have LVM (Logical Volume Manager), standard partitions are used by default.
⦁ Discs always expand to the right.
⦁ The disk is set to GPT (1-128), you can create 128 partitions.
⦁ LVM Management will place the /boot partition in the first sector.
⦁ In best practice, /boot and /swap should be placed in the first sector.
⦁ The created file systems (xfs, ext3, ext4, ntfs .etc) require a partition. It is mandatory to use these partitions.
⦁ It is a safer approach to mount the UUID of the fstab /boot partition.
⦁ Expanding and reducing the partition can be done Online/Offline.
⦁ To reduce the partition, the File system must be minimized first. (reverse process of expansion)
⦁ If enlarging a file system is to be done, it should first start from the partition.
⦁ The file system cannot be enlarged without enlarging the partition
⦁ The "parted" or cfdisk" tool can be used to expand the partition.
⦁ Actually no resize partition option in fdisk tool! (year 2024)
⦁ "e2fsck" checker should be used before reducing the partition.
⦁ xfs file system can be expanded but not reducing!! (year 2024)
⦁ Disk reducing is not recommended. If the reducing is greater than the disk capacity, you will lose data!!
⦁ There are two types of disks used in the Linux world. Active partitions and Logical partitions
⦁ The active partition must be primary.
⦁ "Primary partitions" "can be active partition"
⦁ "Extended partition" will not be an active partition
⦁ The NTFS disk format can be used for dual booting on a Linux system.
⦁ To repair the file system with e2fsck, the file system must be unmounted.
⦁
⦁
🧰Disk Tools:
- Fdisk: Used to create and manage disk partitions.
- Cfdisk: To list your disks, create, delete or edit partitions.
- Parted: A command line tool used to create, edit and manage disk partitions.
- Gdisk: Performs partition creation and management operations on GPT-based disks.
- Gparted: GParted (GNOME Partition Editor) is an open-source graphical tool for managing disk partitions.
- KDE Partition Manager: It is a powerful and easy-to-use tool used to manage disk partitions, running in the KDE desktop environment.
-
🧱Disk Partitioning Style:
There are generally two (2) styles for disk partitioning.
MBR (Master Boot Record) and GPT (GUID Partition Table)
>> MBR: Max: 2 TB
4 primary and 1 extended partitions can be created.
>> GPT: Max: 9.44 ZB (9.4 BILLION TERABABYTES)
128 primary partitions can be created. There is no extended partition.
💾⚙️ Standard Partitions: [Install, Configure]
Standard disk configuration in Linux usually includes standard partitions. This configuration divides the hard disk into physically separated partitions and formats each as a separate file system. If Linux systems do not have LVM (Logical Volume Manager), standard partitions are used by default.
Standard partitions are used to separate physical disk spaces of a certain size and format each with a separate file system. These partitions may be directories containing system files or user data, such as /boot, /home, /var .etc.
👨🏼💻 Standard Partitions: [Manage]
##System: RHELL / Centos
--------------------------------------------|
#[Standard Partitions] Install, Configure:
--------------------------------------------|
### Disk Configuration ###
#Disk/Directory Status:
sudo du -hla /storage/log
sudo du -hla --max-depth=1 / | sort -h
#Check Status:
ls -l /dev/sd*
df -Th
lsblk -p
sudo fdisk -l
#Check the disk added to the system: (SCSI or NVMe)
ls /sys/class/scsi_host/
echo "- - -" | tee /sys/class/scsi_host/host*/scan
echo "1" > /sys/class/block/sda/device/rescan
##Disk Partitioning##
1- #Using Fdisk: [sdb1, nvme0n2, ...]
sudo fdisk /dev/nvme0n2
2- #Using Cfdisk: [sdb1, nvme0n2, ...]
sudo cfdisk /dev/nvme0n2
3- #Using Parted: [sdb1, nvme0n2, ...]
sudo parted /dev/nvme0n2
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
m - print this help menu:
n - add a new partition:
p - print the partition table:
Create a new label
g - create a new empty GPT partition table [1-128 Partitions]
G - create a new empty SGI (IRIX) partition table
o - create a new empty DOS partition table
s - create a new empty Sun partition table
Partition type
p primary (0 primary, 0 extended, 4 free) [Max 4 pieces]
e extended (container for logical partitionsSelect (default p):[Unlimited]
*Specify the starting and ending sectors. You can use 100% of all unallocated space.
*Disk type will be [Linux] by default.
*To change this, use the [t] command.
*Specify the partition type and number we want to change.
#Write the changes to disk. [Attention!]
t - Change partition type:
L - List partition type:
8e - Set/change partition type:
#w - Write changes to disk:
p - List disk partitions:
q - Exit from fdisk tool:
#Introduce disk changes to the kernel:
partprobe -s
Disk/Partition Status:
sudo file -sL /dev/nvme0n2
sudo blkid /dev/repo_vg/logs
1- Disk, Partition Formatting [Ext3/Ext4]: (sdb1,nvme0n2p1, ..)
#sudo mkfs -t ext4 /dev/nvme0n2
#sudo mkfs -t ext4 /dev/nvme0n2p1
2- Disk, Partition Formatting [Xfs]: (sdb1,nvme0n2p1, ...)
#sudo mkfs -t xfs /dev/nvme0n2
#sudo mkfs -t xfs /dev/nvme0n2p1
#Folder Ops.:
sudo mkdir /alan
sudo mkdir -p /alan/hodl-77/xxx (sub tree)
#Mount & Umount Ops.:
sudo mount /dev/nvme0n2p1 /alan
sudo umount /dev/nvme0n2p1 /alan
sudo umount -l /dev/nvme0n2p1 /alan
#fstab edit: (Persistence)
sudo cp /etc/fstab /etc/fstab.old
cat /etc/fstab
#nano /etc/fstab
#/dev/nvme0n2p1 /alan ext4 defaults 0 0
sudo mount -av
sudo findmnt --verify
sudo systemctl daemon-reload
#Expand the size of the volume:
⦁ 📜Tutorials / Information:
#Reduce the size of the volume:
⦁ The partition can be reducing after the file system is reduce. (reverse process of expansion)
⚠️ Be careful and "back up" your data before these operations. Misconfiguration may result in "System crashes" and "Data loss"!
-------------------------------------------------------------------|
#[Standard Partitions] Manage: Extend and Reduce **Online/Offline
-------------------------------------------------------------------|
##>>A +Extend Operation##
#Check for errors with fsck:
sudo e2fsck -ff -v /dev/nvme0n2p1
sudo e2fsck -f /dev/nvme0n2p1
#A1 -First size Extend the Partition:
Fdisk tool:
Parted or Cdisk tool:
df -Th
#A2 -Later size Extend the File System:
⦁If you are using Ext3/Ext4: (resize2fs) [Online]
#sudo resize2fs /dev/nvme0n2p1 [%100]
#sudo resize2fs /dev/nvme0n2p1 18G [spesific]
df -Th
⦁If you are using Xfs: (xfs_growfs) [Online]
#sudo xfs_growfs -d /dev/nvme0n2p1 [%100]
#sudo xfs_growfs /dev/nvme0n2p1 18G [spesific]
df -Th
##>>B +Reducing Operation ## (only Ext3/Ext4, not Xfs)
#If you shrink more than the disk data, you will lose data!
#Check for errors with fsck:
sudo e2fsck -ff -v /dev/nvme0n2p1
sudo e2fsck -f /dev/nvme0n2p1
#B1 First size the File System: (Reverse)
⦁If you are using Ext3/Ext4: (resize2fs) [Offline]
sudo umount /dev/nvme0n2p1 /alan [umount]
sudo e2fsck -f /dev/nvme0n2p1
#sudo resize2fs /dev/nvme0n2p1 17G [spesific size]
sudo mount /dev/nvme0n2p1 /alan [try mount]
df -Th
🔄Data/Disk Migration and Disaster Recovery:
Data migration or copying is used to [Completely] transfer our existing data from old disk to a new disk. We typically perform these types of migrations when an error or malfunction occurs in the disks or when our storage requirements change.
It is an abbreviation for “dd” (disk dump) and is a command used in Unix and Unix-like operating systems. It is a powerful and flexible tool that basically reads/writes [block-by-block] from files or devices. There is also SSH support to transfer data with the remote server. It is used to write iso images and bootable USBs or to create disk images.
dd tool:
#dd if=/dev/sda of=/dev/nvme0n2 status=progress conv=fsync
#dd if=recovery-14.img of=rec-14.tar status=progress conv=fsync
☢️✅ Disaster Recovery:
Disk system disasters can cause serious problems in operating systems. These disasters usually occur in the form of data loss, file system corruption, or system crash.
💡 If you do not have an additional disk or are just focused on your data, you can access your data using 3rd party live disk/CD images, move it to an external area and try to recover it.
💡 The faulty partition/data be copied from the old disk to the new disk using "dd" (disk dump) and then the necessary configuration should be made on "fstab". On exit you should verify fstab and remove errors. You can then remove the faulty disk from the system. If the disk is removed from the system or the system is rebooted before the errors are resolved, it may not boot. You may need to use an external live disk image.
💡 It is recommended to always format the [/boot] partition with the [Ext] file system. This is because Ext file system support is available in the Linux Kernel. Other file systems (LVM, XFS, BTRS, etc.) come as modules and are located in the [/lib] directory.
root@ubuntu-siemnode4:~# lsblk -f
sda
├─sda1
└─sda2 LVM2_member xxx-xxx-xxx-xxx-xxx
└─/dev/repo_vg/logs ext4 xxx-xxx-xxx-xxx-xxx 580.4G 37% /LOGS
sdb
├─/dev/sdb1
├─/dev/sdb2 ext4 xxx-xxx-xxx-xxx-xxx 4.8GB 11% /boot
root@ubuntu-siemnode4:~#
fstab Configuration:
# /etc/fstab: static file system information.
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/repo_vg/logs / ext4 defaults 0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/xxx-xxx-xxx-xxx-xxx /boot ext4 defaults 0 1
fstab verifying:
sudo cp /etc/fstab /etc/fstab.old
sudo mount -av
sudo findmnt --verify
udo systemctl daemon-reload
##The same rules apply other systems.
⦁ Debian / Ubuntu
⦁ Slackware
⦁ Arch Linux
End of chapter 1 – Best Regards…