What are the steps to partition a Linux disk?

The steps for partitioning a Linux disk are as follows:

  1. Open the terminal and log in as a root user or a user with sudo privileges.
  2. Run the command fdisk -l or lsblk to view disk information and identify the disk to be partitioned.
  3. Run the command fdisk /dev/sdX, replacing X with the disk identifier of the disk you want to partition. For example, to partition /dev/sda, run the command fdisk /dev/sda.
  4. Enter n to create a new partition.
  5. Choose the partition type, usually either primary partition (input p) or extended partition (input e).
  6. Enter the partition number, for example, 1 represents the first partition.
  7. Please input the starting and ending sectors of the partition (or partition size). If you are unsure, you can simply press Enter to use the default values.
  8. Repeat steps 4-7 as necessary to create additional partitions.
  9. Save the partition table by inputting “w” and then exit.
  10. Run the command partprobe or restart the system to make the partition take effect.
  11. Run the command mkfs to create a file system, for example mkfs.ext4 /dev/sdXn, where X is replaced with the disk identifier and n is replaced with the partition number.
  12. Execute the command mkdir to create a directory for mounting a new partition, for example mkdir /mnt/new_partition.
  13. Use the mount command to mount the new partition to a directory by typing something like mount /dev/sdXn /mnt/new_partition, replacing X with the disk identifier and n with the partition number.
  14. You can confirm if the new partition has been successfully mounted by running the command df -hT.

The above are the basic steps for partitioning a Linux disk. Please note that partitioning a disk may result in data loss, so be sure to backup important data beforehand.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds