partprobe

不重啓的情況下重讀分區

補充說明

partprobe命令 用於重讀分區表,當出現刪除文件後,出現仍然佔用空間。可以partprobe在不重啓的情況下重讀分區。

語法

1partprobe(選項)(參數)

選項

1-d:不更新內核;
2-s:顯示摘要和分區;
3-h:顯示幫助信息;
4-v:顯示版本信息。

參數

設備:指定需要確認分區表改變的硬盤對應的設備文件。

實例

使用partprobe不重啓系統添加新的磁盤分區,主機自帶硬盤超過300GB,目前只劃分使用了3個主分區,不到70GB,如下:

1[root@localhost ~]# df -h 
2Filesystem Size Used Avail Use% Mounted on 
3/dev/sda1 29G 3.7G  24G 14% / 
4/dev/sda2 29G  22G 5.2G 81% /oracle 
5tmpfs    2.0G    0 2.0G  0% /dev/shm
 1[root@localhost ~]# cat /proc/partitions
 2major minor  #blocks  name
 3
 4   8     0  311427072 sda
 5   8     1   30716248 sda1
 6   8     2   30716280 sda2
 7   8     3    8193150 sda3
 8   8    16     976896 sdb
 9   8    32     976896 sdc
10
11…省略其他

現在需要給系統添加1個100GB的空間存放數據文件,而又不影響現有系統上業務的運行,使用fdisk結合partprobe命令不重啓系統添加一塊新的磁盤分區。操作步驟如下:

第1步 添加新的磁盤分區

 1[root@localhost ~]# fdisk /dev/sda
 2The number of cylinders for this disk is set to 38770.
 3There is nothing wrong with that, but this is larger than 1024,
 4and could in certain setups cause problems with:
 51) software that runs at boot time (e.g., old versions of lilo)
 62) booting and partitioning software from other OSs
 7   (e.g., DOS FDISK, OS/2 FDISK)
 8
 9command (m for help): p
10
11Disk /dev/sda: 318.9 GB, 318901321728 bytes
12255 heads, 63 sectors/track, 38770 cylinders
13Units = cylinders of 16065 * 512 = 8225280 bytes
14
15   Device Boot      Start         End      Blocks   id  System
16/dev/sda1   *           1        3824    30716248+  83  Linux
17/dev/sda2            3825        7648    30716280   83  Linux
18/dev/sda3            7649        8668     8193150   82  Linux swap / Solaris
19
20Command (m for help): n
21Command action
22   e   extended
23   p   primary partition (1-4)
24p
25Selected partition 4
26First cylinder (8669-38770, default 8669):
27Using default value 8669
28last cylinder or +size or +sizeM or +sizeK (8669-38770, default 38770): +100G   
29Command (m for help): w
30The partition table has been altered!
31
32Calling ioctl() to re-read partition table.
33
34WARNING: Re-reading the partition table failed with error 16: 
35
36Device or resource busy.
37The kernel still uses the old table.
38The new table will be used at the next reboot.
39Syncing disks.

第2步 使用工具partprobe讓kernel讀取分區信息:

1[root@localhost ~]# partprobe

使用fdisk工具只是將分區信息寫到磁盤,如果需要mkfs磁盤分區則需要重啓系統,而使用partprobe則可以使kernel重新讀取分區信息,從而避免重啓系統。

第3步 格式化文件系統:

 1[root@localhost ~]# mkfs.ext3 /dev/sda4
 2mke2fs 1.39 (29-May-2006)
 3Filesystem label=
 4OS type: Linux
 5Block size=4096 (log=2)
 6Fragment size=4096 (log=2)
 712222464 inodes, 24416791 blocks
 81220839 blocks (5.00%) reserved for the super user
 9First data block=0
10Maximum filesystem blocks=4294967296
11746 block groups
1232768 blocks per group, 32768 fragments per group
1316384 inodes per group
14Superblock backups stored on blocks:
15        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 
16    2654208, 4096000, 7962624, 11239424, 20480000, 23887872
17
18Writing inode tables: done
19Creating journal (32768 blocks): done
20Writing superblocks and filesystem accounting information:
21
22done
23
24This filesystem will be automatically checked every 26 mounts or
25180 days, whichever comes first.  Use tune2fs -c or -i to override.
26[root@localhost ~]#

第4步 mount新的分區/dev/sda4

1[root@localhost ~]# e2label  /dev/sda4 /data
2[root@localhost ~]# mkdir /data
3[root@localhost ~]# mount /dev/sda4 /data
4[root@localhost ~]# df
5Filesystem           1K-blocks      Used Available Use% Mounted on
6/dev/sda1             29753556   3810844  24406900  14% /
7/dev/sda2             29753588  11304616  16913160  41% /oracle
8tmpfs                  2023936         0   2023936   0% /dev/shm
9/dev/sda4             96132968    192312  91057300   1% /data

使用partprobe可以不用重啓系統即可配合fdisk工具創建新的分區。

來源:https://github.com/jaywcjlove/linux-command

最後修改於: Wednesday, January 31, 2024

相關文章:

翻譯: