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
lsblk
command. For example:sudo lsblk
- Use a partitioning tool such as
fdisk
,parted
, orgparted
to create partitions on the disk. For example, usingfdisk
:sudo fdisk /dev/sdX
/dev/sdX
with the appropriate disk identifier. - Follow the prompts to create partitions. You can create primary, extended, or logical partitions as needed.
- Use the
p
command to list existing partitions,n
to create a new partition,t
to change a partition's type,d
to delete a partition, andw
to 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:
sudo mkfs.ext4 /dev/sdXY
/dev/sdXY
with 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/fstab
file to automatically mount partitions at boot time. Add an entry for each partition in the following format:/dev/sdXY /mnt/data ext4 defaults 0 0
/dev/sdXY
with the partition identifier and/mnt/data
with the mount point. - Mount the partitions manually using the
mount
command: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
fsck
for ext4 orxfs_repair
for XFS.
Comments