Lab: Partitioning and Using a Disk
Objective: To practice partitioning a disk and utilizing the created partitions for data storage.
Requirements:
- A Unix-like system (Linux distribution) with a disk available for partitioning.
- Administrative privileges (sudo or root access) may be required.
Steps:
Note: Before proceeding, ensure you have a backup of any important data on the disk, as partitioning may lead to data loss.
- Identify the Disk:Use the
lsblk
orfdisk -l
command to list available disks and identify the target disk for partitioning. For example, let’s assume the target disk is/dev/sdb
. - Launch Disk Partitioning Tool:Use a partitioning tool like
fdisk
orparted
to partition the disk.For example, usingfdisk
:bashCopy codesudo fdisk /dev/sdb
- Create Partitions:In the partitioning tool (
fdisk
in this example):a. Typen
for creating a new partition. b. Select the partition type (primary, extended, or logical). c. Specify the partition size (in cylinders, +size{K,M,G}). d. Repeat steps a-c to create additional partitions if needed. - Set Partition Type:If creating a partition for a specific file system (e.g., ext4), set the partition type:a. Type
t
to change the partition type. b. Select the partition number. c. Specify the partition type code (e.g., 83 for Linux filesystem). - Write Changes:Once partitions are created, save the changes:a. Type
w
to write the changes to disk and exit. - Format Partitions:Use a suitable file system format command (e.g.,
mkfs.ext4
,mkfs.ntfs
) to format the partitions. For example:bashCopy codesudo mkfs.ext4 /dev/sdb1
Repeat for each partition (e.g.,/dev/sdb2
,/dev/sdb3
). - Create Mount Points:Create directories for mounting the partitions:bashCopy code
sudo mkdir /mnt/partition1 sudo mkdir /mnt/partition2
- Mount Partitions:Mount the partitions to the created directories:bashCopy code
sudo mount /dev/sdb1 /mnt/partition1 sudo mount /dev/sdb2 /mnt/partition2
Adjust the mount points and partition names as per your setup. - Verify Mounts:Use the
df -h
command to verify that the partitions are mounted correctly and check their available space. - Automount Partitions at Boot (Optional):Add entries to the
/etc/fstab
file to ensure partitions are mounted automatically at system startup. - Test Data Storage:Create, modify, and delete files within the mounted partitions to ensure they function as expected.
- Unmount Partitions (Optional):If you need to unmount the partitions temporarily, use the
umount
command:bashCopy codesudo umount /mnt/partition1 sudo umount /mnt/partition2
Conclusion:
You have successfully partitioned a disk, formatted the partitions, and utilized them for data storage. This exercise provides hands-on experience with disk management in a Unix-like system. Remember to exercise caution when performing disk operations to avoid unintended data loss.