ZFS调试命令zdb之进阶用法

简介:

  zdb命令本身是可以查阅man zdb或zdb –help提供帮助的,无奈帮助太过简洁,而且省略了很多非常重要、有用的参数,正巧这几天研究,就记录一下。

    以下假设pool的名称为case2.2:





1
zdb –uuu case2.2

    作用:显示case2.2的活动uberblock,并显示其DVA,结果如下图所示:


 wKioL1fqt9CCFjfWAAJ53tHSs4o058.png




1
zdb –ddddd case2.2

    作用:显示所有文件系统集合上的对象的详细摘要信息,导出后有用信息太多了。足够看N久的了。



1
zdb –ddddd case2.2/ 4

    作用:显示case2.2用户文件系统下第4号节点文件的摘要信息,包括dva信息等,如果是zdb –ddddd case2.2 4,则表示是meta集合的第4号节点的摘要信息。

wKiom1fqt9KQ7bHWAAWpfQEC1lk935.png




1
2
3
4
5
6
7
8
#!/bin/bash
echo  "readzfsobj.sh <poolname> <objectid> <outfile>"
touch  $3
zdb -ddddd $1/ $2 | sed  -n  "/^  *[0123456789abcdef]*  *L0 * /p"  | awk  '{print $3}' | while  read  line
do
     #echo "zy:$line"
     zdb -R $1 $line:r >>$3
done

       作用:使用此shell脚本,配合zdb命令,即可导出指定对象,主要用于研究目录等非文件集合数据。如通过ls -i 命令知道某个目录的节点号,执行

1
readzfsobj.sh case2.2 4 root.img

即可将文件系统根目录块导出成一个普通文件,再用二进制工具查看则较容易读懂mzap,fatzap的结构。

    大致原理:假设有一大目录id是13,因执行zdb -ddddd case2.2  13时,会列出如下图所示目录的地址索引信息,通过sed命令过滤出这些行,再通过awk打印其中的DVA。最后,通过一行一行地执行zdb -R 命令把块导出后输入到目标文件中(本示例为去掉压缩选项后的处理方案,如果有压缩,需做针对性处置)。

wKioL1fqt3iipaAtAAfNibzLJwE725.png-wh_50




zdb -m <poolname>:可以打印每个metaslab的使用情况,如果是两个m,多列出磁盘可分配碎片清单;如果是3个m,再多列出内存可分配碎片清单;如果是4个m,再列出详细的io分配/释放记录清单;

zdb -m <poolname> <vdev> <metaslab number>:可以列出指定的某个vdev的metalabs的情况,规则与上述相同。

1
2
3
4
5
6
7
[root@localhost ~] # zdb -m case4 sdb1 4
 
Metaslabs:
     vdev          0
     metaslabs   119   offset                spacemap           free     
     ---------------   -------------------   ---------------   -------------
     metaslab      4   offset     40000000   spacemap     42    free     5.05M
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost ~] # zdb -mm case4 sdb1 4
 
Metaslabs:
     vdev          0
     metaslabs   119   offset                spacemap           free     
     ---------------   -------------------   ---------------   -------------
     metaslab      4   offset     40000000   spacemap     42    free     5.05M
     On-disk histogram:      fragmentation 11
               9:      2 **
              10:      0
              11:      0
              12:      0
              13:      1 *
              14:      1 *
              15:      2 **
              16:      0
              17:      0
              18:      0
              19:      0
              20:      0
              21:      0
              22:      1 *
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@localhost ~] # zdb -mmm case4 sdb1 4
 
Metaslabs:
     vdev          0
     metaslabs   119   offset                spacemap           free     
     ---------------   -------------------   ---------------   -------------
     metaslab      4   offset     40000000   spacemap     42    free     5.05M
                       segments         19   maxsize   4.44M   freepct    1%
     In-memory histogram:
               9:      3 ***
              10:      2 **
              11:      1 *
              12:      0
              13:      1 *
              14:      6 ******
              15:      2 **
              16:      2 **
              17:      1 *
              18:      0
              19:      0
              20:      0
              21:      0
              22:      1 *
     On-disk histogram:      fragmentation 11
               9:      2 **
              10:      0
              11:      0
              12:      0
              13:      1 *
              14:      1 *
              15:      2 **
              16:      0
              17:      0
              18:      0
              19:      0
              20:      0
              21:      0
              22:      1 *
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
[root@localhost ~] # zdb -mmmm case4 sdb1 4
 
Metaslabs:
     vdev          0
     metaslabs   119   offset                spacemap           free     
     ---------------   -------------------   ---------------   -------------
     metaslab      4   offset     40000000   spacemap     42    free     5.05M
                       segments         19   maxsize   4.44M   freepct    1%
     In-memory histogram:
               9:      3 ***
              10:      2 **
              11:      1 *
              12:      0
              13:      1 *
              14:      6 ******
              15:      2 **
              16:      2 **
              17:      1 *
              18:      0
              19:      0
              20:      0
              21:      0
              22:      1 *
     On-disk histogram:      fragmentation 11
               9:      2 **
              10:      0
              11:      0
              12:      0
              13:      1 *
              14:      1 *
              15:      2 **
              16:      0
              17:      0
              18:      0
              19:      0
              20:      0
              21:      0
              22:      1 *
         [     0] ALLOC: txg 109, pass 1
         [     1]    A  range: 0040000000-00403e9c00  size: 3e9c00
         [     2] FREE: txg 109, pass 1
         [     3]    F  range: 00403e4000-00403e4800  size: 000800
         [     4] ALLOC: txg 109, pass 2
         [     5]    A  range: 00403e9c00-00403f7000  size: 00d400
         [     6] ALLOC: txg 109, pass 3
         [     7]    A  range: 00403f7000-00403fb000  size: 004000
         [     8] ALLOC: txg 111, pass 1
         [     9]    A  range: 00403fb000-00413fb000  size: 1000000
         [    10]    A  range: 00413fb000-00423fb000  size: 1000000
         [    11]    A  range: 00423fb000-0042a8cc00  size: 691c00
         [    12] FREE: txg 111, pass 1
         [    13]    F  range: 00403c0000-00403e4000  size: 024000
         [    14]    F  range: 00403e4800-00403e9c00  size: 005400
         [    15]    F  range: 0042a87000-0042a87800  size: 000800
         [    16] ALLOC: txg 111, pass 2
         [    17]    A  range: 0042a8cc00-0042a97c00  size: 00b000
         [    18] ALLOC: txg 111, pass 3
         [    19]    A  range: 0042a97c00-0042a9ec00  size: 007000
         [    20] ALLOC: txg 112, pass 1
         [    21]    A  range: 0042a9ec00-0042ac5000  size: 026400
         [    22] FREE: txg 112, pass 1
         [    23]    F  range: 0042a6f000-0042a87000  size: 018000
         [    24]    F  range: 0042a87800-0042a8cc00  size: 005400
         [    25]    F  range: 0042abf400-0042abfc00  size: 000800
         [    26] ALLOC: txg 112, pass 2
         [    27]    A  range: 0042ac5000-0042ad1000  size: 00c000
         [    28] FREE: txg 112, pass 2
         [    29]    F  range: 00403e9c00-00403eac00  size: 001000
         [    30]    F  range: 00403eae00-00403ebe00  size: 001000
         [    31]    F  range: 00403ec000-00403fb000  size: 00f000
         [    32] ALLOC: txg 112, pass 3
         [    33]    A  range: 0042ad1000-0042ad7000  size: 006000
         [    34] ALLOC: txg 114, pass 1
         [    35]    A  range: 00403c0000-00403e8800  size: 028800
         [    36]    A  range: 0042ad7000-0043ad7000  size: 1000000
         [    37]    A  range: 0043ad7000-004448b000  size: 9b4000
         [    38] FREE: txg 114, pass 1
         [    39]    F  range: 0042a9ec00-0042a9ee00  size: 000200
         [    40]    F  range: 0042a9f400-0042aa3400  size: 004000
         [    41]    F  range: 0042aa7400-0042abf400  size: 018000
         [    42]    F  range: 0042abfc00-0042ac5000  size: 005400
         [    43]    F  range: 0044485400-0044485c00  size: 000800
         [    44] ALLOC: txg 114, pass 2
         [    45]    A  range: 004448b000-0044496000  size: 00b000
         [    46] FREE: txg 114, pass 2
         [    47]    F  range: 0042a8cc00-0042a9bc00  size: 00f000
         [    48]    F  range: 0042a9cc00-0042a9dc00  size: 001000
         [    49] ALLOC: txg 114, pass 3
         [    50]    A  range: 0044496000-004449d000  size: 007000
         [    51] ALLOC: txg 117, pass 1
         [    52]    A  range: 004449d000-004549d000  size: 1000000
         [    53]    A  range: 004549d000-0045a07a00  size: 56aa00
         [    54] FREE: txg 117, pass 1
         [    55]    F  range: 00403c0000-00403c0400  size: 000400
         [    56]    F  range: 0042ad8a00-0042ad8c00  size: 000200
         [    57]    F  range: 004441d400-0044421400  size: 004000
         [    58]    F  range: 0044469400-0044485400  size: 01c000
         [    59]    F  range: 0044485c00-004448b000  size: 005400
         [    60]    F  range: 0045a01e00-0045a02600  size: 000800
         [    61] ALLOC: txg 117, pass 2
         [    62]    A  range: 0045a07a00-0045a12a00  size: 00b000
         [    63] FREE: txg 117, pass 2
         [    64]    F  range: 0042a9bc00-0042a9cc00  size: 001000
         [    65]    F  range: 0042a9dc00-0042a9ec00  size: 001000
         [    66]    F  range: 0042ac6000-0042ad6000  size: 010000
         [    67] ALLOC: txg 117, pass 3
         [    68]    A  range: 0045a12a00-0045a16a00  size: 004000
         [    69] ALLOC: txg 118, pass 1
         [    70]    A  range: 00403ec000-00403f4000  size: 008000
         [    71]    A  range: 0045a16a00-0046a16a00  size: 1000000
         [    72]    A  range: 0046a16a00-0047a16a00  size: 1000000
         [    73]    A  range: 0047a16a00-0047dbca00  size: 3a6000
         [    74] FREE: txg 118, pass 1
         [    75]    F  range: 0042ad7200-0042ad7400  size: 000200
         [    76]    F  range: 00453ffc00-00453ffe00  size: 000200
         [    77]    F  range: 004588b000-004588b400  size: 000400
         [    78]    F  range: 00458be800-00458bec00  size: 000400
         [    79]    F  range: 004593de00-0045941e00  size: 004000
         [    80]    F  range: 00459d9e00-00459dde00  size: 004000
         [    81]    F  range: 00459e1e00-0045a01e00  size: 020000
         [    82]    F  range: 0045a02600-0045a07a00  size: 005400
         [    83]    F  range: 0047db6e00-0047db7600  size: 000800
         [    84] ALLOC: txg 118, pass 2
         [    85]    A  range: 0047dbca00-0047dc7a00  size: 00b000
         [    86] FREE: txg 118, pass 2
         [    87]    F  range: 004448b000-004449a000  size: 00f000
         [    88] ALLOC: txg 118, pass 3
         [    89]    A  range: 0047dc7a00-0047dcba00  size: 004000
         [    90] ALLOC: txg 119, pass 1
         [    91]    A  range: 0047dcba00-0048dcba00  size: 1000000
         [    92]    A  range: 0048dcba00-0049dcba00  size: 1000000
         [    93]    A  range: 0049dcba00-004ab07a00  size: d3c000
         [    94] FREE: txg 119, pass 1
         [    95]    F  range: 0047abde00-0047abee00  size: 001000
         [    96]    F  range: 0047d82e00-0047d86e00  size: 004000
         [    97]    F  range: 0047d9ae00-0047db6e00  size: 01c000
         [    98]    F  range: 0047db7600-0047dbca00  size: 005400
         [    99]    F  range: 004ab01e00-004ab02600  size: 000800
         [   100] ALLOC: txg 119, pass 2
         [   101]    A  range: 004ab07a00-004ab12a00  size: 00b000
         [   102] FREE: txg 119, pass 2
         [   103]    F  range: 0045a07a00-0045a16a00  size: 00f000
         [   104] ALLOC: txg 119, pass 3
         [   105]    A  range: 004ab12a00-004ab16a00  size: 004000
         [   106] ALLOC: txg 120, pass 1
         [   107]    A  range: 004ab16a00-004bb16a00  size: 1000000
         [   108]    A  range: 004bb16a00-004cb16a00  size: 1000000
         [   109]    A  range: 004cb16a00-004db16a00  size: 1000000
         [   110]    A  range: 004db16a00-004db18000  size: 001600
         [   111] FREE: txg 120, pass 1
         [   112]    F  range: 0047dd3e00-0047dd6600  size: 002800
         [   113]    F  range: 004aab5a00-004aabda00  size: 008000
         [   114]    F  range: 004aac1e00-004aac5e00  size: 004000
         [   115]    F  range: 004aae5e00-004ab01e00  size: 01c000
         [   116]    F  range: 004ab02600-004ab07a00  size: 005400
         [   117]    F  range: 004db12400-004db12c00  size: 000800
         [   118] ALLOC: txg 120, pass 2
         [   119]    A  range: 004db18000-004db23000  size: 00b000
         [   120] FREE: txg 120, pass 2
         [   121]    F  range: 0047dbca00-0047dcba00  size: 00f000
         [   122] ALLOC: txg 120, pass 3
         [   123]    A  range: 004db23000-004db27000  size: 004000
         [   124] ALLOC: txg 121, pass 1
         [   125]    A  range: 004db27000-004e090c00  size: 569c00
         [   126] FREE: txg 121, pass 1
         [   127]    F  range: 004dabe000-004dac6000  size: 008000
         [   128]    F  range: 004daf6400-004db12400  size: 01c000
         [   129]    F  range: 004db12c00-004db18000  size: 005400
         [   130]    F  range: 004e08b000-004e08b800  size: 000800
         [   131] ALLOC: txg 121, pass 2
         [   132]    A  range: 004e090c00-004e09bc00  size: 00b000
         [   133] FREE: txg 121, pass 2
         [   134]    F  range: 004ab07a00-004ab16a00  size: 00f000
         [   135] ALLOC: txg 121, pass 3
         [   136]    A  range: 004e09bc00-004e09fc00  size: 004000
         [   137] ALLOC: txg 123, pass 1
         [   138]    A  range: 00403c0000-00403c0400  size: 000400
         [   139]    A  range: 00403e8800-00403eac00  size: 002400
         [   140]    A  range: 00403eae00-00403ebe00  size: 001000
         [   141]    A  range: 00403f4000-00403fb000  size: 007000
         [   142]    A  range: 0042a6f000-0042a9ee00  size: 02fe00
         [   143]    A  range: 0042a9f400-0042aa3400  size: 004000
         [   144]    A  range: 0042aa7400-0042ac5000  size: 01dc00
         [   145]    A  range: 0042ac6000-0042ad6000  size: 010000
         [   146]    A  range: 0042ad7200-0042ad7400  size: 000200
         [   147]    A  range: 0042ad8a00-0042ad8c00  size: 000200
         [   148]    A  range: 004441d400-0044421400  size: 004000
         [   149]    A  range: 0044469400-004449a000  size: 030c00
         [   150]    A  range: 00453ffc00-00453ffe00  size: 000200
         [   151]    A  range: 004588b000-004588b400  size: 000400
         [   152]    A  range: 00458be800-00458bec00  size: 000400
         [   153]    A  range: 004593de00-0045941e00  size: 004000
         [   154]    A  range: 00459d9e00-00459dde00  size: 004000
         [   155]    A  range: 00459e1e00-0045a16a00  size: 034c00
         [   156]    A  range: 0047abde00-0047abee00  size: 001000
         [   157]    A  range: 0047d82e00-0047d86e00  size: 004000
         [   158]    A  range: 0047d9ae00-0047dcba00  size: 030c00
         [   159]    A  range: 0047dd3e00-0047dd6600  size: 002800
         [   160]    A  range: 004aab5a00-004aabda00  size: 008000
         [   161]    A  range: 004aac1e00-004aac5e00  size: 004000
         [   162]    A  range: 004aae5e00-004ab07a00  size: 021c00
         [   163]    A  range: 004db12400-004db12c00  size: 000800
         [   164]    A  range: 004e09fc00-004f09fc00  size: 1000000
         [   165]    A  range: 004f09fc00-004fb92e00  size: af3200
         [   166] FREE: txg 123, pass 1
         [   167]    F  range: 0042a9ee00-0042a9f400  size: 000600
         [   168]    F  range: 0042aa3400-0042aa7400  size: 004000
         [   169]    F  range: 0046680800-0046680e00  size: 000600
         [   170]    F  range: 00474f7400-00474f7600  size: 000200
         [   171]    F  range: 0047c5ae00-0047c5ee00  size: 004000
         [   172]    F  range: 0047cb6e00-0047cbae00  size: 004000
         [   173]    F  range: 0047d72e00-0047d76e00  size: 004000
         [   174]    F  range: 004ac8cc00-004ac91200  size: 004600
         [   175]    F  range: 004daca400-004dace400  size: 004000
         [   176]    F  range: 004e067000-004e08b000  size: 024000
         [   177]    F  range: 004e08b800-004e090c00  size: 005400
         [   178]    F  range: 004fb8d200-004fb8da00  size: 000800
         [   179] ALLOC: txg 123, pass 2
         [   180]    A  range: 004fb92e00-004fb9de00  size: 00b000
         [   181] FREE: txg 123, pass 2
         [   182]    F  range: 004db18000-004db27000  size: 00f000
         [   183] ALLOC: txg 123, pass 3
         [   184]    A  range: 004fb9de00-004fba1e00  size: 004000
         [   185] FREE: txg 125, pass 1
         [   186]    F  range: 004fb8e600-004fb92e00  size: 004800
         [   187] FREE: txg 125, pass 2
         [   188]    F  range: 004e090c00-004e09fc00  size: 00f000
         [   189] FREE: txg 127, pass 2
         [   190]    F  range: 00403eac00-00403eae00  size: 000200
         [   191]    F  range: 00403ebe00-00403ec000  size: 000200
         [   192]    F  range: 004449a000-004449c000  size: 002000
         [   193]    F  range: 004fb92e00-004fba1e00  size: 00f000




引用:http://cuddletech.com/?p=407 中的一段zdb命令的说明

 

    There are 3 arguments that are really the core ones of interest, but fefore we get to them, you absolutely must understand something unique about zdb. ZDB is like a magnifying glass, at default magnification you can see that its tissue, turn up the magnification and you see that it has veins, turn it up again and you see how intricate the system is, crank it up one more time and you can see blood cells themselves. With zdb, each time we repeat an argument we increase the verbosity and thus dig deeper. For instance, zdb -d will list the datasets of a pool, but zdb -dd will output the list of objects within the pool. Thus, when you really zoom in you’ll see commands that look really odd like zdb -ddddddddd. This takes a little practice to get the hang of, so please toy around on a small test pool to get the hang of it.

    Now, here are summaries of the 3 primary arguments you’ll use and how things change as you crank up the verbosity:


  • zdb -b pool: This will traverse blocks looking for leaks like the default form.


    • -bb: Outputs a breakdown of space (block) usage for various ZFS object types.

    • -bbb: Same as above, but includes breakdown by DMU/SPA level (L0-L6).

    • -bbbb: Same as above, but includes line line per object with details about it, including compression, checksum, DVA, object ID, etc.

    • -bbbbb…: Same as above.


  • zdb -d dataset: This will output a list of objects within a dataset. More d’s means more verbosity:


    • -d: Output list of datasets, including ID, cr_txg, size, and number of objects.

    • –dd: Output concise list of objects within the dataset, with object id, lsize, asize, type, etc.

    • -ddd: Same as dd.

    • -dddd: Outputs list of datasets and objects in detail, including objects path (filename), a/c/r/mtime, mode, etc.

    • -ddddd: Same as previous, but includes indirect block addresses (DVAs) as well.

    • -dddddd….: Same as above.


  • zdb -R pool:vdev_specifier:offset:size[:flags]: Given a DVA, outputs object contents in hex display format. If given the :r flag it will output in raw binary format. This can be used for manual recovery of files.










本文转自 张宇 51CTO博客,原文链接:http://blog.51cto.com/zhangyu/1857185,如需转载请自行联系原作者
目录
相关文章
|
6月前
|
监控 Linux 数据处理
|
4月前
|
Linux
Linux02---命令基础 Linux命令基础, ls命令入门,ls命令参数和选项,命令行是一种以纯字符操作系统的方式,command命令本身,options命令的细节行为,parameter命令的
Linux02---命令基础 Linux命令基础, ls命令入门,ls命令参数和选项,命令行是一种以纯字符操作系统的方式,command命令本身,options命令的细节行为,parameter命令的
|
5月前
|
Java Linux 网络安全
Linux常用50个命令分享:功能、示例与实用技巧
Linux常用50个命令分享:功能、示例与实用技巧
|
6月前
|
存储 运维 搜索推荐
深入理解文件系统与文件操作:从基础概念到高级用法
深入理解文件系统与文件操作:从基础概念到高级用法
|
6月前
|
分布式计算 Ubuntu Linux
Linux的基础编程——Linux常用操作总结(十一)
Linux的基础编程——Linux常用操作总结(十一)
56 0
Linux的基础编程——Linux常用操作总结(十一)
|
Linux Shell
Linux常用命令用法及实现方式
3.查找定位文件 (1)pwd命令:pwd命令用于显示用户当前所处的工作目录,英文全称为“print working directory”,输入该命令后按回车键执行即可。 (2)cd命令:cd命令用于切换当前的工作路径,英文全称为“change directory”,语法格式为“cd [参数] [目录]”。 (3)ls命令:ls命令用于显示目录中的文件信息,英文全称为“list”,语法格式为“ls [参数] [文件名称]”。 (4)tree命令:tree命令用于以树状图的形式列出目录内容及结构,输入该命令后按回车键执行即可。
|
Linux Windows
linux入门练级篇:ls指令你真的会用吗?(下)
linux入门练级篇:ls指令你真的会用吗?
103 1
|
人工智能 Linux 索引
linux入门练级篇:ls指令你真的会用吗?(上)
linux入门练级篇:ls指令你真的会用吗?
176 0
|
Linux
Linux tail命令该如何使用?这篇文章讲的十分详细!
Linux tail命令该如何使用?这篇文章讲的十分详细!
493 0
|
Linux Shell PHP
Linux基本功系列之rename命令实战
Linux基本功系列之rename命令实战
293 0
Linux基本功系列之rename命令实战