Linux學(xué)習(xí)
一、LVM講解
二、磁盤故障小案例
一、LVM講解
LVM有一定的局限性;數(shù)據(jù)恢復(fù)困難
物理分區(qū)==>物理卷==>卷組==>邏輯卷
準(zhǔn)備磁盤分區(qū)
- fdisk /dev/sdb
- n創(chuàng)建三個新分區(qū),分別1G
- t改變分區(qū)類型為8e
- 操作
1. [root@centos7-01 ~]# fdisk -l
2. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
3. Units = 扇區(qū) of 1 * 512 = 512 bytes
4. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
5. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
6. 磁盤 /dev/sda:32.2 GB, 32212254720 字節(jié),62914560 個扇區(qū)
7. Units = 扇區(qū) of 1 * 512 = 512 bytes
8. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
9. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
10. 磁盤標(biāo)簽類型:dos
11. 磁盤標(biāo)識符:0x000ee6f4
12. 設(shè)備 Boot Start End Blocks Id System
13. /dev/sda1 * 2048 411647 204800 83 Linux
14. /dev/sda2 411648 62914559 31251456 8e Linux LVM
15. 磁盤 /dev/mapper/cl-root:29.9 GB, 29850861568 字節(jié),58302464 個扇區(qū)
16. Units = 扇區(qū) of 1 * 512 = 512 bytes
17. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
18. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
19. 磁盤 /dev/mapper/cl-swap:2147 MB, 2147483648 字節(jié),4194304 個扇區(qū)
20. Units = 扇區(qū) of 1 * 512 = 512 bytes
21. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
22. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
23. [root@centos7-01 ~]#
24. [root@centos7-01 ~]# fdisk /dev/sdb
25. 歡迎使用 fdisk (util-linux 2.23.2)。
26. 更改將停留在內(nèi)存中,直到您決定將更改寫入磁盤。
27. 使用寫入命令前請三思。
28. Device does not contain a recognized partition table
29. 使用磁盤標(biāo)識符 0xc29f4c6d 創(chuàng)建新的 DOS 磁盤標(biāo)簽。
30. 命令(輸入 m 獲取幫助):p
31. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
32. Units = 扇區(qū) of 1 * 512 = 512 bytes
33. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
34. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
35. 磁盤標(biāo)簽類型:dos
36. 磁盤標(biāo)識符:0xc29f4c6d
37. 設(shè)備 Boot Start End Blocks Id System
38. 命令(輸入 m 獲取幫助):m
39. 命令操作
40. a toggle a bootable flag
41. b edit bsd disklabel
42. c toggle the dos compatibility flag
43. d delete a partition
44. g create a new empty GPT partition table
45. G create an IRIX (SGI) partition table
46. l list known partition types
47. m print this menu
48. n add a new partition
49. o create a new empty DOS partition table
50. p print the partition table
51. q quit without saving changes
52. s create a new empty Sun disklabel
53. t change a partition's system id
54. u change display/entry units
55. v verify the partition table
56. w write table to disk and exit
57. x extra functionality (experts only)
58. 命令(輸入 m 獲取幫助):p
59. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
60. Units = 扇區(qū) of 1 * 512 = 512 bytes
61. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
62. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
63. 磁盤標(biāo)簽類型:dos
64. 磁盤標(biāo)識符:0xc29f4c6d
65. 設(shè)備 Boot Start End Blocks Id System
66. 命令(輸入 m 獲取幫助):n
67. Partition type:
68. p primary (0 primary, 0 extended, 4 free)
69. e extended
70. Select (default p): p
71. 分區(qū)號 (1-4,默認(rèn) 1):
72. 起始 扇區(qū) (2048-20971519,默認(rèn)為 2048):
73. 將使用默認(rèn)值 2048
74. Last 扇區(qū), +扇區(qū) or +size{K,M,G} (2048-20971519,默認(rèn)為 20971519):+1G
75. 分區(qū) 1 已設(shè)置為 Linux 類型,大小設(shè)為 1 GiB
76. 命令(輸入 m 獲取幫助):t
77. 已選擇分區(qū) 1
78. Hex 代碼(輸入 L 列出所有代碼):8e
79. 已將分區(qū)“Linux”的類型更改為“Linux LVM”
80. 命令(輸入 m 獲取幫助):p
81. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
82. Units = 扇區(qū) of 1 * 512 = 512 bytes
83. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
84. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
85. 磁盤標(biāo)簽類型:dos
86. 磁盤標(biāo)識符:0xc29f4c6d
87. 設(shè)備 Boot Start End Blocks Id System
88. /dev/sdb1 2048 2099199 1048576 8e Linux LVM
89. 命令(輸入 m 獲取幫助):n
90. Partition type:
91. p primary (1 primary, 0 extended, 3 free)
92. e extended
93. Select (default p): p
94. 分區(qū)號 (2-4,默認(rèn) 2):
95. 起始 扇區(qū) (2099200-20971519,默認(rèn)為 2099200):
96. 將使用默認(rèn)值 2099200
97. Last 扇區(qū), +扇區(qū) or +size{K,M,G} (2099200-20971519,默認(rèn)為 20971519):+1G
98. 分區(qū) 2 已設(shè)置為 Linux 類型,大小設(shè)為 1 GiB
99. 命令(輸入 m 獲取幫助):t
100. 分區(qū)號 (1,2,默認(rèn) 2):8e
101. 分區(qū)號 (1,2,默認(rèn) 2):2
102. Hex 代碼(輸入 L 列出所有代碼):8e
103. 已將分區(qū)“Linux”的類型更改為“Linux LVM”
104. 命令(輸入 m 獲取幫助):p
105. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
106. Units = 扇區(qū) of 1 * 512 = 512 bytes
107. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
108. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
109. 磁盤標(biāo)簽類型:dos
110. 磁盤標(biāo)識符:0xc29f4c6d
111. 設(shè)備 Boot Start End Blocks Id System
112. /dev/sdb1 2048 2099199 1048576 8e Linux LVM
113. /dev/sdb2 2099200 4196351 1048576 8e Linux LVM
114. 命令(輸入 m 獲取幫助):n
115. Partition type:
116. p primary (2 primary, 0 extended, 2 free)
117. e extended
118. Select (default p): p
119. 分區(qū)號 (3,4,默認(rèn) 3):
120. 起始 扇區(qū) (4196352-20971519,默認(rèn)為 4196352):
121. 將使用默認(rèn)值 4196352
122. Last 扇區(qū), +扇區(qū) or +size{K,M,G} (4196352-20971519,默認(rèn)為 20971519):+1G
123. 分區(qū) 3 已設(shè)置為 Linux 類型,大小設(shè)為 1 GiB
124. 命令(輸入 m 獲取幫助):t
125. 分區(qū)號 (1-3,默認(rèn) 3):3
126. Hex 代碼(輸入 L 列出所有代碼):8e
127. 已將分區(qū)“Linux”的類型更改為“Linux LVM”
128. 命令(輸入 m 獲取幫助):p
129. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
130. Units = 扇區(qū) of 1 * 512 = 512 bytes
131. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
132. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
133. 磁盤標(biāo)簽類型:dos
134. 磁盤標(biāo)識符:0xc29f4c6d
135. 設(shè)備 Boot Start End Blocks Id System
136. /dev/sdb1 2048 2099199 1048576 8e Linux LVM
137. /dev/sdb2 2099200 4196351 1048576 8e Linux LVM
138. /dev/sdb3 4196352 6293503 1048576 8e Linux LVM
139. 命令(輸入 m 獲取幫助):p
140. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
141. Units = 扇區(qū) of 1 * 512 = 512 bytes
142. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
143. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
144. 磁盤標(biāo)簽類型:dos
145. 磁盤標(biāo)識符:0xc29f4c6d
146. 設(shè)備 Boot Start End Blocks Id System
147. /dev/sdb1 2048 2099199 1048576 8e Linux LVM
148. /dev/sdb2 2099200 4196351 1048576 8e Linux LVM
149. /dev/sdb3 4196352 6293503 1048576 8e Linux LVM
150. 命令(輸入 m 獲取幫助):w
151. The partition table has been altered!
152. Calling ioctl() to re-read partition table.
153. WARNING: Re-reading the partition table failed with error 16: 設(shè)備或資源忙.
154. The kernel still uses the old table. The new table will be used at
155. the next reboot or after you run partprobe(8) or kpartx(8)
156. 正在同步磁盤。
157. [root@centos7-01 ~]# fdisk -l
158. 磁盤 /dev/sdb:10.7 GB, 10737418240 字節(jié),20971520 個扇區(qū)
159. Units = 扇區(qū) of 1 * 512 = 512 bytes
160. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
161. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
162. 磁盤標(biāo)簽類型:dos
163. 磁盤標(biāo)識符:0xc29f4c6d
164. 設(shè)備 Boot Start End Blocks Id System
165. /dev/sdb1 2048 2099199 1048576 8e Linux LVM
166. /dev/sdb2 2099200 4196351 1048576 8e Linux LVM
167. /dev/sdb3 4196352 6293503 1048576 8e Linux LVM
168. 磁盤 /dev/sda:32.2 GB, 32212254720 字節(jié),62914560 個扇區(qū)
169. Units = 扇區(qū) of 1 * 512 = 512 bytes
170. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
171. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
172. 磁盤標(biāo)簽類型:dos
173. 磁盤標(biāo)識符:0x000ee6f4
174. 設(shè)備 Boot Start End Blocks Id System
175. /dev/sda1 * 2048 411647 204800 83 Linux
176. /dev/sda2 411648 62914559 31251456 8e Linux LVM
177. 磁盤 /dev/mapper/cl-root:29.9 GB, 29850861568 字節(jié),58302464 個扇區(qū)
178. Units = 扇區(qū) of 1 * 512 = 512 bytes
179. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
180. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
181. 磁盤 /dev/mapper/cl-swap:2147 MB, 2147483648 字節(jié),4194304 個扇區(qū)
182. Units = 扇區(qū) of 1 * 512 = 512 bytes
183. 扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
184. I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
- 準(zhǔn)備物理卷
- pvcreate,pvcreate /dev/sdb1報錯,需要運行partprobe即可
1. [root@centos7-01 ~]# pvcreate /dev/sdb1
2. Device /dev/sdb1 not found (or ignored by filtering)
1. [root@centos7-01 ~]# pvcreate /dev/sdb1
2. Device /dev/sdb1 not found (or ignored by filtering).
3. [root@centos7-01 ~]# partprobe
4. [root@centos7-01 ~]# ls /dev/sdb1
5. /dev/sdb1
- 再pvcreate /dev/sdb1報錯,因為sdb已經(jīng)掛載,需要卸載
- 完成之后運行pvs或者pvdisplay都可以查看
1. [root@centos7-01 ~]# pvcreate /dev/sdb1
2. Can't open /dev/sdb1 exclusively. Mounted filesystem?
3. [root@centos7-01 ~]# umount /mnt/
4. [root@centos7-01 ~]# !p
5. pvcreate /dev/sdb1
6. WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
7. Wiping ext4 signature on /dev/sdb1.
8. Physical volume "/dev/sdb1" successfully created.
9. [root@centos7-01 ~]# pvcreate /dev/sdb2
10. Physical volume "/dev/sdb2" successfully created.
11. [root@centos7-01 ~]# pvcreate /dev/sdb3
12. Physical volume "/dev/sdb3" successfully created.
13. [root@centos7-01 ~]# pvs
14. PV VG Fmt Attr PSize PFree
15. /dev/sda2 cl lvm2 a-- 29.80g 0
16. /dev/sdb1 lvm2 --- 1.00g 1.00g
17. /dev/sdb2 lvm2 --- 1.00g 1.00g
18. /dev/sdb3 lvm2 --- 1.00g 1.00g
19. [root@centos7-01 ~]# pvdisplay
20. --- Physical volume ---
21. PV Name /dev/sda2
22. VG Name cl
23. PV Size 29.80 GiB / not usable 3.00 MiB
24. Allocatable yes (but full)
25. PE Size 4.00 MiB
26. Total PE 7629
27. Free PE 0
28. Allocated PE 7629
29. PV UUID Rpf1Lw-oScG-iE7T-Y3S1-nGUD-UK17-s6kDL4
30.
31. "/dev/sdb1" is a new physical volume of "1.00 GiB"
32. --- NEW Physical volume ---
33. PV Name /dev/sdb1
34. VG Name
35. PV Size 1.00 GiB
36. Allocatable NO
37. PE Size 0
38. Total PE 0
39. Free PE 0
40. Allocated PE 0
41. PV UUID YnoAOr-1fRJ-iS4Q-tvXq-T61M-RKky-r1kx4O
42.
43. "/dev/sdb3" is a new physical volume of "1.00 GiB"
44. --- NEW Physical volume ---
45. PV Name /dev/sdb3
46. VG Name
47. PV Size 1.00 GiB
48. Allocatable NO
49. PE Size 0
50. Total PE 0
51. Free PE 0
52. Allocated PE 0
53. PV UUID f6dIQj-OckU-6xlW-2Sgu-zOKt-uer1-HtRCxb
54.
55. "/dev/sdb2" is a new physical volume of "1.00 GiB"
56. --- NEW Physical volume ---
57. PV Name /dev/sdb2
58. VG Name
59. PV Size 1.00 GiB
60. Allocatable NO
61. PE Size 0
62. Total PE 0
63. Free PE 0
64. Allocated PE 0
65. PV UUID TI7uxv-Evmj-usxp-NorV-92jm-M03k-JAPcY0
- 創(chuàng)建卷組,查看物理卷命令:pvs或者pvdisplay
- 創(chuàng)建物理卷:vgcreate vg1 /dev/sdb1 /dev/sdb2
1. [root@centos7-01 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2
2. Volume group "vg1" successfully created
3. [root@centos7-01 ~]# vgs
4. VG #PV #LV #SN Attr VSize VFree
5. cl 1 2 0 wz--n- 29.80g 0
6. vg1 2 0 0 wz--n- 1.99g 1.99g
7. [root@centos7-01 ~]# vgdisplay
8. --- Volume group ---
9. VG Name vg1
10. System ID
11. Format lvm2
12. Metadata Areas 2
13. Metadata Sequence No 1
14. VG Access read/write
15. VG Status resizable
16. MAX LV 0
17. Cur LV 0
18. Open LV 0
19. Max PV 0
20. Cur PV 2
21. Act PV 2
22. VG Size 1.99 GiB
23. PE Size 4.00 MiB
24. Total PE 510
25. Alloc PE / Size 0 / 0
26. Free PE / Size 510 / 1.99 GiB
27. VG UUID g7uLO2-oGi2-a8KL-SUlh-ifA2-XbwZ-Kay33W
28.
29. --- Volume group ---
30. VG Name cl
31. System ID
32. Format lvm2
33. Metadata Areas 1
34. Metadata Sequence No 3
35. VG Access read/write
36. VG Status resizable
37. MAX LV 0
38. Cur LV 2
39. Open LV 2
40. Max PV 0
41. Cur PV 1
42. Act PV 1
43. VG Size 29.80 GiB
44. PE Size 4.00 MiB
45. Total PE 7629
46. Alloc PE / Size 7629 / 29.80 GiB
47. Free PE / Size 0 / 0
48. VG UUID XI5UeN-2odJ-QNE2-I1lw-ymDK-ECG2-fesvl2
- vgremove刪除卷組命令
- 創(chuàng)建邏輯卷 lvcreate -L 100M -n lv1 vg1,參數(shù)-L指定大小,-n命名;
- lvs或者lvdisplay查看
1. [root@centos7-01 ~]# lvcreate -L 100M -n admin vg1
2. Logical volume "admin" created.
3. [root@centos7-01 ~]# lvs
4. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
5. root cl -wi-ao---- 27.80g
6. swap cl -wi-ao---- 2.00g
7. admin vg1 -wi-a----- 100.00m
8. [root@centos7-01 ~]# lvdisplay
9. --- Logical volume ---
10. LV Path /dev/vg1/admin
11. LV Name admin
12. VG Name vg1
13. LV UUID dksWSS-xFrp-NNGU-xCrd-FnN0-n0op-0gySKr
14. LV Write Access read/write
15. LV Creation host, time centos7-01, 2017-11-07 09:07:16 +0800
16. LV Status available
17. # open 0
18. LV Size 100.00 MiB
19. Current LE 25
20. Segments 1
21. Allocation inherit
22. Read ahead sectors auto
23. - currently set to 8192
24. Block device 253:2
25.
26. --- Logical volume ---
27. LV Path /dev/cl/swap
28. LV Name swap
29. VG Name cl
30. LV UUID fpBmdc-ZTaT-RIH7-4QcF-0K1T-P4SA-nLAXDs
31. LV Write Access read/write
32. LV Creation host, time localhost.localdomain, 2017-10-16 22:44:36 +0800
33. LV Status available
34. # open 2
35. LV Size 2.00 GiB
36. Current LE 512
37. Segments 1
38. Allocation inherit
39. Read ahead sectors auto
40. - currently set to 8192
41. Block device 253:1
42.
43. --- Logical volume ---
44. LV Path /dev/cl/root
45. LV Name root
46. VG Name cl
47. LV UUID pGdTnm-3Hgq-6Efq-zosa-2gK5-wsmA-6m2AvO
48. LV Write Access read/write
49. LV Creation host, time localhost.localdomain, 2017-10-16 22:44:36 +0800
50. LV Status available
51. # open 1
52. LV Size 27.80 GiB
53. Current LE 7117
54. Segments 1
55. Allocation inherit
56. Read ahead sectors auto
57. - currently set to 8192
58. Block device 253:0
- 格式化mkfs.ext4 /dev/vg1/admin
1. [root@centos7-01 ~]# mkfs.ext4 /dev/vg1/admin
2. mke2fs 1.42.9 (28-Dec-2013)
3. 文件系統(tǒng)標(biāo)簽=
4. OS type: Linux
5. 塊大小=1024 (log=0)
6. 分塊大小=1024 (log=0)
7. Stride=0 blocks, Stripe width=0 blocks
8. 25688 inodes, 102400 blocks
9. 5120 blocks (5.00%) reserved for the super user
10. 第一個數(shù)據(jù)塊=1
11. Maximum filesystem blocks=33685504
12. 13 block groups
13. 8192 blocks per group, 8192 fragments per group
14. 1976 inodes per group
15. Superblock backups stored on blocks:
16. 8193, 24577, 40961, 57345, 73729
17. Allocating group tables: 完成
18. 正在寫入inode表: 完成
19. Creating journal (4096 blocks): 完成
20. Writing superblocks and filesystem accounting information: 完成
- 掛載到mnt下,mount /dev/vg1/admin /mnt/
1. [root@centos7-01 ~]# mount /dev/vg1/admin /mnt/
2. [root@centos7-01 ~]# df -h
3. 文件系統(tǒng) 容量 已用 可用 已用% 掛載點
4. /dev/mapper/cl-root 28G 1.2G 27G 5% /
5. devtmpfs 478M 0 478M 0% /dev
6. tmpfs 489M 0 489M 0% /dev/shm
7. tmpfs 489M 6.8M 482M 2% /run
8. tmpfs 489M 0 489M 0% /sys/fs/cgroup
9. /dev/sda1 197M 117M 81M 60% /boot
10. tmpfs 98M 0 98M 0% /run/user/0
11. /dev/mapper/vg1-admin 93M 1.6M 85M 2% /mnt
12. [root@centos7-01 ~]# ls -l /dev/vg1/admin
13. lrwxrwxrwx. 1 root root 7 11月 7 09:09 /dev/vg1/liyang -> ../dm-2
- 擴容邏輯卷,先umount /mnt/
- 執(zhí)行l(wèi)vresize -L 200M /dev/vg1/admin
- 檢測磁盤錯誤:e2fsck -f /dev/vg1/admin
- 更新邏輯卷信息:resize2fs /dev/vg1/lv1
- 再掛載到mnt下
- 以上操作都是針對ext4
1. [root@centos7-01 ~]# umount /mnt/
2. [root@centos7-01 ~]# lvresize -L 200M /dev/vg1/admin
3. Size of logical volume vg1/admin changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
4. Logical volume vg1/admin successfully resized.
5. [root@centos7-01 ~]# e2fsck -f /dev/vg1/admin
6. e2fsck 1.42.9 (28-Dec-2013)
7. 第一步: 檢查inode,塊,和大小
8. 第二步: 檢查目錄結(jié)構(gòu)
9. 第3步: 檢查目錄連接性
10. Pass 4: Checking reference counts
11. 第5步: 檢查簇概要信息
12. /dev/vg1/admin: 13/25688 files (7.7% non-contiguous), 8899/102400 blocks
13. [root@centos7-01 ~]# resize2fs /dev/vg1/admin
14. resize2fs 1.42.9 (28-Dec-2013)
15. Resizing the filesystem on /dev/vg1/admin to 204800 (1k) blocks.
16. The filesystem on /dev/vg1/admin is now 204800 blocks long.
17. [root@centos7-01 ~]# mount /dev/vg1/admin /mnt/
18. [root@centos7-01 ~]# df -h
19. 文件系統(tǒng) 容量 已用 可用 已用% 掛載點
20. /dev/mapper/cl-root 28G 1.2G 27G 5% /
21. devtmpfs 478M 0 478M 0% /dev
22. tmpfs 489M 0 489M 0% /dev/shm
23. tmpfs 489M 6.8M 482M 2% /run
24. tmpfs 489M 0 489M 0% /sys/fs/cgroup
25. /dev/sda1 197M 117M 81M 60% /boot
26. tmpfs 98M 0 98M 0% /run/user/0
27. /dev/mapper/vg1-admin 190M 1.6M 175M 1% /mnt
- 縮容邏輯卷(此方法xfs不支持)
- 先umount
- e2fsck -f /dev/vg1/admin檢查磁盤錯誤(ext)
- resize2fs /dev/vg1/admin 100M更新邏輯卷信息(ext)
- resize -L 100M /dev/vg1/lv1重新設(shè)置卷大小
1. [root@centos7-01 ~]# e2fsck -f /dev/vg1/admin
2. e2fsck 1.42.9 (28-Dec-2013)
3. 第一步: 檢查inode,塊,和大小
4. 第二步: 檢查目錄結(jié)構(gòu)
5. 第3步: 檢查目錄連接性
6. Pass 4: Checking reference counts
7. 第5步: 檢查簇概要信息
8. /dev/vg1/admin: 13/49400 files (7.7% non-contiguous), 11887/204800 blocks
9. [root@centos7-01 ~]# resize2fs /dev/vg1/admin 100M
10. resize2fs 1.42.9 (28-Dec-2013)
11. Resizing the filesystem on /dev/vg1/admin to 102400 (1k) blocks.
12. The filesystem on /dev/vg1/admin is now 102400 blocks long.
13. [root@centos7-01 ~]# lvresize -L 100M /dev/vg1/admin
14. WARNING: Reducing active logical volume to 100.00 MiB.
15. THIS MAY DESTROY YOUR DATA (filesystem etc.)
16. Do you really want to reduce vg1/admin? [y/n]: y
17. Size of logical volume vg1/admin changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).
18. Logical volume vg1/admin successfully resized.
19. [root@centos7-01 ~]# mount /dev/vg1/admin /mnt/
20. [root@centos7-01 ~]# lvs
21. LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
22. root cl -wi-ao---- 27.80g
23. swap cl -wi-ao---- 2.00g
24. admin vg1 -wi-ao---- 100.00m
- xfs擴容縮容
- 先卸載/mnt/
- 重新格式化mkfs.xfs -f /dev/vg1/admin
- 掛載(xfs擴容不需要卸載)
- 擴容,lvresize -L 300M /dev/vg1/admin
- xfs_growfs /dev/vg1/admin 更新擴容
1. [root@centos7-01 ~]# !umount
2. umount /mnt/
3. [root@centos7-01 ~]# mkfs.xfs -f /dev/vg1/admin
4. meta-data=/dev/vg1/admin isize=512 agcount=4, agsize=6400 blks
5. = sectsz=512 attr=2, projid32bit=1
6. = crc=1 finobt=0, sparse=0
7. data = bsize=4096 blocks=25600, imaxpct=25
8. = sunit=0 swidth=0 blks
9. naming =version 2 bsize=4096 ascii-ci=0 ftype=1
10. log =internal log bsize=4096 blocks=855, version=2
11. = sectsz=512 sunit=0 blks, lazy-count=1
12. realtime =none extsz=4096 blocks=0, rtextents=0
13. [root@centos7-01 ~]# !mount
14. mount /dev/vg1/admin /mnt/
15. [root@centos7-01 ~]# lvresize -L 310M /dev/vg1/admin
16. Rounding size to boundary between physical extents: 312.00 MiB.
17. Size of logical volume vg1/admin changed from 100.00 MiB (25 extents) to 312.00 MiB (78 extents).
18. Logical volume vg1/admin successfully resized.
19. [root@centos7-01 ~]# xfs_growfs /dev/vg1/admin
20. meta-data=/dev/mapper/vg1-admin isize=512 agcount=4, agsize=6400 blks
21. = sectsz=512 attr=2, projid32bit=1
22. = crc=1 finobt=0 spinodes=0
23. data = bsize=4096 blocks=25600, imaxpct=25
24. = sunit=0 swidth=0 blks
25. naming =version 2 bsize=4096 ascii-ci=0 ftype=1
26. log =internal bsize=4096 blocks=855, version=2
27. = sectsz=512 sunit=0 blks, lazy-count=1
28. realtime =none extsz=4096 blocks=0, rtextents=0
29. data blocks changed from 25600 to 79872
30. [root@centos7-01 ~]# df -h
31. 文件系統(tǒng) 容量 已用 可用 已用% 掛載點
32. /dev/mapper/cl-root 28G 1.2G 27G 5% /
33. devtmpfs 478M 0 478M 0% /dev
34. tmpfs 489M 0 489M 0% /dev/shm
35. tmpfs 489M 6.7M 482M 2% /run
36. tmpfs 489M 0 489M 0% /sys/fs/cgroup
37. /dev/sda1 197M 117M 81M 60% /boot
38. tmpfs 98M 0 98M 0% /run/user/0
39. /dev/mapper/vg1-admin 309M 5.5M 304M 2% /mnt
- 重新格式化mkfs.xfs -f /dev/vg1/admin
- 掛載(xfs擴容不需要卸載)
- 擴容,lvresize -L 300M /dev/vg1/admin
- xfs_growfs /dev/vg1/admin 更新擴容
- 擴展卷組,邏輯卷消耗結(jié)束后需要個卷組擴容;
- fdisk /dev/sdb 新增/dev/sdb5(邏輯分區(qū)8e)2G
- pvcreate /dev/sdb5
- xgextend vg1 /dev/sdb5
- lvresize -L 100M /dev/vg1/lv1 重新設(shè)置卷大小
1. [root@centos7-01 ~]# vgextend vg1 /dev/sdb3
2. Volume group "vg1" successfully extended
3. [root@centos7-01 ~]# lvresize -L 500M /dev/vg1/admin
4. Size of logical volume vg1/admin changed from 312.00 MiB (78 extents) to 500.00 MiB (125 extents).
5. Logical volume vg1/admin successfully resized.
6. [root@centos7-01 ~]# vgs
7. VG #PV #LV #SN Attr VSize VFree
8. cl 1 2 0 wz--n- 29.80g 0
9. vg1 3 1 0 wz--n- 2.99g 2.50g
10. [root@centos7-01 ~]# vgdisplay
11. --- Volume group ---
12. VG Name cl
13. System ID
14. Format lvm2
15. Metadata Areas 1
16. Metadata Sequence No 3
17. VG Access read/write
18. VG Status resizable
19. MAX LV 0
20. Cur LV 2
21. Open LV 2
22. Max PV 0
23. Cur PV 1
24. Act PV 1
25. VG Size 29.80 GiB
26. PE Size 4.00 MiB
27. Total PE 7629
28. Alloc PE / Size 7629 / 29.80 GiB
29. Free PE / Size 0 / 0
30. VG UUID XI5UeN-2odJ-QNE2-I1lw-ymDK-ECG2-fesvl2
31.
32. --- Volume group ---
33. VG Name vg1
34. System ID
35. Format lvm2
36. Metadata Areas 3
37. Metadata Sequence No 7
38. VG Access read/write
39. VG Status resizable
40. MAX LV 0
41. Cur LV 1
42. Open LV 1
43. Max PV 0
44. Cur PV 3
45. Act PV 3
46. VG Size 2.99 GiB
47. PE Size 4.00 MiB
48. Total PE 765
49. Alloc PE / Size 125 / 500.00 MiB
50. Free PE / Size 640 / 2.50 GiB
51. VG UUID BlMKNZ-KBxm-u2Zp-Xq6Z-94qt-yIeG-am7Seh
52. [root@centos7-01 ~]# xfs_growfs /dev/vg1/admin
53. meta-data=/dev/mapper/vg1-admin isize=512 agcount=13, agsize=6400 blks
54. = sectsz=512 attr=2, projid32bit=1
55. = crc=1 finobt=0 spinodes=0
56. data = bsize=4096 blocks=79872, imaxpct=25
57. = sunit=0 swidth=0 blks
58. naming =version 2 bsize=4096 ascii-ci=0 ftype=1
59. log =internal bsize=4096 blocks=855, version=2
60. = sectsz=512 sunit=0 blks, lazy-count=1
61. realtime =none extsz=4096 blocks=0, rtextents=0
62. data blocks changed from 79872 to 128000
63. [root@centos7-01 ~]# df -h
64. 文件系統(tǒng) 容量 已用 可用 已用% 掛載點
65. /dev/mapper/cl-root 28G 1.2G 27G 5% /
66. devtmpfs 478M 0 478M 0% /dev
67. tmpfs 489M 0 489M 0% /dev/shm
68. tmpfs 489M 6.7M 482M 2% /run
69. tmpfs 489M 0 489M 0% /sys/fs/cgroup
70. /dev/sda1 197M 117M 81M 60% /boot
71. tmpfs 98M 0 98M 0% /run/user/0
72. /dev/mapper/vg1-admin 497M 5.7M 491M 2% /mnt
二、磁盤故障小案例
- 問題:etc/fstab下面添加配置后,重啟進入不了系統(tǒng);
- 分析:磁盤掛載問題;
- 輸入root密碼進入,vi/etc/fatab
1. # /etc/fstab
2. # Created by anaconda on Mon Oct 16 22:44:37 2017
3. #
4. # Accessible filesystems, by reference, are maintained under '/dev/disk'
5. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
6. #
7. /dev/mapper/cl-root / xfs defaults 0 0
8. UUID=4c1ae631-2b19-464d-b226-1da717f58b96 /boot xfs defaults 0 0
9. /dev/mapper/cl-swap swap swap defaults 0 0
10. /dev/sdb /mnt xfs defaults 0 0
- 把最后一行注釋掉或者刪除(前面加#注釋,dd刪除整行),保存退出;重啟即可;