centos7磁盘挂载及取消

磁盘挂载
查看已经挂载磁盘数

cat /proc/scsi/scsi | grep Host
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Host: scsi2 Channel: 00 Id: 00 Lun: 00
# 或者
ll /dev/disk/by-path | grep -v part
lrwxrwxrwx. 1 root root 9 Dec 2 00:25 pci-0000:00:1f.2-ata-2.0 -> ../../sda
lrwxrwxrwx. 1 root root 9 Dec 2 00:25 pci-0000:00:1f.2-ata-2.0 -> ../../sdb
判断磁盘名

ll /dev/disk/by-path/
取到了'../../sdb',
则磁盘名为:/dev/disk/by-path/../../sdb,即 /dev/sdb
删除/dev/sdb所有分区

fdisk /dev/sdb
Command (m for help): p(查看当前分区状态)
Command (m for help): d(删除分区)
Partition number (1-3): 3(选择要删除的分区)
Command (m for help): d(删除分区)
Partition number (1-2): 2(选择要删除的分区)
Command (m for help): d(因为只剩下一个分区,无需选择直接删除)
Command (m for help): p(查看当前分区状态)
Command (m for help): w(回车保存新的分区)
格式化磁盘

fdisk /dev/sdb
Command(m for help): n(回车新建分区)
p primary partition(1-4): p(回车新建主分区)
Partition number (1-4): 1(分区号1-4之间选择1)
First cylinder(2048-xxxxx,default 2048):(开始柱面 回车默认选择最小值)
Last cylinder(2048-xxxxx,default xxxxx):(结束柱面 选择上一步中的xxxxx)
Command(m for help): p(查看调整后分区表)
Command(m for help): w(回车保存新的分区)
如果提示“Partition table entries are not in disk order”则执行

fdisk /dev/sdb
Command(m for help): x(进入专家模式)
Command(m for help): f(修复分区表)
Command(m for help): p(查看调整后分区表)
Command(m for help): w(回车保存新的分区)
创建磁盘分区

mkfs.ext4 /dev/sdb1
Writing superblocks and filesystem accounting information:(回车)
挂载分区中的磁盘到目录/file1

# 创建目录/file1
# 挂载/dev/sdb1 到目录 /file1
mkdir /file1
mount /dev/sdb1 /file1
将挂载信息写入fstab,让系统自动挂载

# 参数说明
设备名: /dev/sdb1(一个磁盘分区)
挂载点: /file1(系统上的一个目录)
设备类型: ext4(可通过'man fstab'查询支持类型)
挂载参数: defaults(参数默认即可)
dump-freq: 0
pass-num: 0
echo "/dev/sdb1 /file1 ext4 defaults 0 0" >> /etc/fstab
查看挂载写入情况

cat /etc/fstab
取消挂载
安装psmisc

yum install psmisc -y
取消目录占用

fuser -k /file1
fuser -k /dev/sdb1
取消挂载点

umount /file1
umount /dev/sdb1
删除/dev/sdb所有分区

fdisk /dev/sdb
Command (m for help): p(查看当前分区状态)
Command (m for help): d(删除分区)
Partition number (1-2): 1(选择要删除的分区)
Command (m for help): d(删除分区)
Partition number (1-2): 2(选择要删除的分区)
Command (m for help): p(查看当前分区状态)
Command (m for help): w(回车保存新的分区)

 

https://yq.aliyun.com/articles/601273

posted @ 2018-12-15 02:11  泡面 @ 幸福  阅读(12913)  评论(0编辑  收藏  举报