远看山有色,近听水无声。
家里服务器磁盘空间不够用,买来一块新硬盘,需要挂载到现在的CentOS系统上,在Linux下如何挂载,具体步骤可以参考下面演示。本次服务器我用的命令如下,您所需要的不一定与我的完全相同。输出结果也仅供参考,请以自己实际情况为准。
1、首先查看是否已经分配
命令:
fdisk -l
输出:
[root@master ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/nvme0n1: 500.1 GB, 500107862016 bytes, 976773168 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 label type: gpt
Disk identifier: 48619109-FB2A-4717-A2FF-729E56DC4BEC
# Start End Size Type Name
1 2048 411647 200M EFI System EFI System Partition
2 411648 2508799 1G Microsoft basic
3 2508800 976773119 464.6G Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sda: 4000.8 GB, 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
Disk label type: gpt
Disk identifier: 1404C869-F98E-4D9F-B7F0-D47B878CE584
# Start End Size Type Name
1 34 32767 16M Microsoft reser Microsoft reserved partition
Partition 1 does not start on physical sector boundary.
2 32768 7814033407 3.7T Microsoft basic Basic data partition
Disk /dev/mapper/centos-root: 375.8 GB, 375809638400 bytes, 734003200 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/mapper/centos-swap: 16.8 GB, 16844324864 bytes, 32899072 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/mapper/centos-home: 105.2 GB, 105226698752 bytes, 205520896 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
2、发现有硬盘,路径为 /dev/sda,然后用 fdisk 命令进行分区
命令:
fdisk /dev/sda
输出:
[root@master ~]# fdisk /dev/sda
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Welcome 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.
3、接着新建分区,因为我主要是想要存文件,所以逻辑全部是一个分区
我看网上的教程,他的命令步骤有可能不一样,我把我的命令和结果一块写下,供参考比较:命令输入m获取帮助(一些fdisk命令),井号后为后期写文章时加入的注释,注意!
Command (m for help): m
Command action
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
#井号#后为后期加入的注释
Command (m for help): n #建分区,输入命令
:n
Partition number (3-128, default 3): 3 #分区号,默认3(你的可能不一样)可以直接回车
First sector (7814033408-7814037134, default 7814033408): #起始扇区,默认,可直接回车
Last sector, +sectors or +size{K,M,G,T,P} (7814033408-7814037134, default 7814037134): #结束扇区 默认,可直接回车
Created partition 3 #已经设置好分区
4、然后保存分区,接着在上面的界面输入w即可
Command (m for help): w #接着输入w即可保存
The partition table has been altered!
Calling ioctl() to re-read partition table. #正在同步磁盘
Syncing disks.
You have new mail in /var/spool/mail/root
5、使用 fdisk -l 命令查看,已经有分区了
[root@master ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/nvme0n1: 500.1 GB, 500107862016 bytes, 976773168 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 label type: gpt
Disk identifier: 48619109-FB2A-4717-A2FF-729E56DC4BEC
# Start End Size Type Name
1 2048 411647 200M EFI System EFI System Partition
2 411648 2508799 1G Microsoft basic
3 2508800 976773119 464.6G Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sda: 4000.8 GB, 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
Disk label type: gpt
Disk identifier: 1404C869-F98E-4D9F-B7F0-D47B878CE584
# Start End Size Type Name
1 34 32767 16M Microsoft reser Microsoft reserved partition
Partition 1 does not start on physical sector boundary.
2 32768 7814033407 3.7T Microsoft basic Basic data partition
3 7814033408 7814037134 1.8M Linux filesyste
Disk /dev/mapper/centos-root: 375.8 GB, 375809638400 bytes, 734003200 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/mapper/centos-swap: 16.8 GB, 16844324864 bytes, 32899072 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/mapper/centos-home: 105.2 GB, 105226698752 bytes, 205520896 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
6、建立好分区后要格式化分区,然后建立文件系统
命令:
mkfs.xfs -f /dev/sda
输出:
[root@master ~]# mkfs.xfs -f /dev/sda
meta-data=/dev/sda isize=512 agcount=4, agsize=244188662 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=976754646, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=476930, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
7、至此文件系统建设好了,之后选择一个挂载点挂上就行,我直接挂载在 /home 下了
命令:
mount /dev/sda /home
8、查看是否挂在成功
命令:
df -Th /home
输出:
[root@master ~]# df -Th /home
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda xfs 3.7T 33M 3.7T 1% /home
9、为了让系统每次开机重启后自动挂载,可以修改下系统配置。用vim编辑器在 /etc/fstab 文件中加入一行(根据实际情况修改):
/dev/sda /home defaults 0 0
至此完美解决。文章或许有不足之处,大家多多阅读其他大佬文章,根据自己实际情况测试使用!