1 查看磁盘信息
[root@localhost ~]# fdisk -l
Disk /dev/sda: 34.4 GB, 34359738368 bytes, 67108864 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: 0x0009f305
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 67108863 32504832 8e Linux LVM
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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-root: 29.8 GB, 29842472960 bytes, 58286080 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: 3435 MB, 3435134976 bytes, 6709248 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@localhost ~]#
添加的硬盘为/dev/sdb(容量为10GB,10737418240bytes)
2 格式化新磁盘为EXT4文件系统格式(/dev/sdb)
[root@localhost ~]# mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]#
3 创建磁盘挂载目录并手动挂载
[root@localhost ~]# mkdir -p /data/mydata/
[root@localhost ~]# mount /dev/sdb /data/mydata/
[root@localhost ~]#
4 查看磁盘UUID以设置开机自动挂载
[root@localhost ~]# blkid
/dev/sda1: UUID="a5e2f917-fdff-446d-9eba-5a0a2b94a7e4" TYPE="xfs"
/dev/sda2: UUID="yf271m-A1M3-PeZs-AIoS-hUgz-ilDH-gWEuze" TYPE="LVM2_member"
/dev/sr0: UUID="2020-02-20-18-17-32-20" LABEL="VBox_GAs_6.0.18" TYPE="iso9660"
/dev/sdb: UUID="b311676d-7780-4eec-85bb-24c29fe5ed93" TYPE="ext4"
/dev/mapper/centos-root: UUID="ea78266d-7f0e-4242-ab43-73f2278f1c80" TYPE="xfs"
/dev/mapper/centos-swap: UUID="278e45d0-6739-49b0-9fdb-a818fd5d993e" TYPE="swap"
[root@localhost ~]#
可知,/dev/sdb的UUID为b311676d-7780-4eec-85bb-24c29fe5ed93
5 修改/etc/fstab文件,增加开机自动挂载磁盘/dev/sdb的信息
[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Apr 11 23:14:01 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=a5e2f917-fdff-446d-9eba-5a0a2b94a7e4 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID=b311676d-7780-4eec-85bb-24c29fe5ed93 /data/mydata ext4 defaults 0 0
[root@localhost ~]#
6 测试是否可以自动挂载成功
[root@localhost ~]# umount /data/mydata/
[root@localhost ~]# mount | grep "/dev/sdb"
[root@localhost ~]# mount -a
[root@localhost ~]# mount | grep "/dev/sdb"
/dev/sdb on /data/mydata type ext4 (rw,relatime,seclabel,data=ordered)
[root@localhost ~]#
7 重启操作系统,查看是否开机自动挂载成功
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 28G 2.7G 26G 10% /
/dev/sda1 1014M 181M 834M 18% /boot
/dev/sdb 9.8G 37M 9.2G 1% /data/mydata
tmpfs 379M 0 379M 0% /run/user/0
[root@localhost ~]#
可知,开机启动后硬盘/dev/sdb被成功自动挂载到了/data/mydata路径下