Systems Administration Y2 Sem 1 PDF
Document Details
Uploaded by NeatestZither
Fiona Redmond
Tags
Related
- FOS Unit 5 File Management PDF
- UEC01: Computer Skills & Programming Concepts I - Windows 10 Lab (1&2)
- Operating System Past Paper PDF PSM/KW/23/2571
- Operating System Past Paper PDF - Winter 2022
- Computer Systems - Bestandssystemen en File management PDF
- Operating Systems Concepts - File Management PDF
Summary
This document is a chapter from a Systems Administration textbook. It covers essential disk management concepts and commands for systems administrators, including adding storage, partitioning disks, formatting, and managing file systems within a Linux environment. The chapter details Linux drive naming conventions and commands like lsblk for verifying disk detection and provides examples.
Full Transcript
Systems Administration Y2 // Sem 1 3. Disk Management In this chapter, we'll cover essential disk management concepts and commands that are crucial for systems administrators. You will learn about tasks like adding storage, partitioning disks, formatting, and managing file systems. Caution D...
Systems Administration Y2 // Sem 1 3. Disk Management In this chapter, we'll cover essential disk management concepts and commands that are crucial for systems administrators. You will learn about tasks like adding storage, partitioning disks, formatting, and managing file systems. Caution Disk management can affect your data. Always back up important information before making changes. Important Please DO NOT try to create, modify or delete partitions or format existing partitions as this will make your VMs for this module unusable. 3.1. Adding storage 1. Adding Storage: Physical Disks: Connect the new disk to your server. Verify the disk is recognised in BIOS/UEFI, and ensure device files are created in /dev. Virtual Disks: In virtual environments (VMs or cloud), add a disk using the management tools or dashboards. Linux Drive Naming Basics Windows, which uses alphabetical letters to denote different drives (C:, D:, E:, etc.), whereas Linux has a different approach. In Linux, drives and partitions are represented as files and are located in the /dev directory. The naming of these files follows a specific pattern, usually in the format of sdXY or hdXY, where: X is a letter that represents the physical drive. The first drive is a, the second is b, and so on. Y is a number that represents the partition on the drive. The first partition is 1, the second is 2, and so forth. For instance, /dev/sda1 refers to the first partition on the first drive and /dev/sda2 refers to the second partition on the first drive while /dev/sdb1 refers to the first partition on the second drive and so on. sd stands for SCSI drives. However, it’s also used for SATA drives and SAS drives, which are commonly found in modern systems. hd stands for IDE or ATA drives. These are older types of drives that are not commonly used in modern systems. 2. Verify Detection: Use commands such as lsblk to check if the system recognises the new disk lsblk command The lsblk command lists all available block devices (disks and partitions). Example of what you might see when you run lsblk: Fiona Redmond Systems Administration Y2 // Sem 1 $ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk └─sda1 8:1 0 20G 0 part / sdb 8:16 0 40G 0 disk └─sdb1 8:17 0 20G 0 part /mnt/data sdc 8:32 1 120G 0 disk Explanation: NAME: Device name (e.g., sda, sda1). MAJ:MIN: Major and minor device numbers. RM: Whether the device is removable. SIZE: Size of the device or partition. RO: Whether the device is read-only. TYPE: Type of the device (e.g., disk, part). MOUNTPOINT: Where the partition is mounted. In the above example: sda is a physical disk with a 20GB size, and it contains a single partition sda1, which is mounted as the root filesystem ("/"). sdb is another physical disk with a 40GB size and a single partition sdb1, which is mounted at “/mnt/data” sdc is a removable disk (RM=1) with a 120GB size. It is not currently mounted. This output provides a clear overview of the available block devices, their sizes, mount points (if mounted), and other relevant information, making it useful for disk management and troubleshooting tasks. 3.2. Creating Partitions Partitions divide a disk into separate sections, each with its own file system. This helps in organising data and enhancing security. For example in the image shown a Linux hard disk could have these partitions: / (root) partition (one) - everything needed to bring system up in single-user mode (often copied onto another disk for emergencies) swap partition (at least one) – stores virtual memory when physical memory is insufficient /home partition - for user files such as home directories etc. /boot partition – for the boot loader, kernel, etc. Once a disk is attached and recognised, you can proceed to partition it. You can use tools like fdisk, parted, or gparted to create partitions on the newly attached disk. Fiona Redmond Systems Administration Y2 // Sem 1 fdisk command fdisk is a command-line utility used for managing disk partitions. You can use fdisk to display information about your disks and their partitions. Example output: Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors Disk model: ATA VBOX HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes... Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1026047 1024000 500M 83 Linux /dev/sda2 1026048 209715199 208689152 99.5G 83 Linux To display the total size of hard disks, you use the -l option, which lists all partitions and their sizes. $ sudo fdisk -l Disk /dev/sda: 500 GB, 500107862016 bytes, 976773168 sectors Disk /dev/sdb: 1 TB, 1000204886016 bytes, 1953525168 sectors Disk /dev/sda: 500 GB: Indicates that the total size of /dev/sda is 500 gigabytes. Disk /dev/sdb: 1 TB: Indicates that the total size of /dev/sdb is 1 terabyte. To filter the output of fdisk -l to show only the lines containing the word "Disk" you can use: $ sudo fdisk -l | grep Disk Disk /dev/sda: 500 GB, 500107862016 bytes, 976773168 sectors Disk /dev/sdb: 1 TB, 1000204886016 bytes, 1953525168 sectors fdisk -l | grep Disk filters this output to show only the total sizes of the disks, making it easier to read the relevant information. Explanation: sudo fdisk -l: Lists the partitions and disks. |: The pipe symbol passes the output of fdisk -l to the next command. grep Disk: Filters the output to show only lines containing the word "Disk". Warning **Remember you should NOT create, modify or delete partitions or format partitions on your VMs for this module as this could make them unusable. Be cautious when using fdisk because any changes made to disk partitions can result in data loss. Always backup important data before using fdisk. Fiona Redmond Systems Administration Y2 // Sem 1 3.3. Formatting and Building File Systems After creating a partition, format it with a file system to organise and manage data. Filesystem Types supported by Linux ext4: Default for many Linux distributions, supports large file systems and is stable. xfs: Default in some distributions like Red Hat, good for large files. btrfs: Supports advanced features like snapshots and built-in RAID. Use the mkfs command to create a File System: You specify which file system you want to use by entering the –t option and the type of file system. mkfs -t : This is the type of file system you want to create (e.g., ext4, xfs, btrfs). : This is the device or partition where you want to create the file system (e.g., /dev/sdX1). Example of Creating an ext4 File System: To format the new partition as ext4, use the mkfs.ext4 command like so: sudo mkfs.ext4 /dev/sdX1 To create an XFS file system on a partition, you would use the mkfs.xfs command. Important Please DO NOT try to format partitions as this will make your VMs for this module unusable. Formatting will erase all data on the partition. 3.4. Mounting and Unmounting Mounting makes a file system accessible, while unmounting detaches it. Example of Creating a Mount Point and Mounting: You first need to decide on a directory where you want to create the mount point. This directory should be empty or should not contain important data, as the contents of the mounted file system will overlay it. Let's say you have a partition on /dev/sdb1 that you want to mount to a directory named mydata in /mnt. Here's how you can create the mount point and mount the partition: Create a mount point (an empty directory) where you want to attach the partition. Use the mkdir command to create the directory. The external device or file system becomes accessible through this directory. For example, to create a mount point named "mydata" in the /mnt directory: sudo mkdir /mnt/mydata Fiona Redmond Systems Administration Y2 // Sem 1 You typically need superuser (root) permissions to create directories in system directories like /mnt, so you might need to use sudo. Mount the filesystem: Once the mount point is created, use the mount command to attach the partition to the mount point: sudo mount /dev/sdX1 /mnt/mydata After mounting, you can read and write data to the attached disk as if it were any other directory in your filesystem. Replace /dev/sdX1 with the actual device name or file system you want to mount. To unmount a filesystem, use: sudo umount /mnt/mydata Unmounting is the process of detaching a file system from its mount point, making it no longer accessible. Make sure you're not currently using any files or directories within the file system, as they must be closed before unmounting. To display details of all mounted filesystems use the mount command without any options like so: $ mount # Sample Output /dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro) /dev/sda2 on /boot type ext4 (rw,relatime) /dev/sdb1 on /mnt/backup type ext4 (rw,noatime) tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755) This output shows several partitions and temporary filesystems mounted on the system: /dev/sda1 is the root filesystem, mounted as ext4 in read-write mode, with error handling set to remount as read-only if errors occur. /dev/sda2 is the /boot partition, also using ext4 in read-write mode. /dev/sdb1 is a backup partition mounted on /mnt/backup, using ext4 with access time tracking disabled for performance. tmpfs is a temporary memory-based filesystem mounted on /run with specific restrictions (nosuid, nodev). Automounting: By default, file systems mounted using the mount command are not automatically mounted at system boot. To ensure a file system is mounted automatically at boot, you can add an entry to the /etc/fstab (file system table) file. (Almost) every filesystem that the system knows about automatically is in /etc/fstab. Example entry in /etc/fstab: /dev/sdX1 /mnt/mydata ext4 defaults 0 0 Fiona Redmond Systems Administration Y2 // Sem 1 3.5. Checking the File System Use fsck to check and repair file systems. Run on unmounted file systems to avoid data corruption. Example command: sudo fsck /dev/sdX1 3.6. Logical Volume Management (LVM) LVM provides flexible disk management by abstracting physical storage into logical volumes. It abstracts the physical storage devices (such as hard drives or SSDs) into logical volumes (LVs) and volume groups (VGs), making it easier to manage disk space, resize volumes, and create snapshots. Red Hat Enterprise Linux includes support for LVM. LVM Components: Physical Volume (PV): The actual disk or partition. Volume Group (VG): A collection of PVs. Logical Volume (LV): A virtual partition within a VG. Steps to set up LVM: 1. Initialise a physical volume (PV): pvcreate /dev/sdX 2. Create a volume group (VG): vgcreate my_vg /dev/sdX 3. Create logical volumes (LV) within the volume group: lvcreate -L 10G -n my_lv my_vg 4. Format the logical volume: mkfs.ext4 /dev/my_vg/my_lv 5. Mount it: mount /dev/my_vg/my_lv /mnt/mydisk Example: This shows that two physical volumes hda1 and hdc1 were used for volume group diskvg which was used to create the logical volumes usrlv, rootlv and varlv. Each of which are of different filesystem types. LVM is a valuable tool for managing disk space, especially in environments where storage needs change over time. Checking Disk Usage df Command The df command in Linux is used to report file system disk space usage. $ df Fiona Redmond Systems Administration Y2 // Sem 1 Explanation: Filesystem: Filesystem name. Size: Total size of the filesystem. Used: Space used. Avail: Space available. Use%: Percentage of space used. Mounted on: Mount point. The -h option modifies the output of df to display the sizes in a human-readable format (e.g., KB, MB, GB). Example Output from df -h: Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 43% / /dev/sda2 50G 10G 37G 22% /home The -T option modifies the output of df to show the type of filesystem in the output. Example Output from df -Th: Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cl-root xfs 50G 10G 41G 21% / /dev/sda1 xfs 1.0G 200M 800M 21% /boot /dev/sdb1 ext4 100G 20G 75G 21% /mnt/data tmpfs tmpfs 16G 1.0M 16G 1% /run Checking Disk Space and Usage du Command The du command shows disk usage of files and directories. $ du -sh /path/to/directory Explanation: o -s: Summarises total size of the directory. o -h: Human-readable format (e.g., KB, MB, GB). Example Output: 1.5G /home/user 3.7. Lab Sheet Lab Instructions 1. Download the file named Lab3_DiskMgmt_FirstNameLastName from Blackboard. 2. Rename it to include your first and last name. 3. As you complete each task, record the command(s) used in the document. 4. Once all tasks are complete, submit the renamed document via the relevant Blackboard link. Fiona Redmond