0% found this document useful (0 votes)
2 views5 pages

Disk Management

The document provides a step-by-step guide on creating and managing disk partitions using the fdisk utility, including creating a filesystem and mounting it. It also covers setting up a Logical Volume Manager (LVM), creating physical volumes, volume groups, and logical volumes, as well as extending logical volumes and resizing filesystems. Additionally, it includes practice questions for hands-on learning.

Uploaded by

Umang Makwana
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)
2 views5 pages

Disk Management

The document provides a step-by-step guide on creating and managing disk partitions using the fdisk utility, including creating a filesystem and mounting it. It also covers setting up a Logical Volume Manager (LVM), creating physical volumes, volume groups, and logical volumes, as well as extending logical volumes and resizing filesystems. Additionally, it includes practice questions for hands-on learning.

Uploaded by

Umang Makwana
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/ 5

1.

Creating a Partition Using fdisk

The fdisk utility is used to create, delete, and manage partitions on a disk.

Steps:

1. List Available Disks:

bash
Copy code
lsblk

Output:

bash
Copy code
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 20G 0 part /
└─sda2 8:2 0 80G 0 part /data

Explanation:

o lists block devices, their sizes, and their mount points.


lsblk
Identify the disk you want to partition, e.g., /dev/sdb.
o
2. Open fdisk for Disk Management:

bash
Copy code
fdisk /dev/sdb

oCommand Breakdown:
 /dev/sdb: The disk to partition.
3. Create a New Partition:
o Inside fdisk, enter these commands interactively:
 Press n to create a new partition.
 Choose a partition type: primary or logical.
 Specify the partition number (default is usually fine).
 Set the first and last sector (or accept defaults for the whole disk).
o Example Output:

sql
Copy code
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): 1
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default
209715199): +20G

4. Write Changes:
o Press w to save changes and exit fdisk.
o Important: If you want to cancel, use q.
5. Refresh the Partition Table:

bash
Copy code
partprobe

Explanation:

o Updates the kernel with the new partition information.


6. Check the Partition:

bash
Copy code
lsblk

o Verify that the partition is created, e.g., /dev/sdb1.

2. Create a Filesystem

A partition must have a filesystem before it can be used.

Steps:

1. Create a Filesystem:

bash
Copy code
mkfs.ext4 /dev/sdb1

Command Breakdown:

o mkfs.ext4:
Creates an ext4 filesystem.
o /dev/sdb1:
The new partition.
2. Label the Partition (Optional):

bash
Copy code
e2label /dev/sdb1 data_partition

3. Create a Mount Point:

bash
Copy code
mkdir /mnt/data

4. Mount the Partition:

bash
Copy code
mount /dev/sdb1 /mnt/data

5. Verify the Mount:


bash
Copy code
df -h

Output:

bash
Copy code
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 20G 0G 20G 0% /mnt/data

6. Persistent Mounting: Add the entry to /etc/fstab:

bash
Copy code
echo '/dev/sdb1 /mnt/data ext4 defaults 0 0' >> /etc/fstab

3. Logical Volume Manager (LVM)

What is Needed Before Creating LVM?

 A physical disk or partition to use as a Physical Volume (PV).


 LVM requires the lvm2 package (installed by default in RHEL).

Steps to Create an LVM:

1. Create a Physical Volume (PV):

bash
Copy code
pvcreate /dev/sdb1

Command Breakdown:

o pvcreate: Initializes /dev/sdb1 as a physical volume for LVM.


2. Create a Volume Group (VG):

bash
Copy code
vgcreate my_vg /dev/sdb1

Command Breakdown:

o vgcreate: Creates a volume group named my_vg.


o /dev/sdb1: Adds the PV to the volume group.
3. Create a Logical Volume (LV):

bash
Copy code
lvcreate -L 10G -n my_lv my_vg

Command Breakdown:
o -L 10G: Specifies the size of the logical volume (10 GB).
o -n my_lv: Names the logical volume my_lv.
o my_vg: The volume group name.
4. Create a Filesystem on the LV:

bash
Copy code
mkfs.xfs /dev/my_vg/my_lv

5. Mount the Logical Volume:

bash
Copy code
mkdir /mnt/lvm_data
mount /dev/my_vg/my_lv /mnt/lvm_data

6. Verify the Mount:

bash
Copy code
df -h

4. Extend an LVM

1. Extend the Logical Volume:

bash
Copy code
lvextend -L +5G /dev/my_vg/my_lv

Command Breakdown:

o -L +5G: Increases the size by 5 GB.


o /dev/my_vg/my_lv: Specifies the logical volume to extend.
2. Resize the Filesystem: For XFS:

bash
Copy code
xfs_growfs /mnt/lvm_data

For ext4:

bash
Copy code
resize2fs /dev/my_vg/my_lv

3. Verify the New Size:

bash
Copy code
df -h
Practice Questions

1. Create a partition, format it with ext4, and mount it permanently at /mnt/data.


2. Set up an LVM with:
o A PV of 20 GB.
o A VG named test_vg.
o An LV of 10 GB named test_lv.
o Mount the LV at /mnt/test_data.
3. Extend the logical volume by 5 GB and resize the filesystem.
4. Create an additional partition on a disk, convert it to an LVM PV, and add it to the existing VG.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy