Home  >  Article  >  Operation and Maintenance  >  How to add a hard disk in linux

How to add a hard disk in linux

WBOY
WBOYOriginal
2022-01-28 15:54:5023419browse

How to add a hard disk in Linux: 1. Use the fdisk command to display the current hard disk partition status, and press the "n" key to add a new partition; 2. Use the mkfs command to format the partition; 3. Use the mount command to mount the partition. ;4. Use the "defaults 0 0" statement to set automatic mounting at permanent startup.

How to add a hard disk in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to add a hard disk in Linux

A hard disk with a capacity of 20GB has been added and mounted to the /data partition.

fdisk is a command line tool used to display and manage hard disks and partitions on Linux systems.

# fdisk -l

This command will list the current partition and configuration.

How to add a hard disk in linux

After adding a 20GB hard drive, the output of fdisk -l is as follows.

# fdisk -l

How to add a hard disk in linux

View new partition details

The newly added disk is displayed as /dev/xvdc. If we were adding a physical disk, it would look like /dev/sda based on the disk type. Here I am using a virtual disk.

To partition on a specific hard drive, such as /dev/xvdc.

# fdisk /dev/xvdc

Commonly used fdisk commands

n - Create partition

p - Print partition table

d - Delete a partition

q -Exit without saving changes

w -Save changes and exit

Since we want to create a partition, use the n option.

How to add a hard disk in linux

Create a primary partition or extended partition. By default we can have up to 4 primary partitions.

Enter the partition number as required. It is recommended to use the default value of 1.

Enter the size of the first sector. If it is a new disk, usually choose the default value. If you are creating a second partition on the same disk, we need to add 1 to the last sector of the previous partition.

Enter the value of the last sector or partition size. It is generally recommended to enter the size of the partition. Always add prefix to prevent value out of range errors.

Save changes and exit.

How to add a new disk on a Linux system How to add a new disk on a Linux system

Save partition changes

Now use the mkfs command to format the disk.

# mkfs.ext4 /dev/xvdc1

How to add a hard disk in linux

Format the new partition

After the formatting is completed, follow the following command to mount the partition.

# mount /dev/xvdc1 /data

Add entries in the /etc/fstab file for automatic mounting on permanent boot.

/dev/xvdc1 /data ext4 defaults 0 0

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of How to add a hard disk in linux. 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