This training covers:
This training covers:
- Creating partitions using fdisk
- Creating and mounting ext2, ext3, ext4 and XFS filesystems
- Primary, extended and logical partitions
- Expanding a partition after increasing disk size
- Creating and managing LVM
- Expanding LVM physical volumes, volume groups and logical volumes
- Adding additional disks to LVM
- Migrating LVM data using pvmove
- Removing disks from an LVM configuration
- Understanding Linux inodes
- Demonstrating inode consumption
- Creating and configuring swap
- Checking directory and filesystem usage
- Creating partitions using fdisk
- Creating and mounting ext2, ext3, ext4 and XFS filesystems
- Primary, extended and logical partitions
- Expanding a partition after increasing disk size
- Creating and managing LVM
- Expanding LVM physical volumes, volume groups and logical volumes
- Adding additional disks to LVM
- Migrating LVM data using pvmove
- Removing disks from an LVM configuration
- Understanding Linux inodes
- Demonstrating inode consumption
- Creating and configuring swap
- Checking directory and filesystem usage
2. File Systems
A filesystem provides the structure used by an operating system to store, organize, retrieve and manage files on storage devices.
The lab introduces the following filesystems:
FilesystemFAT: Basic and simple filesystem with broad compatibility.FAT32: FAT variant with larger capacity support but approximately 4 GB maximum per file.NTFS: Windows filesystem providing journaling, permissions and security features. ext3: Linux filesystem that introduced journaling to the ext filesystem family.ext4: Modern Linux filesystem and successor to ext3. XFS: Scalable, high-performance Linux filesystem commonly used for enterprise workloads.
The lab introduces the following filesystems:
3. Check Existing Disk Layout
First check the existing disks and partitions.[root@rocky ~]# lsblk
Example environment:
sda 16G
├─sda1 600M /boot/efi
├─sda2 1G /boot
└─sda3 14.4G
├─rl-root 12.8G /
└─rl-swap 1.6G [SWAP]
A new 4 GB disk /dev/sdb is then added to the server.
Example environment:
sda 16G
├─sda1 600M /boot/efi
├─sda2 1G /boot
└─sda3 14.4G
├─rl-root 12.8G /
└─rl-swap 1.6G [SWAP]
A new 4 GB disk /dev/sdb is then added to the server.
4. Create Four Partitions Using fdisk
5. Create Filesystems
Create the filesystems:[root@rocky ~]# mkfs.ext3 /dev/sdb5[root@rocky ~]# mkfs.ext4 /dev/sdb6[root@rocky ~]# mkfs.xfs /dev/sdb7
[root@rocky ~]# mount /dev/sdb6 /data-ext4
[root@rocky ~]# mount /dev/sdb5 /data-ext3/
[root@rocky ~]# mount /dev/sdb1 /data-ext2
[root@rocky ~]# mount /dev/sdb7 /data-xfs/Training observation: The supplied lab shows /dev/sdb1 as ext2 in the df output, but does not show a preceding mkfs.ext2 command. Preserve this sequence when demonstrating the supplied lab.
6. Test Filesystem Usage
7. Extend a Partition After Increasing Disk Size
7.2 Why Can Only sdb7 Be Extended Directly?
The original layout is:sdb1 → 1G
sdb2 → Extended partition
├─ sdb5 → 1G
├─ sdb6 → 1G
└─ sdb7 → 1020M
After the disk is expanded, the additional space exists after /dev/sdb7.Therefore:- /dev/sdb1 cannot directly use that space because other partitions exist after it.
- /dev/sdb5 cannot directly use the space because /dev/sdb6 and /dev/sdb7 follow it.
- /dev/sdb6 cannot directly use the space because /dev/sdb7 follows it.
- /dev/sdb7 is the last partition, so the new free space is immediately after it.
This is why the supplied lab demonstrates extending /dev/sdb7.
sdb1 → 1G
sdb2 → Extended partition
├─ sdb5 → 1G
├─ sdb6 → 1G
└─ sdb7 → 1020M/dev/sdb7.- /dev/sdb1 cannot directly use that space because other partitions exist after it.
- /dev/sdb5 cannot directly use the space because /dev/sdb6 and /dev/sdb7 follow it.
- /dev/sdb6 cannot directly use the space because /dev/sdb7 follows it.
- /dev/sdb7 is the last partition, so the new free space is immediately after it.
8. Recreate the Extended Partition
9. Grow the XFS Filesystem
10. Create a Partition and Put It Under LVM
11. Create LVM Physical Volume
12. Create Filesystems on LVM
13. Configure /etc/fstab
14. Test LVM Filesystems
15. Expand the LVM Disk
16. Expand the LVM Partition is (disadvantage hence we should always take disk under LVM without fdisk partition)
17. Resize the LVM Physical Volume
18. Extend ext3 Logical Volume
Increase the LV:
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3
Resize the filesystem:
[root@rocky ~]# resize2fs /dev/mapper/vg01-lv--ext3
Increase the LV:
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3
Resize the filesystem:
[root@rocky ~]# resize2fs /dev/mapper/vg01-lv--ext319. Extend ext4 Logical Volume
Increase the LV:
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext4
Resize the filesystem:
[root@rocky ~]# resize2fs /dev/mapper/vg01-lv--ext4
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext4
Resize the filesystem:
[root@rocky ~]# resize2fs /dev/mapper/vg01-lv--ext4
20. Extend XFS Logical Volume
21. Add a New Disk to LVM
Add a new 3 GB /dev/sdc disk.
Verify:
[root@rocky ~]# lsblk
Create a physical volume directly on /dev/sdc:
[root@rocky ~]# pvcreate /dev/sdc
Check:
[root@rocky ~]# pvs
[root@rocky ~]# vgs
[root@rocky ~]# lvs
Add the new PV to vg01:
[root@rocky ~]# vgextend vg01 /dev/sdc
Verify:
[root@rocky ~]# pvs
[root@rocky ~]# vgs
[root@rocky ~]# lsblk
[root@rocky ~]# pvcreate /dev/sdc
[root@rocky ~]# pvs
[root@rocky ~]# vgs
[root@rocky ~]# lvs
[root@rocky ~]# vgextend vg01 /dev/sdc
[root@rocky ~]# pvs
[root@rocky ~]# vgs
22. Extend LVs Using New Disk Space
The supplied lab uses -r, which automatically resizes the filesystem after extending the LV.
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3 -rn
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext4 -rn
[root@rocky ~]# lvextend -L 2.9G /dev/mapper/vg01-lv--xfs -rn
Or, as demonstrated in the supplied lab, these can be executed as one command line:
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3 -rn ; lvextend -L +1G /dev/mapper/vg01-lv--ext4 -rn ; lvextend -L 2.9G /dev/mapper/vg01-lv--xfs -rn
Verify:
[root@rocky ~]# df -PTH /data*
Expected sizes are approximately:
ext3 3.2G
ext4 3.2G
xfs 3.2G
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3 -rn
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext4 -rn
[root@rocky ~]# lvextend -L 2.9G /dev/mapper/vg01-lv--xfs -rn
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3 -rn ; lvextend -L +1G /dev/mapper/vg01-lv--ext4 -rn ; lvextend -L 2.9G /dev/mapper/vg01-lv--xfs -rn
[root@rocky ~]# df -PTH /data*
Expected sizes are approximately:
ext3 3.2G
ext4 3.2G
xfs 3.2G
23. LVM Data Migration Using pvmove
23.1 Move Data from sdc to sdd
[root@rocky ~]# pvmove /dev/sdc /dev/sdd
Verify:
[root@rocky ~]# pvs
The expected result is that /dev/sdc becomes free while the allocated extents are moved to /dev/sdd.
[root@rocky ~]# pvmove /dev/sdc /dev/sdd
Verify:
[root@rocky ~]# pvs
The expected result is that /dev/sdc becomes free while the allocated extents are moved to /dev/sdd.
23.2 Move Data from sdb1 to sdd
24. Remove Old Physical Volumes
25. Remove the Old sdb Partition
Start:
[root@rocky ~]# fdisk /dev/sdb
Display the partition table:
Command (m for help): p
Delete partition 1:
Command (m for help): d
Verify:
Command (m for help): p
Write:
Command (m for help): w
Check:
[root@rocky ~]# lsblk
The expected final LVM storage is on /dev/sdd.
Verify mounted filesystems:
[root@rocky ~]# df -PTh /data*
The supplied lab shows:
/dev/mapper/vg01-lv--ext3 ext3 3.0G 901M 2.0G 32% /data-ext3
/dev/mapper/vg01-lv--ext4 ext4 3.0G 901M 1.9G 32% /data-ext4
/dev/mapper/vg01-lv--xfs xfs 2.9G 954M 2.0G 33% /data-xfs
Start:
[root@rocky ~]# fdisk /dev/sdb
Display the partition table:
Command (m for help): p
Delete partition 1:
Command (m for help): d
Verify:
Command (m for help): p
Write:
Command (m for help): w
Check:
[root@rocky ~]# lsblk
The expected final LVM storage is on /dev/sdd.
Verify mounted filesystems:
[root@rocky ~]# df -PTh /data*
The supplied lab shows:
/dev/mapper/vg01-lv--ext3 ext3 3.0G 901M 2.0G 32% /data-ext3
/dev/mapper/vg01-lv--ext4 ext4 3.0G 901M 1.9G 32% /data-ext4
/dev/mapper/vg01-lv--xfs xfs 2.9G 954M 2.0G 33% /data-xfs
26. Understanding Inodes
An inode is a filesystem data structure that stores metadata about a file.
The inode contains information such as:- File type
- File permissions
- Owner
- Group
- File size
- Timestamps
- Links
- Locations of filesystem data blocks
The inode contains information such as:
- File type
- File permissions
- Owner
- Group
- File size
- Timestamps
- Links
- Locations of filesystem data blocks
A filesystem can have free disk space while still running out of inodes.
Check inode usage:
[root@rocky ~]# df -iPTH /data*Example from the lab:
Filesystem Type Inodes IUsed IFree IUse%
/dev/mapper/vg01-lv--ext3 ext3 197k 12 197k 1%
/dev/mapper/vg01-lv--ext4 ext4 197k 12 197k 1%
/dev/mapper/vg01-lv--xfs xfs 1.6M 4 1.6M 1%27. Demonstrate Inode Consumption
Create 100,000 files on ext3:
[root@rocky ~]# for i in {1..100000}; do
> touch /data-ext3/file_$i
> doneCreate 100,000 files on ext4:
[root@rocky ~]# for i in {1..100000}; do
> touch /data-ext4/file_$i
> doneCreate 1,000,000 files on XFS:
[root@rocky ~]# for i in {1..1000000}; do
> touch /data-xfs/file_$i
> doneCheck inode consumption:
[root@rocky ~]# df -iPTH /data*The supplied lab demonstrates increased inode usage:
ext3 197k → 101k used
ext4 197k → 101k used
xfs 1.6M → 522k used28. Demonstrate Inode Increase After Filesystem Expansion
Check the volume group:
[root@rocky ~]# vgsExtend ext3 by 1 GB:
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3The lab then extends it again with automatic filesystem resizing:
[root@rocky ~]# lvextend -L +1G /dev/mapper/vg01-lv--ext3 -rnCheck inode usage:
[root@rocky ~]# df -iPTH /data*This demonstrates that filesystem expansion can also provide additional inode capacity, depending on filesystem design.
29. Configure Swap Partition
Add a 2 GB /dev/sdc disk.
Check:
[root@rocky ~]# lsblk[root@rocky ~]# fdisk /dev/sdcCommand (m for help): nSelect (default p): pPartition number: 1First sector: <Enter>Last sector: <Enter>Command (m for help): tSelected partition 1Hex code (type L to list all codes): 82Command (m for help): pCommand (m for help): w
fdisk:Create a primary partition:
Change the partition type:
Verify:
Write:
30. Create and Enable Swap
Check current swap:
[root@rocky ~]# free -h[root@rocky ~]# mkswap /dev/sdc1[root@rocky ~]# swapon /dev/sdc1[root@rocky ~]# free -h
Enable it:
Verify:
The supplied lab shows swap increasing from approximately 1.6 GiB to 3.6 GiB after enabling
/dev/sdc1.31. Make Swap Persistent
Check /etc/fstab:
[root@rocky ~]# cat /etc/fstab | grep -v "#"/dev/sdc1 none swap defaults 0 0
This ensures the swap partition is configured to be activated during boot.
32. Check Directory Size
[root@rocky ~]# du -sh /var[root@rocky ~]# du -sh /var/log
To check the total size of /var:
To check a specific directory:
/var:To check a specific directory:
33. Identify Large Directories
To identify which directories under /var are consuming the most space:
[root@rocky ~]# du -h --max-depth=1 /var | sort -hr
8.5G /var
5.2G /var/log
2.1G /var/cache
800M /var/lib
Example:
This is useful when troubleshooting a filesystem that is running out of space.
/var are consuming the most space:[root@rocky ~]# du -h --max-depth=1 /var | sort -hr
8.5G /var
5.2G /var/log
2.1G /var/cache
800M /var/lib
This is useful when troubleshooting a filesystem that is running out of space.
No comments:
Post a Comment