1. Use fdisk -l to view the details of the hard disk
Linux systems generally use the "fdisk -l" command to list the currently connected hard disk devices and partition information in the system. If the new hard disk has no partition information, only the size information of the hard disk will be displayed.
[root@iZm5eb1xqfqw9z2v1gmx11Z chargedot]# fdisk -l
2. Go to the disk and partition the disk
Enter fdisk /dev/vdb: Edit the selected hard disk. When selecting the hard disk, enter n (add a new partition), then enter p (select the main partition), then you can choose the default, and finally enter "w" to save the partition and exit.
[root@iZm5eb1xqfqw9z2v1gmx11Z chargedot]# fdisk /dev/vdb
Note: fdisk hard disk editing, the meaning of each parameter is as follows
1. Enter m to display a list of all commands.
2. Enter p to display the partition status of the hard disk and print the partition table.
3. Enter a to set the hard disk boot area.
4. Enter n to set up a new hard disk partition.
4.1. Input e hard disk as [extend] partition (extend).
4.2. Enter p hard disk as the [primary] partition.
5. Enter t to change the hard disk partition properties.
t: partition system id number
L:82:linux swap
83:linux
86: NTFS window partition
6. Enter d to delete the hard disk partition attribute.
7. Enter q to end without saving the hard disk partition attribute.
8. Enter w to end and write the hard disk partition properties
After performing the above operations, use fdisk -l to see the /dev/vbd1 partition.
3. Format the partition
Format with mkfs.ext4 /dev/vdb1, if there are multiple partitions, change vdb1 to vdb2, vdb3... and so on.
[root@iZm5eb1xqfqw9z2v1gmx11Z chargedot]# mkfs.ext4 /dev/vdb1
4. Mount the partition
After formatting, mount the hard disk to the location you want to mount (such as /mnt), you need to create the /mnt directory (mkdir /mnt).
[root@iZm5eb1xqfqw9z2v1gmx11Z chargedot]# mount /dev/vdb1 /mnt
Then check if the mount is successful with df -h.
5. Configure automatic mount at startup
Because the mount will fail after restarting the server, you need to write the partition information to the /etc/fstab file to make it permanently mounted.
[root@iZm5eb1xqfqw9z2v1gmx11Z chargedot]# vim /etc/fstab
Restart the system and verify that the permanent mount takes effect.
fstab file format description:
- /dev/vdb1: which partition represents;
- ext4: is the format of the partition;
- defaults: are the parameters to be set when mounting (read-only, read-write, enable quota, etc.), the parameters included in the input defaults are (rw, dev, exec, auto, nouser, async);
- 0: Whether to use dump to record, 0 is not;
- 0: It is the order of checking when booting. It is 1 for the boot system file, 2 for other file systems, and 0 if it is not checked.
At this point, the Linux system hangs on the hard disk to complete.
Mount command mount description:
- mount: view partition format
-a mount information takes effect immediately
-t ext4 /dev/sdb1 /opt temporarily mount the linux partition
-t vfat /dev/sdc1 //media/usb U disk mounts the window partition
-o loop docs.iso /media/iso mount the image file
- mount media/cdrom CD-ROM mount
- umount /opt unmount mount