Disk partitioning and file system management are essential tasks when setting up a CentOS system.
1. Partitioning Disks:
- Identify the disk you want to partition using the
lsblkcommand. For example:sudo lsblk - Use a partitioning tool such as
fdisk,parted, orgpartedto create partitions on the disk. For example, usingfdisk:
Replacesudo fdisk /dev/sdX/dev/sdXwith the appropriate disk identifier. - Follow the prompts to create partitions. You can create primary, extended, or logical partitions as needed.
- Use the
pcommand to list existing partitions,nto create a new partition,tto change a partition's type,dto delete a partition, andwto write changes to disk and exit.
2. Formatting Partitions:
- After creating partitions, you need to format them with a file system. Common file systems in CentOS include ext4, XFS, and Btrfs.
- Use the appropriate command to format the partition. For example, to format a partition as ext4:
Replacesudo mkfs.ext4 /dev/sdXY/dev/sdXYwith the appropriate partition identifier. - Repeat the process for each partition you've created.
3. Mounting Partitions:
- After formatting, you need to mount the partitions to make them accessible in the file system.
- Create mount points (directories) for each partition. For example:
sudo mkdir /mnt/data - Edit the
/etc/fstabfile to automatically mount partitions at boot time. Add an entry for each partition in the following format:
Replace/dev/sdXY /mnt/data ext4 defaults 0 0/dev/sdXYwith the partition identifier and/mnt/datawith the mount point. - Mount the partitions manually using the
mountcommand:sudo mount /dev/sdXY /mnt/data
4. Managing File Systems:
- Check disk usage and file system information using commands like
df,du, andlsblk. - Resize partitions and file systems using tools like
parted,resize2fs, orxfs_growfs. - Repair file systems using tools like
fsckfor ext4 orxfs_repairfor XFS.

Comments