74 partprobe-磁盘管理

时间:2023-11-22 11:45:38

partprobe命令用于重读分区表,当出现删除文件后,出现仍然占用空间。可以partprobe在不重启的情况下重读分区。

语法

partprobe (选项)  (参数)

选项

-d:不更新内核; 
-s:显示摘要和分区;
-h:显示帮助信息;
-v:显示版本信息。

参数

设备:指定需要确认分区表改变的硬盘对应的设备文件。

实例

使用partprobe不重启系统添加新的磁盘分区,主机自带硬盘超过300GB,目前只划分使用了3个主分区,不到70GB,如下:

[root@localhost ~]# df -h 
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 29G .7G 24G % /
/dev/sda2 29G 22G .2G % /oracle
tmpfs .0G .0G % /dev/shm
[root@localhost ~]# cat /proc/partitions major minor 
#blocks name sda
sda1
sda2
sda3
sdb
sdc …省略其他

现在需要给系统添加1个100GB的空间存放数据文件,而又不影响现有系统上业务的运行,使用fdisk结合partprobe命令不重启系统添加一块新的磁盘分区。操作步骤如下:

第1步 添加新的磁盘分区:

[root@localhost ~]# fdisk /dev/sda 
The number of cylinders for this disk is set to .
There is nothing wrong with that, but this is larger than , and could in certain setups cause problems with:
) software that runs at boot time (e.g., old versions of lilo)
) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/ FDISK)
command (m for help): p
Disk /dev/sda: 318.9 GB, bytes
heads, sectors/track, cylinders
Units = cylinders of * = bytes
Device Boot Start End Blocks id System
/dev/sda1 * + Linux
/dev/sda2 Linux
/dev/sda3 Linux swap / Solaris Command (m for help): n
Command action
e extended
p primary partition (-)
p Selected partition
First cylinder (-, default ):
Using default value
last cylinder or +size or +sizeM or +sizeK (-, default ): +100G Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error : D evice or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

第2步 使用工具partprobe让kernel读取分区信息:

[root@localhost ~]# partprobe

使用fdisk工具只是将分区信息写到磁盘,如果需要mkfs磁盘分区则需要重启系统,而使用partprobe则可以使kernel重新读取分区信息,从而避免重启系统。

第3步 格式化文件系统:

[root@localhost ~]# mkfs.ext3 /dev/sda4 

mke2fs 1.39 (-May-) 
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups blocks per group,
fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , ,    
, , , , , 23887872 Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every mounts or days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#

第4步 mount新的分区/dev/sda4:

[root@localhost ~]# e2label /dev/sda4 /data 
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/sda4 /data
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 % /
/dev/sda2 % /oracle
tmpfs % /dev/shm
/dev/sda4 % /data

使用partprobe可以不用重启系统即可配合fdisk工具创建新的分区。