What are the steps to partition a Linux disk?
The steps for partitioning a Linux disk are as follows:
- Open the terminal and log in as a root user or a user with sudo privileges.
- Run the command fdisk -l or lsblk to view disk information and identify the disk to be partitioned.
- 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.
- Enter n to create a new partition.
- Choose the partition type, usually either primary partition (input p) or extended partition (input e).
- Enter the partition number, for example, 1 represents the first partition.
- 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.
- Repeat steps 4-7 as necessary to create additional partitions.
- Save the partition table by inputting “w” and then exit.
- Run the command partprobe or restart the system to make the partition take effect.
- 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.
- Execute the command mkdir to create a directory for mounting a new partition, for example mkdir /mnt/new_partition.
- 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.
- 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.