1 | partprobe
|
2 | ===
|
3 |
|
4 | 不重启的情况下重读分区
|
5 |
|
6 | ## 补充说明
|
7 |
|
8 | **partprobe命令** 用于重读分区表,当出现删除文件后,出现仍然占用空间。可以partprobe在不重启的情况下重读分区。
|
9 |
|
10 | ### 语法
|
11 |
|
12 | ```shell
|
13 | partprobe(选项)(参数)
|
14 | ```
|
15 |
|
16 | ### 选项
|
17 |
|
18 | ```shell
|
19 | -d:不更新内核;
|
20 | -s:显示摘要和分区;
|
21 | -h:显示帮助信息;
|
22 | -v:显示版本信息。
|
23 | ```
|
24 |
|
25 | ### 参数
|
26 |
|
27 | 设备:指定需要确认分区表改变的硬盘对应的设备文件。
|
28 |
|
29 | ### 实例
|
30 |
|
31 | 使用partprobe不重启系统添加新的磁盘分区,主机自带硬盘超过300GB,目前只划分使用了3个主分区,不到70GB,如下:
|
32 |
|
33 | ```shell
|
34 | [root@localhost ~]# df -h
|
35 | Filesystem Size Used Avail Use% Mounted on
|
36 | /dev/sda1 29G 3.7G 24G 14% /
|
37 | /dev/sda2 29G 22G 5.2G 81% /oracle
|
38 | tmpfs 2.0G 0 2.0G 0% /dev/shm
|
39 | ```
|
40 |
|
41 | ```shell
|
42 | [root@localhost ~]# cat /proc/partitions
|
43 | major minor #blocks name
|
44 |
|
45 | 8 0 311427072 sda
|
46 | 8 1 30716248 sda1
|
47 | 8 2 30716280 sda2
|
48 | 8 3 8193150 sda3
|
49 | 8 16 976896 sdb
|
50 | 8 32 976896 sdc
|
51 |
|
52 | …省略其他
|
53 | ```
|
54 |
|
55 | 现在需要给系统添加1个100GB的空间存放数据文件,而又不影响现有系统上业务的运行,使用fdisk结合partprobe命令不重启系统添加一块新的磁盘分区。操作步骤如下:
|
56 |
|
57 | **第1步 添加新的磁盘分区** :
|
58 |
|
59 | ```shell
|
60 | [root@localhost ~]# fdisk /dev/sda
|
61 | The number of cylinders for this disk is set to 38770.
|
62 | There is nothing wrong with that, but this is larger than 1024,
|
63 | and could in certain setups cause problems with:
|
64 | 1) software that runs at boot time (e.g., old versions of lilo)
|
65 | 2) booting and partitioning software from other OSs
|
66 | (e.g., DOS FDISK, OS/2 FDISK)
|
67 |
|
68 | command (m for help): p
|
69 |
|
70 | Disk /dev/sda: 318.9 GB, 318901321728 bytes
|
71 | 255 heads, 63 sectors/track, 38770 cylinders
|
72 | Units = cylinders of 16065 * 512 = 8225280 bytes
|
73 |
|
74 | Device Boot Start End Blocks id System
|
75 | /dev/sda1 * 1 3824 30716248+ 83 Linux
|
76 | /dev/sda2 3825 7648 30716280 83 Linux
|
77 | /dev/sda3 7649 8668 8193150 82 Linux swap / Solaris
|
78 |
|
79 | Command (m for help): n
|
80 | Command action
|
81 | e extended
|
82 | p primary partition (1-4)
|
83 | p
|
84 | Selected partition 4
|
85 | First cylinder (8669-38770, default 8669):
|
86 | Using default value 8669
|
87 | last cylinder or +size or +sizeM or +sizeK (8669-38770, default 38770): +100G
|
88 | Command (m for help): w
|
89 | The partition table has been altered!
|
90 |
|
91 | Calling ioctl() to re-read partition table.
|
92 |
|
93 | WARNING: Re-reading the partition table failed with error 16:
|
94 |
|
95 | Device or resource busy.
|
96 | The kernel still uses the old table.
|
97 | The new table will be used at the next reboot.
|
98 | Syncing disks.
|
99 | ```
|
100 |
|
101 | **第2步 使用工具partprobe让kernel读取分区信息:**
|
102 |
|
103 | ```shell
|
104 | [root@localhost ~]# partprobe
|
105 | ```
|
106 |
|
107 | 使用fdisk工具只是将分区信息写到磁盘,如果需要mkfs磁盘分区则需要重启系统,而使用partprobe则可以使kernel重新读取分区信息,从而避免重启系统。
|
108 |
|
109 | **第3步 格式化文件系统:**
|
110 |
|
111 | ```shell
|
112 | [root@localhost ~]# mkfs.ext3 /dev/sda4
|
113 | mke2fs 1.39 (29-May-2006)
|
114 | Filesystem label=
|
115 | OS type: Linux
|
116 | Block size=4096 (log=2)
|
117 | Fragment size=4096 (log=2)
|
118 | 12222464 inodes, 24416791 blocks
|
119 | 1220839 blocks (5.00%) reserved for the super user
|
120 | First data block=0
|
121 | Maximum filesystem blocks=4294967296
|
122 | 746 block groups
|
123 | 32768 blocks per group, 32768 fragments per group
|
124 | 16384 inodes per group
|
125 | Superblock backups stored on blocks:
|
126 | 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632,
|
127 | 2654208, 4096000, 7962624, 11239424, 20480000, 23887872
|
128 |
|
129 | Writing inode tables: done
|
130 | Creating journal (32768 blocks): done
|
131 | Writing superblocks and filesystem accounting information:
|
132 |
|
133 | done
|
134 |
|
135 | This filesystem will be automatically checked every 26 mounts or
|
136 | 180 days, whichever comes first. Use tune2fs -c or -i to override.
|
137 | [root@localhost ~]#
|
138 | ```
|
139 |
|
140 | **第4步 mount新的分区`/dev/sda4`:**
|
141 |
|
142 | ```shell
|
143 | [root@localhost ~]# e2label /dev/sda4 /data
|
144 | [root@localhost ~]# mkdir /data
|
145 | [root@localhost ~]# mount /dev/sda4 /data
|
146 | [root@localhost ~]# df
|
147 | Filesystem 1K-blocks Used Available Use% Mounted on
|
148 | /dev/sda1 29753556 3810844 24406900 14% /
|
149 | /dev/sda2 29753588 11304616 16913160 41% /oracle
|
150 | tmpfs 2023936 0 2023936 0% /dev/shm
|
151 | /dev/sda4 96132968 192312 91057300 1% /data
|
152 | ```
|
153 |
|
154 | 使用partprobe可以不用重启系统即可配合fdisk工具创建新的分区。
|
155 |
|
156 |
|