search
HomeOperation and MaintenanceCentOSHow to partition and manage disks in CentOS

How to partition and manage disks in CentOS

Apr 14, 2025 pm 05:21 PM
linuxcentostooldata lost

Detailed explanation of disk partitioning and management of CentOS system: The use of fdisk and parted command line tools

This article will introduce in detail how to use the command line tools fdisk and parted for disk partitioning and management in CentOS system. Be sure to back up all important data before operation to avoid data loss.

1. Preparation

  1. Data Backup : This is a crucial step, make sure that all important data is backed up to a secure location.
  2. Identify available disks : Use the lsblk or fdisk -l command to view the available disk devices in the system and confirm the name of the disk device you want to operate (for example /dev/sda ).

2. Use fdisk for partitioning (suitable for MBR partition table)

fdisk is a commonly used disk partitioning tool, suitable for MBR partition tables.

  1. Start fdisk : Enter sudo fdisk /dev/sdX to start fdisk tool, where /dev/sdX is replaced by the name of the disk device you want to partition.
  2. View partition table : Enter p to view the partition table information of the current disk.
  3. Create a new partition : Enter n to create a new partition, and then follow the prompts to select:
    • Partition type (main partition p or extended partition e )
    • Partition number
    • Partition start sector (usually press Enter to use the default value)
    • Partition end sector (specify the partition size, for example, 20G means creating a 20GB size partition)
  4. Set partition type : After creating a partition, you can use the t command to modify the partition type (for example, set the partition type to Linux ext4 file system).
  5. Write to the partition table : Enter w to save changes and exit fdisk.

3. Use parted for partitioning (suitable for GPT partition table)

The parted tool supports GPT partition tables and is more suitable for larger disks or scenarios where more partitions are needed.

  1. View partition layout : Use sudo parted /dev/sdX print to view the partition layout of the current disk.
  2. Create a partition : Use mkpart command to create a partition, for example:
    • Create the primary partition: sudo parted /dev/sdX mkpart primary ext4 0 200G (Create the primary partition with a size of 200GB starting from sector 0 and set its type to ext4)
    • Create an extended partition: sudo parted /dev/sdX mkpart extended 200G 100% (create an extended partition starting from 200GB to end of disk)
  3. Save partition table : Use sudo parted /dev/sdX save to save partition table changes.

4. Format partition

Use the mkfs command to format the newly created partition. For example, format the /dev/sdX1 partition to an ext4 file system:

 sudo mkfs.ext4 /dev/sdX1

5. Create a mount point

Use the mkdir command to create a mount point directory, for example:

 sudo mkdir /mnt/data

6. Mount the partition

Use mount command to mount the partition to the mount point:

 sudo mount /dev/sdX1 /mnt/data

7. Permanently mount the partition (edit /etc/fstab )

In order for the partition to be automatically mounted when the system starts, the /etc/fstab file needs to be edited. Please operate this step with caution, as incorrect configuration may cause the system to fail to start. It is recommended to back up the /etc/fstab file first. Add a line like the following:

 <code>/dev/sdX1 /mnt/data ext4 defaults 0 0</code>

8. Verify the mount

Use mount command to verify that the partition is mounted correctly:

 mount | grep data

Note: The above /dev/sdX and /dev/sdX1 need to be replaced with your actual disk device and partition name. Please check carefully to avoid data loss due to incorrect operations. Before performing any partitioning operations, it is strongly recommended that you re-confirm that all important data has been backed up.

The above is the detailed content of How to partition and manage disks in CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
CentOS: An Introduction to the Linux DistributionCentOS: An Introduction to the Linux DistributionApr 19, 2025 am 12:07 AM

CentOS is an open source distribution based on RedHatEnterpriseLinux, focusing on stability and long-term support, suitable for a variety of server environments. 1. The design philosophy of CentOS is stable and suitable for web, database and application servers. 2. Use YUM as the package manager to release security updates regularly. 3. Simple installation, you can build a web server with a few commands. 4. Advanced features include enhanced security using SELinux. 5. Frequently asked questions such as network configuration and software dependencies can be debugged through nmcli and yumdeplist commands. 6. Performance optimization suggestions include tuning kernel parameters and using a lightweight web server.

CentOS in Action: Server Management and Web HostingCentOS in Action: Server Management and Web HostingApr 18, 2025 am 12:09 AM

CentOS is widely used in server management and web hosting. Specific methods include: 1) using yum and systemctl to manage the server, 2) install and configure Nginx for web hosting, 3) use top and mpstat to optimize performance, 4) correctly configure the firewall and manage disk space to avoid common problems.

CentOS: A Community-Driven Linux DistributionCentOS: A Community-Driven Linux DistributionApr 17, 2025 am 12:03 AM

CentOS is a stable, enterprise-grade Linux distribution suitable for server and enterprise environments. 1) It is based on RedHatEnterpriseLinux and provides a free, open source and compatible operating system. 2) CentOS uses the Yum package management system to simplify software installation and updates. 3) Support advanced automation management, such as using Ansible. 4) Common errors include package dependency and service startup issues, which can be solved through log files. 5) Performance optimization suggestions include the use of lightweight software, regular cleaning of the system and optimization of kernel parameters.

What Comes After CentOS: The Road AheadWhat Comes After CentOS: The Road AheadApr 16, 2025 am 12:07 AM

Alternatives to CentOS include RockyLinux, AlmaLinux, OracleLinux, and SLES. 1) RockyLinux and AlmaLinux provide RHEL-compatible binary packages and long-term support. 2) OracleLinux provides enterprise-level support and Ksplice technology. 3) SLES provides long-term support and stability, but commercial licensing may increase costs.

CentOS: Exploring the AlternativesCentOS: Exploring the AlternativesApr 15, 2025 am 12:03 AM

Alternatives to CentOS include UbuntuServer, Debian, Fedora, RockyLinux, and AlmaLinux. 1) UbuntuServer is suitable for basic operations, such as updating software packages and configuring the network. 2) Debian is suitable for advanced usage, such as using LXC to manage containers. 3) RockyLinux can optimize performance by adjusting kernel parameters.

Centos shutdown command lineCentos shutdown command lineApr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

Difference between centos and ubuntuDifference between centos and ubuntuApr 14, 2025 pm 09:09 PM

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

Centos configuration IP addressCentos configuration IP addressApr 14, 2025 pm 09:06 PM

Steps to configure IP address in CentOS: View the current network configuration: ip addr Edit the network configuration file: sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 Change IP address: Edit IPADDR= Line changes the subnet mask and gateway (optional): Edit NETMASK= and GATEWAY= Lines Restart the network service: sudo systemctl restart network verification IP address: ip addr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.