关于本博客的说明:本文主要分享如何为服务器加装机械硬盘

目录

1. 确认原硬盘节点

2. 加装物理硬盘,并再次查看硬盘信息

3. 创建分区

4、创建新的挂载点

5、手动挂载分区

6、添加访问权限

7、设置为开机自动挂载分区


具体加装过程:

1. 确认原硬盘节点

sudo fdisk -l

服务器增加硬盘后bios设置 服务器加硬盘步骤_磁盘挂载

即原硬盘标识为sda

2. 加装物理硬盘,并再次查看硬盘信息

服务器增加硬盘后bios设置 服务器加硬盘步骤_Ubuntu_02

新加硬盘显示为sdb,并且已经存在两个分区sdb1和sdb2

3. 创建分区

在创建分区之前,先删除已经存在的两个分区sdb1和sdb2

指令sudo fdisk /dev/sdb

此命令用于分区管理,会出现类似如下内容:

Command (m for help):   

这里按m获得帮助   

a   toggle a bootable flag   将分区设置为启动区   

b   edit bsd disklabel    编辑bsd的disklabel   

c   toggle the dos compatibility flag  设置该分区为dos分区   

d   delete a partition 删除分区   

l   list known partition types  列出已知的分区类型   

m   print this menu  打印帮助列表   

n   add a new partition 创建新分区   

o   create a new empty DOS partition table   

p   print the partition table查看分区信息   

q   quit without saving changes 退出不保存   

s   create a new empty Sun disklabel   

t   change a partition's system id改变分区类型   

u   change display/entry units   

v   verify the partition table   

w   write table to disk and exit 保存退出   

x   extra functionality (experts only)

 

 

输入 p 并回车,可查看分区信息,输入d删除其中一个分区,再输入d删除另一分区

amax@amax:~/.vnc$ sudo fdisk /dev/sdb


Welcome to fdisk (util-linux 2.27.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.


Command (m for help): m


Help:


Generic

d delete a partition

F list free unpartitioned space

l list known partition types

n add a new partition

p print the partition table

t change a partition type

v verify the partition table

i print information about a partition


Misc

m print this menu

x extra functionality (experts only)


Script

I load disk layout from sfdisk script file

O dump disk layout to sfdisk script file


Save & Exit

w write table to disk and exit

q quit without saving changes


Create a new label

g create a new empty GPT partition table

G create a new empty SGI (IRIX) partition table

o create a new empty DOS partition table

s create a new empty Sun partition table



Command (m for help): p

Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 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: D7CBEC0F-7AD1-4458-8DCE-735426FDFBFE


Device Start End Sectors Size Type

/dev/sdb1 34 262177 262144 128M Microsoft reserved

/dev/sdb2 264192 7814035455 7813771264 3.7T Microsoft basic data


Partition 1 does not start on physical sector boundary.


Command (m for help): d

Partition number (1,2, default 2): 2


Partition 2 has been deleted.


Command (m for help): p

Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 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: D7CBEC0F-7AD1-4458-8DCE-735426FDFBFE


Device Start End Sectors Size Type

/dev/sdb1 34 262177 262144 128M Microsoft reserved


Partition 1 does not start on physical sector boundary.


Command (m for help): d


Selected partition 1

Partition 1 has been deleted.


Command (m for help): p

Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 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: D7CBEC0F-7AD1-4458-8DCE-735426FDFBFE

输入n 并回车,新建分区(此处,只新建一个分区),相关参数均选择推荐的默认值

Command (m for help): n

Partition number (1-128, default 1): 1

First sector (34-7814037134, default 2048): 2048

Last sector, +sectors or +size{K,M,G,T,P} (2048-7814037134, default 7814037134): 7814037134



Created a new partition 1 of type 'Linux filesystem' and of size 3.7 TiB.



Command (m for help): p

Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 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: D7CBEC0F-7AD1-4458-8DCE-735426FDFBFE



Device Start End Sectors Size Type

/dev/sdb1 2048 7814037134 7814035087 3.7T Linux filesystem



Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

再次查看磁盘信息,新的分区为 /dev/sdb1

amax@amax:~/.vnc$ sudo fdisk -l

Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 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: dos

Disk identifier: 0xfce56e52


Device Boot Start End Sectors Size Id Type

/dev/sda1 * 2048 976657 974610 475.9M 83 Linux

/dev/sda2 978942 128976895 127997954 61G 5 Extended

/dev/sda3 128976896 728977407 600000512 286.1G 83 Linux

/dev/sda4 728977408 3907028991 3178051584 1.5T 83 Linux

/dev/sda5 978944 128976895 127997952 61G 82 Linux swap / Solaris


Partition table entries are not in disk order.



Disk /dev/sdb: 3.7 TiB, 4000787030016 bytes, 7814037168 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: D7CBEC0F-7AD1-4458-8DCE-735426FDFBFE


Device Start End Sectors Size Type

/dev/sdb1 2048 7814037134 7814035087 3.7T Linux filesystem

格式化分区

分区完成后,接着要对硬盘进行格式化操作,使它成为Linux系统格式

指令:sudo mkfs -t ext4 /dev/sdb1

此处格式化为 ext4 文件格式,和另一硬盘的文件格式保持一致

amax@amax:~/.vnc$ sudo mkfs -t ext4 /dev/sdb1

mke2fs 1.42.13 (17-May-2015)

Creating filesystem with 976754385 4k blocks and 244195328 inodes

Filesystem UUID: ed919d6a-9519-4a9a-8763-9f1e2dbeaacb

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,

102400000, 214990848, 512000000, 550731776, 644972544


Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

4、创建新的挂载点

为方便普通用户访问,运用管理员权限在/home 目录下创建/extend 文件夹作为挂载节点

sudo mkdir /home/extend

5、手动挂载分区

挂载硬盘分区到挂载点

mount /dev/sdb1 /home/extend

可以发现,该文件夹的信息已经更改为添加新硬盘的信息

服务器增加硬盘后bios设置 服务器加硬盘步骤_服务器增加硬盘后bios设置_03

6、添加访问权限

经过以上操作,该文件夹/extend只能由root账户进行访问,因此需要更改其访问权限,使得普通账户可以进行读写操作

 sudo chmod 777 /home/extend

至此,所有用户均可对此文件夹进行读写,但只能读别人的文件而不能更改(人性化哈,在理)

7、设置为开机自动挂载分区

因为手动mount挂载在重启服务器后会失效,所以需要将分区信息写到/etc/fstab文件中让它开机自动挂载):

sudo vim /etc/fstab 

在最后一行加入:/dev/sdb1 /home/extend ext4 defaults 0 2

(参照/home 的设置)

服务器增加硬盘后bios设置 服务器加硬盘步骤_磁盘挂载_04

重启服务器,查看硬盘分区挂载是否正常。