mount挂载磁盘--CentOS7

 

CentOS7 挂载磁盘

 

参考如下链接:
https://jingyan.baidu.com/article/a681b0de5b46db3b184346fc.html

https://blog.csdn.net/linuxnews/article/details/51282164?utm_source=blogxgwz0

https://blog.csdn.net/weixin_33826609/article/details/89822811?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-89822811-blog-124241555.235^v32^pc_relevant_default_base3&spm=1001.2101.3001.4242.2&utm_relevant_index=4
https://blog.csdn.net/guo_3472428370/article/details/124241555

 

 

### 查看当前磁盘信息:17.2GB(没有新添加的磁盘大小)###
[root@localhost dev]# fdisk -l
Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 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: 0x00061005
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris
/dev/sda3 4605952 33554431 14474240 83 Linux

 

### 不重启手动刷新(或者reboot重启刷新) ###
[root@localhost ~]# ls /sys/class/scsi_host/ 查看该目录下有几个文件
host0 host1 host2 这里显示有3个链接,后面每一个都echo一下
[root@localhost scsi_host]# echo "- - -"> host0/scan 扫描
[root@localhost scsi_host]# echo "- - -"> host1/scan 扫描
[root@localhost scsi_host]# echo "- - -"> host2/scan 扫描
[root@localhost ~]# ls /sys/class/scsi_device/ 查看该目录下有几个文件
0:0:0:0 0:0:1:0 0:0:2:0 2:0:0:0 这里显示有4个链接,后面每一个都echo一下
[root@localhost scsi_device]# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
[root@localhost scsi_device]# echo 1 > /sys/class/scsi_device/0\:0\:1\:0/device/rescan
[root@localhost scsi_device]# echo 1 > /sys/class/scsi_device/0\:0\:2\:0/device/rescan
[root@localhost scsi_device]# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan

 

### 查看当前磁盘信息:(下方显示多出来了214.7GB)###
[root@localhost ~]# fdisk -l
Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 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: 0x00061005
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris
/dev/sda3 4605952 33554431 14474240 83 Linux
Disk /dev/sdb: 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

 

### 使用fdisk分区
[root@localhost ~]# fdisk /dev/sdb 上面查询到的名称 Disk "/dev/sdb" : 214.7GB
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x0d6fd843.
Command (m for help): m 查看帮助
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
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
u change display/entry units
v verify the partition table
w write table to disk and exit 写入磁盘表并退出
x extra functionality (experts only)
Command (m for help): n 添加新分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p 按需选择分区类型。这里我选择主分区。
Partition number (1-4, default 1): 回车默认(可选1-4分区号)
First sector (2048-419430399, default 2048): 回车默认(可选开始柱面,默认最小值)
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): 回车默认(可选结束柱面,默认最小值)
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set
Command (m for help): w 写入磁盘表并退出(保存)
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

 

### 格式化
[root@localhost ~]# fdisk -l 查看新创建磁盘设备(/dev/sdb1)
Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 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: 0x00061005
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris
/dev/sda3 4605952 33554431 14474240 83 Linux
Disk /dev/sdb: 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: 0x0d6fd843
Device Boot Start End Blocks Id System
/dev/sdb1 2048 419430399 209714176 83 Linux

[root@localhost ~]# mkfs.ext4 /dev/sdb1 用mkfs命令格式化该分区(mkfs有多种文件系统类型,可根据需要选择)
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
13107200 inodes, 52428544 blocks
2621427 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2199912448
1600 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, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

 

### 挂载磁盘
[root@localhost ~]# mkdir /abcd 创建挂载目录(名称自定义)

[root@localhost ~]# mount /dev/sdb1 /abcd/ 挂载[磁盘][目录]
[root@localhost ~]# df -h 查看挂载情况
Filesystem Size Used Avail Use% Mounted on
devtmpfs 909M 0 909M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 8.8M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda3 14G 1.8G 13G 13% /
/dev/sda1 197M 119M 78M 61% /boot
tmpfs 184M 0 184M 0% /run/user/0
/dev/sdb1 197G 61M 187G 1% /abcd

 

### 设置开机自动挂载 ###
[root@localhost /]# vi /etc/fstab 修改开机自动挂载文件(添加最后一行内容,对应前面的磁盘和挂载目录)
#
# /etc/fstab
# Created by anaconda on Thu Jul 9 15:25:16 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
#
UUID=cbd81e05-e46d-420b-a7ac-b51c97898df5 / xfs defaults 0 0
UUID=48f63743-f234-46b7-b471-ab5f6fb23ed7 /boot xfs defaults 0 0
UUID=6d252125-ff2e-492d-a7ea-6e897a35dc70 swap swap defaults 0 0
/dev/sdb1                                  /abcd                  ext4     defaults         0  0

 

 

第一列,实际分区名,/dev/sdb1,实际分区的卷标(Lable)。
如果是sata接口,且多个磁盘则,/dev/hda,/dev/hdb,/dev/hdc。每个磁盘分区标记为,/dev/hda1,/dev/hda2,/dev/hda3。
如果是SCSI接口则,/dev/sda,/dev/sdb
如果是标签,LABLE=/

第二列,挂载点。/abcd,必须为当前已存在的目录。为兼容最好权限777

第三列,文件系统类型。可以ext2,ext3,ext4等等,也可以auto系统自动侦测目标分区类型(auto常用挂载可移动设备)

第四列,挂载参数。defaults 常见:
auto:系统自动挂载
defaults:rw,suid,dev,exec,auto,nouser,and async
noauto开机不自动挂载
nouser只有超级用户可以挂载
ro按只读权限挂载
rw按读写权限挂载
user任何用户都可挂载
光驱和软盘只有在装有介质时才可挂载,因此是noauto

第五列,dump备份设置
下面最后有2个"0",
第一个0表示加载后的文件系统是否能被dump备份(0表示不能,1表示每天,2表示不定期)

第六列,fsck磁盘检查(如果两个分区的数字相同则同时检查)
第二个0表示开机过程中是否校验扇区pass(0表示不校验,1表示优先校验,像根目录,2表示在1级别后再校验)

 

###取消挂载,格式化的目录###
[root@localhost ~]# umount /dev/sdb
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.8M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda3 15G 1.7G 13G 12% /
/dev/sda1 190M 109M 67M 62% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0

 

posted @ 2020-07-17 17:33  1420_wafer  阅读(267)  评论(0)    收藏  举报