0% found this document useful (0 votes)
41 views8 pages

Linux - Disk Management

The document provides an overview of disk management in Linux, including partitioning, RAID, and LVM. It details tools like fdisk and parted for managing disk partitions, as well as the functions and comparisons of boot loaders such as GRUB and LILO. Additionally, it covers the setup and management of RAID and LVM for improved performance and flexibility in storage management.

Uploaded by

thirosul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views8 pages

Linux - Disk Management

The document provides an overview of disk management in Linux, including partitioning, RAID, and LVM. It details tools like fdisk and parted for managing disk partitions, as well as the functions and comparisons of boot loaders such as GRUB and LILO. Additionally, it covers the setup and management of RAID and LVM for improved performance and flexibility in storage management.

Uploaded by

thirosul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1

Disk management

Disk management in Linux is the process of organizing and managing storage devices, like hard drives, USB
drives, and solid-state drives. It also involves managing file systems.

Disk Management is an important functionality provided by the Operating System which can be used to
create, delete, format disk partitions, and much more. It enables users to manage and view the different disks
and functions like viewing, creating, deleting, and shrinking the partitions associated with the disk drives

 Disk Partitioning-RAID, and LVM in Linux:


Disk partitioning is the process of dividing a hard disk into separate sections to manage data
efficiently. In Linux, advanced storage solutions like RAID (Redundant Array of Independent Disks) and
LVM (Logical Volume Manager) help improve performance, redundancy, and flexibility.

Disk Partitioning in Linux:


Partitioning allows dividing a disk into logical sections using tools like:

 fdisk – Traditional partitioning tool for MBR.


 gdisk – Works with GPT partitions.
 parted – Supports both MBR and GPT.
 lsblk – Lists available partitions.

Example: Partitioning a Disk Using fdisk

1. Open the disk for partitioning:

$sudo fdisk /dev/sdb

2. Create a new partition (n → enter details).


3. Write changes (w).
4. Format the partition:

$sudo mkfs.ext4 /dev/sdb1

5. Mount it:

sudo mount /dev/sdb1 /mnt

1. RAID (Redundant Array of Independent Disks):


RAID is a technology that combines multiple disks to improve performance and redundancy. Linux
supports software RAID via the mdadm tool.

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj


2
RAID Levels:

RAID Level Description


RAID 0 Striping, improves speed but no redundancy.
RAID 1 Mirroring, provides redundancy (copies data on two disks).
RAID 5 Striping with parity, requires at least 3 disks.
RAID 6 Double parity, requires at least 4 disks.
RAID 10 Combination of RAID 1 and RAID 0 (mirrored striping).

Example: Creating RAID 1 (Mirroring)

1. Install mdadm:

sudo apt install mdadm # (Debian/Ubuntu)

sudo yum install mdadm # (RHEL/CentOS)

sudo dnf install mdadm –y # fedora

2. Create a RAID 1 array:

sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc

3. Save RAID configuration:

sudo mdadm --detail --scan >> /etc/mdadm/mdadm.conf

4. Create a filesystem:

sudo mkfs.ext4 /dev/md0

5. Mount it:

sudo mount /dev/md0 /mnt

Check RAID Status

$cat /proc/mdstat

2. LVM (Logical Volume Manager):


LVM provides flexible disk management by creating logical volumes from physical storage.

LVM Components

Component Description
Physical Volume (PV) Actual disk or partition.
Volume Group (VG) Combines multiple PVs.
Logical Volume (LV) Created from a VG, can be resized easily.

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj


3
Example: Setting Up LVM

1. Create Physical Volume (PV)

sudo pvcreate /dev/sdb /dev/sdc

2. Create a Volume Group (VG)

sudo vgcreate my_vg /dev/sdb /dev/sdc

3. Create a Logical Volume (LV)

sudo lvcreate -L 10G -n my_lv my_vg

4. Format and Mount

sudo mkfs.ext4 /dev/my_vg/my_lv

sudo mount /dev/my_vg/my_lv /mnt

Expanding an LVM Volume

1. Extend LV:

sudo lvextend -L +5G /dev/my_vg/my_lv

2. Resize filesystem:

sudo resize2fs /dev/my_vg/my_lv

 RAID vs. LVM:

Feature RAID LVM


Purpose Redundancy & performance Flexible storage management
Data Protection Yes (except RAID 0) No (unless combined with RAID)
Performance Boost Yes (RAID 0, 5, 10) No
Expandability Limited Easily resizable

 Disk related Management Tools:


In Linux, disk management tools help monitor, manage, and optimize storage devices. These tools
can be used for partitioning, formatting, checking disk usage, and performance monitoring.

There are two:

 Fdisk
 Parted

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj


4
1] Fdisk:
The fdisk also known as format disk is a dialog-driven command in Linux used for creating and
manipulating disk partition table. It is used for the view, create, delete, change, resize, copy and move
partitions on a hard drive using the dialog-driven interface.
The fdisk allows you to create a maximum of four primary partitions and the number of logical
partitions depends on the size of the hard disk you are using.

Syntax:

#fdisk [options] device


or
#fdisk -l [device...]

inside fdisk, you can use the following options:

Command Description
m Show help menu
p Print current partition table
n Create a new partition
d Delete an existing partition
t Change partition type
w Write changes and exit
q Quit without saving

Example: Step-by-Step Guide to Using fdisk.


Step 1: Before using fdisk, check the available disks on your system:

#lsblk

This will show all the disks and their partitions.

Step 2: Open a Disk for Partitioning means choose device name which you want to partition. (You can see
all the disk and their partitions using above lsblk command)

#fdisk /dev/sdb

Step 3: Create a New Partition.

1. Command (m for help):


Press n and hit Enter to create a new partition.

2. Partition number (4-128, default 4):


hit Enter select automatic default partition number.

3. First sector (41940992-46137310, default 41940992):


hit Enter it select automatic default sector.

4. Last sector, +/-sectors or +/-size{K,M,G,T,P} (41940992-46137310, default 46135295):


Specify the last sector or enter the partition size (e.g., +10G for a 10GB partition).

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj


5
Step 4: Write Changes to Disk

Command (m for help): w


The partition table has been altered shows the message.
Syncing disks.

Step 5: Format the partition: After creating the partition, format it with a filesystem (e.g. ext4):

#mkfs.ext4 /dev/sdb1
Replace /dev/sdb with the newly created partition.

Step 6: Mount the partition:

#mkdir /mnt/mydisk
#mount /dev/sdX1 /mnt/mydisk

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj


6
2] Parted:
The parted (GNU Parted) is a powerful disk partitioning tool in Linux that allows users to create,
resize, and manage disk partitions. It supports both MBR (Master Boot Record) and GPT (GUID
Partition Table) partitioning schemes, making it more advanced than fdisk.

Why Use parted?


 Supports GPT, which is required for large disks (>2TB).
 Can resize partitions without data loss (if used carefully).
 Works with both MBR and GPT partition tables.
 Supports scripted execution for automation.

Syntax:

#parted [options] [device]

For example, to work on /dev/sdb:

#parted /dev/sdb

Step-by-Step Guide to Using parted

Step 1: List Available Disks, to see all disks:

#parted –l

Step 2: Start parted on a Specific Disk


To work on a disk (e.g., /dev/sdb):

#parted /dev/sdb

Step 3: Check the Partition Table Type. Inside parted, check the partition table type:

#print

If needed, create a GPT partition table:

#mklabel gpt

For MBR:

#mklabel msdos
⚠ Warning: This erases all partitions on the disk!

Creating a New Partition


Step 4: Create a Partition, Use the mkpart command to create a partition.

Example (creating a 20GB ext4 partition):

#mkpart primary ext4 1MiB 20GiB


primary → Partition type
ext4 → Filesystem type (can be ext3, fat32, etc.)

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj


7
1MiB → Start position
20GiB → End position

Step 5: Verify the Partition

#print

Step 6: Format the Partition

#mkfs.ext4 /dev/sdb1

Step 7: Mount the Partition


Create a mount point and mount it:

#mkdir /mnt/mydisk
#mount /dev/sdb1 /mnt/mydisk

 What is a boot loader:


A boot loader, also called a boot manager, is a small program that is responsible for loading the
operating system (OS) into memory when the computer is powered on. When a computer is powered-up or
restarted, the basic input/output system (BIOS) performs some initial tests, and then transfers control to the
Master Boot Record (MBR) where the boot loader resides. It is the first software that runs after the system
firmware (BIOS/UEFI) initializes the hardware.

Functions of a Boot loader:

1. Initialize Hardware: Sets up CPU, memory, and essential devices.


2. Load Kernel: Loads the Linux kernel into memory.
3. Pass Control: Transfers execution to the kernel to start the OS.
4. Provide Boot Options: Allows selection between multiple OS installations (dual-boot setups).
5. Kernel Parameters: Can modify kernel boot parameters (e.g., enabling debugging or recovery
modes).

In Linux there are two most common boot loaders:

1] LILO (LInux LOader).


2] GRUB (GRand Unified Bootloader).
3] Custom Loaders

1] LILO (LInux LOader):

LILO is a Linux boot loader found in Linux-based devices that have been one of the most widely used and
oldest boot loaders. The development of LILO went via many stages. The LILO was updated or changed by
three developers. Werner Almesberger worked on LILO from 1992 to 1995, John Coffman worked
from 1997 to 2007, and Joachim Wiedorn has been with the project since 2000. LILO has been simplified
and made easier to use due to these three developers.

It only supports a single OS, which is Linux OS. It has been the default boot loader of Linux OS based devices
for several years after gaining popularity from loading. Compared to GRUB, it's an outdated boot loader and
lacks a graphical user interface menu option.

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj


8
Although GRUB is now present in most OS systems, LILO and ELILO are still incredibly popular in the
modern days. LILO software has been good and dependable, keeping the propriety and operating system
effectively.

2] GRUB (GRand Unified Bootloader):

GRand Unified Bootloader (GRUB) is a boot loader created by the GNU project. GRUB allows the user to
choose from a list of operating systems to load, allowing numerous operating systems to run on the same
machine. GRUB is the default boot loader in most modern Linux distributions. GRUB may be customized
dynamically since it permits changes to the configuration during boot. Users are given a simple command line
interface through which they can dynamically input new boot configurations. GRUB provides several user-
friendly characteristics, such as high portability, independence from geometry translation, support for many
executable formats, and support for many file systems, including most UNIX systems, NTFS,
VFAT, and LBA (Logical Block Address) mode. Most Linux distributions that use GRUB give a customized
boot menu by leveraging its support for numerous GUIs (Graphical User Interfaces). GRUB2 is currently
replacing GRUB, and GRUB has been renamed GRUB Legacy.

 Comparison between the GRUB and LILO in Operating System:

Features GRUB LILO


Definition A boot loader offered by the GNU It is a Linux bootloader that replaced loadlin as
project is called GRUB. the default boot loader for most Linux OS in
the years following its success.
Introduction It was introduced in 1995. Werner Almesberger was the first to introduce
the LILO from 1992 to 1997.
Supporting It supports multiple OS, including It supports only a single operating system
OS Windows, macOS, Linux, Unix, BSD, which is Linux OS.
and Solaris.
Complexity It is more complex than LILO. It is simple and easy to use.
GUI Menu It includes a GUI menu choice. It doesn't include a GUI menu choice.
Choice
Development It is developed by GNU Project. Werner Almesberger, John Coffman and
Joachim Wiedorn are three developers that
developed LILO.
Type It is a new default boot loader. It is an old default boot loader.
Network It supports network booting. It doesn't support network booting.
Booting
Interactive It supports an interactive command It doesn't support an interactive command
Command interface. interface.
Interface

3] Custom Loaders:
A "custom loader" in Linux refers to a specially designed program that takes the place of the
standard operating system loader, allowing for customized loading of executables or libraries, often with
additional features or functionalities not present in the default loader, potentially including modifications to
memory allocation, relocation, or execution behavior depending on specific needs; essentially, it's a custom-
written code that can load and run programs in a way tailored to a particular application or environment,
rather than relying on the standard Linux loading mechanism.

Mr. Yogesh D. Pakhare, M. Sc[CS] College - GFCCT, Akluj

You might also like