Network and System Administration Three

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Chapter three

3.1 File System Administration:


File system administration involves various tasks such as partitioning disks, creating and
maintaining file systems, managing swap space, determining disk usage, and configuring disk
quotas. Let's explore each of these topics in detail:
3.1.1 Partitioning Disks with fdisk and parted:
Partitioning disks involves dividing a physical disk into multiple logical sections known as
partitions. This process allows you to organize and manage data more efficiently. Two
commonly used tools for disk partitioning are fdisk and parted.
 fdisk: It is a command-line tool used for partitioning disks in Linux. It allows you to
create, delete, and modify partitions on a disk. Here's an example of using fdisk to
partition a disk:
sql_more

$ sudo fdisk /dev/sdb


Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
Command (m for help): w
In the above example, we partitioned the /dev/sdb disk by creating a new primary partition.
 parted: It is another command-line utility for partitioning disks. It provides a more user-
friendly interface compared to fdisk. Here's an example of using parted to partition a
disk:
Copy
$ sudo parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart primary ext4 0% 50%
(parted) mkpart primary ext4 50% 100%
(parted) print
In the above example, we used parted to partition /dev/sdb into two primary partitions, each
formatted with the ext4 file system.
3.1.2 Creating, Mounting, and Maintaining File Systems:
Once you have partitioned a disk, you need to create a file system on each partition to store data.
The most commonly used file systems in Linux are ext4, XFS, and Btrfs.
To create a file system, you can use the mkfs command followed by the appropriate file system
type. For example:
Copy
$ sudo mkfs.ext4 /dev/sdb1
This command creates an ext4 file system on the /dev/sdb1 partition.
After creating a file system, you can mount it to a directory in the file system hierarchy using
the mount command. For example:
$ sudo mount /dev/sdb1 /mnt/data
This command mounts the /dev/sdb1 partition to the /mnt/data directory.
To maintain file systems, you can perform tasks like checking the file system integrity
(fsck command), resizing partitions, resizing file systems, etc.
3.1.3 Swap:
Swap space is a dedicated area on a disk used by the operating system as virtual memory when
the physical memory (RAM) is full. It allows the system to continue running even when it runs
out of physical memory.
To create a swap partition, you can use fdisk or parted as explained in section 3.1.1. Once the
partition is created, you can format it as a swap file system using the mkswap command:

$ sudo mkswap /dev/sdb2


After creating the swap partition, you can enable it using the swapon command:

$ sudo swapon /dev/sdb2


3.1.4 Determining Disk Usage With df and du:
The df and du commands are used to determine disk usage on a Linux system.
 df: It displays information about the file system disk space usage. For example:
apache

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 8.1G 11G 44% /
/dev/sdb1 100G 50G 50G 50% /mnt/data
In the above example, the df command shows the size, used space, available space, and
utilization percentage of mounted file systems.
 du: It estimates file and directory space usage. For example:

$ du -sh /var/log
2.5G /var/log
In the above example, the du command displays the total size of the /var/log directory.
3.1.5 Configuring Disk Quotas:
Disk quotas allow system administrators to limit the amount of disk space a user or a group can
use on a file system. This helps in preventing users from consuming excessive disk space.
The disk quota configuration involves the following steps:
1. Enable quota support on the file system by adding the appropriate options to
the /etc/fstab fileand remounting the file system.
2. Initialize the quota database using the quotacheck command.
3. Set the quota limits for users or groups using the edquota command.
4. Enable the quotas using the quotaon command.
Here's an example of configuring disk quotas for a user on the /home file system:
1. Edit the /etc/fstab file and add the usrquota option to the /home file system entry:
/dev/sdb1 /home ext4 defaults,usrquota 0 0
2. Remount the /home file system to enable the quota support:
basic
$ sudo mount -o remount /home
3. Initialize the quota database:
$ sudo quotacheck -cug /home
4. Set the quota limits for a user:
$ sudo edquota username
This opens a text editor where you can specify the soft and hard limits for disk space usage for
the user.
5. Enable the quotas:

$ sudo quotaon /home


Now, the disk quotas are configured, and the user will have limits on disk space usage.
3.2 Logical Volume Management (LVM) and RAID:
3.2.1 Implementing LVM, Creating Logical Volumes (LVs), Manipulating VGs & LVs:
Logical Volume Management (LVM) provides a flexible way to manage disk storage in Linux. It
allows you to concatenate, stripe, and mirror physical volumes (PVs) to create logical volumes
(LVs) that can be resized and moved dynamically.
To implement LVM, you need to perform the following steps:
1. Initialize physical volumes using the pvcreate command:

$ sudo pvcreate /dev/sdb1


2. Create a volume group (VG) using the vgcreate command:

$ sudo vgcreate vg1 /dev/sdb1


3. Create logical volumes (LVs) within the volume group using the lvcreate command:

$ sudo lvcreate -L 10G -n lv1 vg1


This creates an LV named lv1 with a size of 10GB in the vg1 volume group.
4. Format the logical volume with a file system:

$ sudo mkfs.ext4 /dev/vg1/lv1


5. Mount the logical volume:
$ sudo mount /dev/vg1/lv1 /mnt/data
Now, the logical volume is created, formatted, and mounted.
You can also manipulate VGs and LVs by extending or reducing their sizes, moving them to
different PVs, creating snapshots, etc., using commands
like vgextend, lvextend, lvreduce, pvmove, etc.
3.2.2 Advanced LVM Concepts (i.e., system-config-lvm):
system-config-lvm is a graphical tool for managing LVM in Linux. It provides a user-friendly
interface to perform various LVM operations such as creating PVs, VGs, LVs, extending
volumes, etc. It simplifies the LVM management process by presenting an intuitive graphical
interface.
To use system-config-lvm, you can install it on your Linux system and launch it from the
desktop environment or command line. The tool guides you through the steps required to
perform LVM operations.
3.2.3 RAID Concepts (Creating and Managing a RAID-5 Array):
RAID (Redundant Array of Independent Disks) is a technology that combines multiple physical
disks into a single logical unit to improve performance, reliability, or both.
To create a RAID-5 array, which provides both performance and redundancy, you need at least
three disks. Here's an example of creating and managing a RAID-5 array using
the mdadm command:
1. Create a RAID-5 array:
$ sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1
This command creates a RAID-5 array named /dev/md0 using three disks (/dev/sdb1, /dev/sdc1,
and /dev/sdd1).
2. Format the RAID array with a file system:
$ sudo mkfs.ext4 /dev/md0
3. Mount the RAID array:
$ sudo mount /dev/md0 /mnt/raid
Now, the RAID-5 array is created, formatted, and mounted.
You can also perform tasks like monitoring the RAID array status, adding or removing disks,
replacing failed disks, and rebuilding the array using commands like mdadm --detail, mdadm --
add, mdadm --fail, mdadm --remove, `mdadm --re

You might also like