先查看硬盘信息

ryan@ubuntu:~$ sudo fdisk -l

Disk /dev/loop1: 116.8 MiB, 122458112 bytes, 239176 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop2: 116.8 MiB, 122433536 bytes, 239128 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9BD6C451-7E8B-4256-B75A-CEB0A62A49DD

Device     Start        End    Sectors   Size Type
/dev/sda1   2048 1953525134 1953523087 931.5G Linux filesystem


Disk /dev/sdb: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: B2A40C55-2DB5-2945-9207-99BA15EF345D

Device     Start       End   Sectors   Size Type
/dev/sdb1   2048 976773134 976771087 465.8G Linux filesystem


Disk /dev/sdc: 149.1 GiB, 160041885696 bytes, 312581808 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3857413E-2A90-4247-AEC3-53FCFB31E45B

Device       Start       End   Sectors   Size Type
/dev/sdc1     2048   1050623   1048576   512M EFI System
/dev/sdc2  1050624 312578047 311527424 148.6G Linux filesystem

这里/dev/sdb是需要格式化的硬盘,使用fdisk格式化

ryan@ubuntu:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-976773134, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-976773134, default 976773134):

Created a new partition 1 of type 'Linux filesystem' and of size 465.8 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o:Y

Command (m for help): w

ryan@ubuntu:~$

格式化分区刚刚新建的分区:

ryan@ubuntu:~$ sudo mkfs.ext4 /dev/sdb1

查看/dev/sdb1的分区uuid

ryan@ubuntu:~$ ll /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Mar 19 22:13 0e800de7-3372-492e-8e95-2df1f1327d72 -> ../../sdc2
lrwxrwxrwx 1 root root 10 Mar 19 22:27 548bf7a5-dca8-4c99-9072-446590738838 -> ../../sda1
lrwxrwxrwx 1 root root 10 Mar 19 22:13 8557-0437 -> ../../sdc1
lrwxrwxrwx 1 root root 10 Mar 23 23:52 db4c335b-edc2-40ce-a517-2f017b72f370 -> ../../sdb1

设置开机自动挂载分区

sudo echo ’/dev/disk/by-uuid/db4c335b-edc2-40ce-a517-2f017b72f370 /srv/ST500DM002-500G ext4 defaults 0 0‘ >> /etc/fstab