Objective:
To learn how to partition a disk in Linux using command-line tools.
Prerequisites:
- Basic understanding of Linux terminal commands
- A non-mounted block device (e.g.,
/dev/sdb
) for partitioning - Administrator privileges (using
sudo
)
Lab Exercise: Disk Partitioning
1. List Available Disks: Begin by listing all available storage devices:
sudo fdisk -l
Identify the disk that you will partition (e.g., /dev/sdb
).
2. Using fdisk
to Create Partitions:
- Open the disk for partitioning:
sudo fdisk /dev/sdb
Interactive steps:
- Type
n
to create a new partition. - Choose the partition type (Primary or Extended).
- Set the first and last sectors, or press Enter to accept defaults.
- Type
p
to display the current partition table. - Type
w
to write the partition table and exit.
3. Verify the Partition: After creating the partition, verify it using:
sudo fdisk -l /dev/sdb
4. Formatting the Partition:
Format the newly created partition (e.g., /dev/sdb1
) using a filesystem of your choice:
sudo mkfs.ext4 /dev/sdb1
5. Mount the Partition: Create a mount point and mount the partition:
sudo mkdir /mnt/mydisk
sudo mount /dev/sdb1 /mnt/mydisk
6. Verify the Mounted Partition: Check if the partition is mounted:
df -h
7. Unmount and Automate Mounting: Unmount the partition:
sudo umount /mnt/mydisk
To automate mounting, add the partition to the /etc/fstab
file.
8. Removing a Partition: If you want to delete a partition, repeat step 2, but use d
instead of n
to delete the partition.
Lab Report:
- The commands used for each step
- Screenshots of their partitioning progress
- Verification of the partition and formatting
- Final confirmation with the mounted partition