Linux磁盘配置

Linux磁盘配置

在 Linux 中配置磁盘,不管是使用 VMware Workstation还是 网络建设与运维专用的 云平台 都差不多,都是添加 磁盘 就行

1.磁盘添加(省略)

2.创建磁盘挂载节点

1
2
3
4
5
6
[root@ftp_skills_net /]# mkdir -p /file_1 /file_2 /file_3
[root@ftp_skills_net /]# ls / | grep file
file_1
file_2
file_3
[root@ftp_skills_net /]#

这里我们创建三个文件夹,分别是 file_1,file_2,file_3。

3.查看新增磁盘路径

  • 首先我们需要使用命令 fdisk -l 查看未格式化的新增磁盘路径
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
[root@waiting ~]#  fdisk -l

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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: dos
Disk identifier: 0x0009d399

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM

Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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: 4160 MB, 4160749568 bytes, 8126464 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/nvme0n1: 1073 MB, 1073741824 bytes, 2097152 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/nvme0n2: 1073 MB, 1073741824 bytes, 2097152 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/nvme0n3: 1073 MB, 1073741824 bytes, 2097152 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: 155.8 GB, 155818393600 bytes, 304332800 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

[root@waiting ~]#

这里我们看到了很多的磁盘,那我们怎么看哪个是我们的新增磁盘呢?

很简单!我们只需查看磁盘大小就行啦,可以看到 在 Disk /dev/nvme0n1 中出现 1073 MB 这就是我们新增的1G磁盘,往下看以此类推。

从命令返回得知,我们新增的三块磁盘分别为:

1
2
3
4
5
Disk /dev/nvme0n1

Disk /dev/nvme0n2

Disk /dev/nvme0n3

4.对新增磁盘进行文件系统格式化

  • 我们使用 mkfs 工具进行格式化操作,如果不知道这个工具有啥用的,自行百度~

  • mkfs.vfat工具存在于dosfstools软件包,通过yum provides mkfs.vfat命令可以查看,没有改命令的话可以安装这个包

下面我们展示格式化ext3,ext2,vfat三个格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// 格式化 ext3
[root@waiting ~]# mkfs.ext3 /dev/nvme0n1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

// 格式化 ext2
[root@waiting ~]# mkfs.ext2 /dev/nvme0n2
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

// 格式化 vfat
[root@waiting ~]# mkfs.vfat /dev/nvme0n3
mkfs.fat 3.0.20 (12 Jun 2013)
[root@waiting ~]#

5.配置磁盘自动挂载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// 编辑文件
[root@waiting ~]# vim /etc/fstab

// 添加以下内容
[root@waiting ~]# tail -3 /etc/fstab
// 挂载磁盘路径 挂载文件夹 文件类型 默认挂载选项,用户配额
/dev/nvme0n1 /file_1 ext3 defaults,usrquota 0 0

// 挂载磁盘路径 挂载文件夹 文件类型 默认挂载选项
/dev/nvme0n2 /file_2 ext2 defaults 0 0

// 挂载磁盘路径 挂载文件夹 文件类型 默认挂载选项
/dev/nvme0n3 /file_3 vfat defaults 0 0
[root@waiting ~]#

后面的那两个0 0没什么特别意思,第一个:是否 dump备份,第二个:是否开机时 fsck 检查

6.验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 卸载全部已挂载的
[root@waiting ~]# umount -a
umount: /: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /sys/fs/cgroup/systemd: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /sys/fs/cgroup: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /run: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /dev: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))

// 挂载全部磁盘(自动读取 /etc/fstab 文件进行挂载)
[root@waiting ~]# mount -a

// 查看磁盘挂载详情
[root@waiting ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 50G 1.1G 49G 3% /
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 143M 872M 15% /boot
/dev/mapper/centos-home xfs 146G 33M 146G 1% /home
/dev/nvme0n1 ext3 976M 1.3M 924M 1% /file_1
/dev/nvme0n2 ext2 1008M 1.3M 956M 1% /file_2
/dev/nvme0n3 vfat 1022M 4.0K 1022M 1% /file_3
[root@waiting ~]#