sum=$(ll /sys/class/scsi_host/host* | wc -l)
for ((i=0; i<${sum}; i++))
do
echo "- - -" > /sys/class/scsi_host/host${i}/scan
done
查看占用磁盘空间最大的目录
基于du命令的深度查询参数,在根目录下执行以下命令
du -h --max-depth=1
执行此命令可以得出当前目录的下一级中占用最大磁盘空间的目录。
磁盘分区 - MBR类型
MBR类型特点
不支持2T以上硬盘
最多支持4个主分区
fdisk命令只能创建MBR分区
使用fdisk命令创建磁盘分区
[root@web-7 /]#fdisk /dev/sdb
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.
Command (m for help): p #列出分区表
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 label type: dos
Disk identifier: 0x25b1f0fc
Device Boot Start End Blocks Id System
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): # 分区编号:使用默认值
First sector (2048-20971519, default 2048): # 其实扇区:使用默认值
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +256M # 赋予该主分区256M的磁盘空间
Partition 1 of type Linux and of size 256 MiB is set
Command (m for help): p
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 label type: dos
Disk identifier: 0x25b1f0fc
Device Boot Start End Blocks Id System
/dev/sdb1 2048 526335 262144 83 Linux
Command (m for help): n #添加新分区
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e # 选择添加扩展分区
Partition number (2-4, default 2):
First sector (526336-20971519, default 526336):
Using default value 526336
Last sector, +sectors or +size{K,M,G} (526336-20971519, default 20971519):
Using default value 20971519 # 将全部的剩余空间给这个分区
Partition 2 of type Extended and of size 9.8 GiB is set
Command (m for help): p
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 label type: dos
Disk identifier: 0x25b1f0fc
Device Boot Start End Blocks Id System
/dev/sdb1 2048 526335 262144 83 Linux
/dev/sdb2 526336 20971519 10222592 5 Extended
Command (m for help): n #添加新分区
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l # 添加逻辑分区
Adding logical partition 5
First sector (528384-20971519, default 528384):
Using default value 528384
Last sector, +sectors or +size{K,M,G} (528384-20971519, default 20971519):
Using default value 20971519 # 将扩展分区的全部磁盘给这个逻辑分区
Partition 5 of type Linux and of size 9.8 GiB is set
Command (m for help): p
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 label type: dos
Disk identifier: 0x25b1f0fc
Device Boot Start End Blocks Id System
/dev/sdb1 2048 526335 262144 83 Linux
/dev/sdb2 526336 20971519 10222592 5 Extended
/dev/sdb5 528384 20971519 10221568 83 Linux
Command (m for help): w #!!!! 写入之前的操作 !!!!!
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
然后可以看到新的磁盘文件了
[root@web-7 /]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 256M 0 part
├─sdb2 8:18 0 1K 0 part
└─sdb5 8:21 0 9.8G 0 part #新的磁盘(逻辑分区)
sr0 11:0 1 4.4G 0 rom
[root@web-7 ~]#gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help): p #查看分区列表
Disk /dev/sdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 5C1FE704-60A3-4D3B-8F91-8C9782B0FAF6
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 20971453 sectors (10.0 GiB)
# 目前还没有分区
Number Start (sector) End (sector) Size Code Name
Command (? for help): n #增加一个分区
Partition number (1-128, default 1):
First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: #起始扇区:默认值
Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +1G #最后一个扇区:直接分给他1G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): # 创建GUID
Changed type of partition to 'Linux filesystem'
Command (? for help): p #查看分区列表
Disk /dev/sdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 5C1FE704-60A3-4D3B-8F91-8C9782B0FAF6
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 18874301 sectors (9.0 GiB)
# 可以发现有了一个分区
Number Start (sector) End (sector) Size Code Name
1 2048 2099199 1024.0 MiB 8300 Linux filesystem
Command (? for help): n #增加一个分区
Partition number (2-128, default 2):
First sector (34-20971486, default = 2099200) or {+-}size{KMGTP}:
Last sector (2099200-20971486, default = 20971486) or {+-}size{KMGTP}: #将所有剩余空间分给这个分区
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): #创建GUID
Changed type of partition to 'Linux filesystem'
Command (? for help): w #将之前的操作写入
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y #确认写入
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
验收分区
[root@web-7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 1G 0 part
└─sdb2 8:18 0 9G 0 part
sr0 11:0 1 4.4G 0 rom
[root@web-7 ~]#parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable msdos #转换磁盘类型
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No? yes
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
(parted) quit
Information: You may need to update /etc/fstab.
将MBR类型的磁盘转换为GPT
基于gdisk命令
[root@web-7 ~]#gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
#这里提示如果转换会重写整个磁盘,如果是误操作可以直接按q退出
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************
Command (? for help): w #写入操作
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
在服务器日常运行服务的过程中磁盘空间可能会变的越来越小,有一种可能是因为日志太多了,只要清理日志文件即可,也有可能是静态文件服务器中存放的内容越来越多,这些东西也没办法删减,所以只能对磁盘进行扩容。
插入新磁盘后服务器不识别
有两种解决方法:
然后通过
lsblk
命令应该能看到新安装的硬盘。以shell脚本扫描SCSI总线
查看占用磁盘空间最大的目录
基于du命令的深度查询参数,在根目录下执行以下命令
执行此命令可以得出当前目录的下一级中占用最大磁盘空间的目录。
磁盘分区 - MBR类型
MBR类型特点
使用fdisk命令创建磁盘分区
然后可以看到新的磁盘文件了
格式化文件系统
目前这个磁盘还是无法使用的,因为还没有文件系统;XFS是Centos7开始使用的默认文件系统。我们可以将新的磁盘格式化为这个系统使用
挂载磁盘
格式化后还需要将新磁盘挂载在某个目录下,这样我们才能够访问到这块磁盘;这个目录就像Windows我的电脑中的D盘E盘目录一样。
临时挂载
使用这种挂载方法,服务器重启后会失去挂载,必须重新进行手动挂载。
配置自动挂载
需要将配置写入到
/etc/fstab
文件中挂载参数
挂载参数其实就是
mount -o
命令可附加的挂载选项磁盘分区 - GPT(GUID)类型
GPT类型特点
使用gdisk命令创建GPT类型的分区
验收分区
格式化文件系统
这次将这块硬盘格式化为Ext4格式
挂载
写入挂载配置
生效挂载配置
将GPT类型转为MBR类型
基于parted命令
将MBR类型的磁盘转换为GPT
基于gdisk命令
Read Next
MySQL/Redis相关面试题
数据库运维(MySQL和Redis)的面试题总结
事件源模式和传统数据库方法在数据管理上的优劣分析
对事件源模式和传统数据库方法在应用程序性能影响、性能、扩展性和可靠性的分析;以及云原生环境下数据管理的最佳实践
关于Metrics_server在自托管环境下无法使用的问题
修复kubernetes的metrics server在自托管环境下因缺少CA证书而无法运行的问题。
关于IP、子网掩码、主机位和网络位的计算方法
如何通过子网掩码和掩码位计算一个IP地址的网络地址和可分配的主机位