电脑计算机论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 619|回复: 0

Linux添加硬盘简要步骤

[复制链接]
admin 发表于 2022-5-31 12:11:38 | 显示全部楼层 |阅读模式
1、查看硬盘 # fdisk -l   
可看到当前的云服务器有两块磁盘,“/dev/vda”是系统盘,“/dev/vdb”是新增数据盘。
2、执行分区操作

执行以下命令,进入 fdisk 分区工具,开始对新增数据盘执行分区操作。

#fdisk /dev/vdb

[root@Server-c00ef8c3-710d-4708-9cde-2c864e7c03e2 ~# fdisk /dev/vdbWelcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x3e9baf68.
Command (m for help): 输入“n”,按“Enter”,
开始新建分区。
Partition type:   
p   primary (0 primary, 0 extended, 4 free)   
e   extendedSelect (default p):

输入“p”,按“Enter”,开始创建一个主分区。

Select (default p): p
Partition number (1-4, default 1):

接下来每步均使用默认值,直接按“Enter”。

Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199Partition 1 of type Linux and of size 100 GiB is setCommand (m for help):

输入“p”,按“Enter”,查看新建分区的详细信息。

Command (m for help): p
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x3e9baf68   
Device Boot      Start         End      Blocks   Id  System/dev/vdb1            2048   209715199   104856576   83  LinuxCommand (m for help):

输入“w”,按“Enter”,将分区结果写入分区表中。

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

执行以下命令,将新的分区表变更同步至操作系统。

partprobe
3、格式化分区、挂载分区
mkfs -t ext4 /dev/vdb1mkdir /data
mount /dev/vdb1 /data
df -TH
4、设置开机自动挂载分区

以查询磁盘分区“/dev/vdb1”的UUID:

blkid /dev/vdb1[root@Server-c00ef8c3-710d-4708-9cde-2c864e7c03e2 ~# blkid /dev/vdb1/dev/vdb1: UUID="6a366ae5-7066-4b5c-8ca1-401345dee29d" TYPE="ext4"

执行以下命令,使用VI编辑器打开“fstab”文件。

vi /etc/fstab

在文件后添加一行:

UUID=6a366ae5-7066-4b5c-8ca1-401345dee29d /data                ext4    defaults        0 2

参数说明如下:
第一列为UUID,此处填写1中查询到的磁盘分区的UUID。
第二列为磁盘分区的挂载目录,可以通过df -TH命令查询。
第三列为磁盘分区的文件系统格式, 可以通过df -TH命令查询。
第四列为磁盘分区的挂载选项,此处通常设置为defaults即可。
第五列为Linux dump备份选项。
0表示不使用Linux dump备份。现在通常不使用dump备份,此处设置为0即可。
1表示使用Linux dump备份。
第六列为fsck选项,即开机时是否使用fsck检查磁盘。
0表示不检验。
挂载点为(/)根目录的分区,此处必须填写1。
根分区设置为1,其他分区只能从2开始,系统会按照数字从小到大依次检查下去。


您需要登录后才可以回帖 登录 | 注册

本版积分规则


QQ|手机版|小黑屋|电脑计算机论坛 ( 京ICP备2022023538号-1 )

GMT+8, 2024-5-19 13:40 , Processed in 0.070982 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表