Linux磁盘管理

4.10、LVM讲解(上)

  • LVM有一定的局限性;数据恢复困难

  • 物理分区==>物理卷==>卷组==>逻辑卷

  • 准备磁盘分区

  1. fdisk /dev/sdb
  2. n创建三个新分区,分别1G
  3. t改变分区类型为8e
  • 操作


	1. [root@centos7-01 ~]# fdisk -l
	2. 磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
	3. Units = 扇区 of 1 * 512 = 512 bytes
	4. 扇区大小(逻辑/物理):512 字节 / 512 字节
	5. I/O 大小(最小/最佳):512 字节 / 512 字节
	6. 磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
	7. Units = 扇区 of 1 * 512 = 512 bytes
	8. 扇区大小(逻辑/物理):512 字节 / 512 字节
	9. I/O 大小(最小/最佳):512 字节 / 512 字节
	10. 磁盘标签类型:dos
	11. 磁盘标识符:0x000ee6f4
	12.    设备 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 字节,58302464 个扇区
	16. Units = 扇区 of 1 * 512 = 512 bytes
	17. 扇区大小(逻辑/物理):512 字节 / 512 字节
	18. I/O 大小(最小/最佳):512 字节 / 512 字节
	19. 磁盘 /dev/mapper/cl-swap:2147 MB, 2147483648 字节,4194304 个扇区
	20. Units = 扇区 of 1 * 512 = 512 bytes
	21. 扇区大小(逻辑/物理):512 字节 / 512 字节
	22. I/O 大小(最小/最佳):512 字节 / 512 字节
	23. [root@centos7-01 ~]#
	24. [root@centos7-01 ~]# fdisk /dev/sdb
	25. 欢迎使用 fdisk (util-linux 2.23.2)。
	26. 更改将停留在内存中,直到您决定将更改写入磁盘。
	27. 使用写入命令前请三思。
	28. Device does not contain a recognized partition table
	29. 使用磁盘标识符 0xc29f4c6d 创建新的 DOS 磁盘标签。
	30. 命令(输入 m 获取帮助):p
	31. 磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
	32. Units = 扇区 of 1 * 512 = 512 bytes
	33. 扇区大小(逻辑/物理):512 字节 / 512 字节
	34. I/O 大小(最小/最佳):512 字节 / 512 字节
	35. 磁盘标签类型:dos
	36. 磁盘标识符:0xc29f4c6d
	37.    设备 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 字节,20971520 个扇区
	60. Units = 扇区 of 1 * 512 = 512 bytes
	61. 扇区大小(逻辑/物理):512 字节 / 512 字节
	62. I/O 大小(最小/最佳):512 字节 / 512 字节
	63. 磁盘标签类型:dos
	64. 磁盘标识符:0xc29f4c6d
	65.    设备 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. 分区号 (1-4,默认 1):
	72. 起始 扇区 (2048-20971519,默认为 2048):
	73. 将使用默认值 2048
	74. Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519):+1G
	75. 分区 1 已设置为 Linux 类型,大小设为 1 GiB
	76. 命令(输入 m 获取帮助):t
	77. 已选择分区 1
	78. Hex 代码(输入 L 列出所有代码):8e
	79. 已将分区“Linux”的类型更改为“Linux LVM”
	80. 命令(输入 m 获取帮助):p
	81. 磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
	82. Units = 扇区 of 1 * 512 = 512 bytes
	83. 扇区大小(逻辑/物理):512 字节 / 512 字节
	84. I/O 大小(最小/最佳):512 字节 / 512 字节
	85. 磁盘标签类型:dos
	86. 磁盘标识符:0xc29f4c6d
	87.    设备 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. 分区号 (2-4,默认 2):
	95. 起始 扇区 (2099200-20971519,默认为 2099200):
	96. 将使用默认值 2099200
	97. Last 扇区, +扇区 or +size{K,M,G} (2099200-20971519,默认为 20971519):+1G
	98. 分区 2 已设置为 Linux 类型,大小设为 1 GiB
	99. 命令(输入 m 获取帮助):t
	100. 分区号 (1,2,默认 2):8e
	101. 分区号 (1,2,默认 2):2
	102. Hex 代码(输入 L 列出所有代码):8e   
	103. 已将分区“Linux”的类型更改为“Linux LVM”
	104. 命令(输入 m 获取帮助):p
	105. 磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
	106. Units = 扇区 of 1 * 512 = 512 bytes
	107. 扇区大小(逻辑/物理):512 字节 / 512 字节
	108. I/O 大小(最小/最佳):512 字节 / 512 字节
	109. 磁盘标签类型:dos
	110. 磁盘标识符:0xc29f4c6d
	111.    设备 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. 分区号 (3,4,默认 3):
	120. 起始 扇区 (4196352-20971519,默认为 4196352):
	121. 将使用默认值 4196352
	122. Last 扇区, +扇区 or +size{K,M,G} (4196352-20971519,默认为 20971519):+1G
	123. 分区 3 已设置为 Linux 类型,大小设为 1 GiB
	124. 命令(输入 m 获取帮助):t
	125. 分区号 (1-3,默认 3):3
	126. Hex 代码(输入 L 列出所有代码):8e
	127. 已将分区“Linux”的类型更改为“Linux LVM”
	128. 命令(输入 m 获取帮助):p   
	129. 磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
	130. Units = 扇区 of 1 * 512 = 512 bytes
	131. 扇区大小(逻辑/物理):512 字节 / 512 字节
	132. I/O 大小(最小/最佳):512 字节 / 512 字节
	133. 磁盘标签类型:dos
	134. 磁盘标识符:0xc29f4c6d
	135.    设备 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 字节,20971520 个扇区
	141. Units = 扇区 of 1 * 512 = 512 bytes
	142. 扇区大小(逻辑/物理):512 字节 / 512 字节
	143. I/O 大小(最小/最佳):512 字节 / 512 字节
	144. 磁盘标签类型:dos
	145. 磁盘标识符:0xc29f4c6d
	146.    设备 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: 设备或资源忙.
	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 字节,20971520 个扇区
	159. Units = 扇区 of 1 * 512 = 512 bytes
	160. 扇区大小(逻辑/物理):512 字节 / 512 字节
	161. I/O 大小(最小/最佳):512 字节 / 512 字节
	162. 磁盘标签类型:dos
	163. 磁盘标识符:0xc29f4c6d
	164.    设备 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 字节,62914560 个扇区
	169. Units = 扇区 of 1 * 512 = 512 bytes
	170. 扇区大小(逻辑/物理):512 字节 / 512 字节
	171. I/O 大小(最小/最佳):512 字节 / 512 字节
	172. 磁盘标签类型:dos
	173. 磁盘标识符:0x000ee6f4
	174.    设备 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 字节,58302464 个扇区
	178. Units = 扇区 of 1 * 512 = 512 bytes
	179. 扇区大小(逻辑/物理):512 字节 / 512 字节
	180. I/O 大小(最小/最佳):512 字节 / 512 字节
	181. 磁盘 /dev/mapper/cl-swap:2147 MB, 2147483648 字节,4194304 个扇区
	182. Units = 扇区 of 1 * 512 = 512 bytes
	183. 扇区大小(逻辑/物理):512 字节 / 512 字节
	184. I/O 大小(最小/最佳):512 字节 / 512 字节


  • 准备物理卷
  • 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已经挂载,需要卸载
  • 完成之后运行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


4.11、LVM讲解(中)

  • 创建卷组,查看物理卷命令:pvs或者pvdisplay
  • 创建物理卷: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删除卷组命令
  • 创建逻辑卷 lvcreate -L 100M -n lv1 vg1,参数-L指定大小,-n命名;
  • lvs或者lvdisplay查看

	1. [root@centos7-01 ~]# lvcreate -L 100M -n liyang vg1
	2.   Logical volume "liyang" 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.   liyang vg1 -wi-a----- 100.00m                                                    
	8. [root@centos7-01 ~]# lvdisplay
	9.   --- Logical volume ---
	10.   LV Path                /dev/vg1/liyang
	11.   LV Name                liyang
	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/liyang

	1. [root@centos7-01 ~]# mkfs.ext4 /dev/vg1/liyang
	2. mke2fs 1.42.9 (28-Dec-2013)
	3. 文件系统标签=
	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. 第一个数据块=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/liyang /mnt/

	1. [root@centos7-01 ~]# mount /dev/vg1/liyang /mnt/
	2. [root@centos7-01 ~]# df -h
	3. 文件系统                容量  已用  可用 已用% 挂载点
	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-liyang   93M  1.6M   85M    2% /mnt
	12. [root@centos7-01 ~]# ls -l /dev/vg1/liyang
	13. lrwxrwxrwx. 1 root root 7 11月  7 09:09 /dev/vg1/liyang -> ../dm-2


  • 扩容逻辑卷,先umount /mnt/
  • 执行lvresize -L 200M /dev/vg1/liyang
  • 检测磁盘错误:e2fsck -f /dev/vg1/liyang
  • 更新逻辑卷信息:resize2fs /dev/vg1/lv1
  • 再挂载到mnt下
  • 以上操作都是针对ext4

	1. [root@centos7-01 ~]# umount /mnt/
	2. [root@centos7-01 ~]# lvresize -L 200M /dev/vg1/liyang
	3.   Size of logical volume vg1/liyang changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
	4.   Logical volume vg1/liyang successfully resized.
	5. [root@centos7-01 ~]# e2fsck -f /dev/vg1/liyang
	6. e2fsck 1.42.9 (28-Dec-2013)
	7. 第一步: 检查inode,块,和大小
	8. 第二步: 检查目录结构
	9. 第3步: 检查目录连接性
	10. Pass 4: Checking reference counts
	11. 第5步: 检查簇概要信息
	12. /dev/vg1/liyang: 13/25688 files (7.7% non-contiguous), 8899/102400 blocks
	13. [root@centos7-01 ~]# resize2fs /dev/vg1/liyang
	14. resize2fs 1.42.9 (28-Dec-2013)
	15. Resizing the filesystem on /dev/vg1/liyang to 204800 (1k) blocks.
	16. The filesystem on /dev/vg1/liyang is now 204800 blocks long.
	17. [root@centos7-01 ~]# mount /dev/vg1/liyang /mnt/
	18. [root@centos7-01 ~]# df -h
	19. 文件系统                容量  已用  可用 已用% 挂载点
	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-liyang  190M  1.6M  175M    1% /mnt


  • 缩容逻辑卷(此方法xfs不支持)
  • 先umount
  • e2fsck -f /dev/vg1/liyang检查磁盘错误(ext)
  • resize2fs /dev/vg1/liyang 100M更新逻辑卷信息(ext)
  • resize -L 100M /dev/vg1/lv1重新设置卷大小

	1. [root@centos7-01 ~]# e2fsck -f /dev/vg1/liyang
	2. e2fsck 1.42.9 (28-Dec-2013)
	3. 第一步: 检查inode,块,和大小
	4. 第二步: 检查目录结构
	5. 第3步: 检查目录连接性
	6. Pass 4: Checking reference counts
	7. 第5步: 检查簇概要信息
	8. /dev/vg1/liyang: 13/49400 files (7.7% non-contiguous), 11887/204800 blocks
	9. [root@centos7-01 ~]# resize2fs /dev/vg1/liyang 100M
	10. resize2fs 1.42.9 (28-Dec-2013)
	11. Resizing the filesystem on /dev/vg1/liyang to 102400 (1k) blocks.
	12. The filesystem on /dev/vg1/liyang is now 102400 blocks long.
	13. [root@centos7-01 ~]# lvresize -L 100M /dev/vg1/liyang
	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/liyang? [y/n]: y
	17.   Size of logical volume vg1/liyang changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).
	18.   Logical volume vg1/liyang successfully resized.
	19. [root@centos7-01 ~]# mount /dev/vg1/liyang /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.   liyang vg1 -wi-ao---- 100.00m


  • xfs扩容缩容
  • 先卸载/mnt/
  • 重新格式化mkfs.xfs -f /dev/vg1/liyang
  • 挂载(xfs扩容不需要卸载)
  • 扩容,lvresize -L 300M /dev/vg1/liyang
  • xfs_growfs /dev/vg1/liyang 更新扩容

	1. [root@centos7-01 ~]# !umount
	2. umount /mnt/
	3. [root@centos7-01 ~]# mkfs.xfs -f /dev/vg1/liyang
	4. meta-data=/dev/vg1/liyang        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/liyang /mnt/
	15. [root@centos7-01 ~]# lvresize -L 310M /dev/vg1/liyang
	16.   Rounding size to boundary between physical extents: 312.00 MiB.
	17.   Size of logical volume vg1/liyang changed from 100.00 MiB (25 extents) to 312.00 MiB (78 extents).
	18.   Logical volume vg1/liyang successfully resized.
	19. [root@centos7-01 ~]# xfs_growfs /dev/vg1/liyang
	20. meta-data=/dev/mapper/vg1-liyang 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. 文件系统                容量  已用  可用 已用% 挂载点
	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-liyang  309M  5.5M  304M    2% /mnt


4.12、LVM讲解(下)

  • 重新格式化mkfs.xfs -f /dev/vg1/liyang
  • 挂载(xfs扩容不需要卸载)
  • 扩容,lvresize -L 300M /dev/vg1/liyang
  • xfs_growfs /dev/vg1/liyang 更新扩容
  • 扩展卷组,逻辑卷消耗结束后需要个卷组扩容;
  • fdisk /dev/sdb 新增/dev/sdb5(逻辑分区8e)2G
  • pvcreate /dev/sdb5
  • xgextend vg1 /dev/sdb5
  • lvresize -L 100M /dev/vg1/lv1 重新设置卷大小

	1. [root@centos7-01 ~]# vgextend vg1 /dev/sdb3
	2.   Volume group "vg1" successfully extended
	3. [root@centos7-01 ~]# lvresize -L 500M /dev/vg1/liyang
	4.   Size of logical volume vg1/liyang changed from 312.00 MiB (78 extents) to 500.00 MiB (125 extents).
	5.   Logical volume vg1/liyang 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/liyang
	53. meta-data=/dev/mapper/vg1-liyang 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. 文件系统                容量  已用  可用 已用% 挂载点
	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-liyang  497M  5.7M  491M    2% /mnt


4.13、磁盘故障小案例

  • 问题:etc/fstab下面添加配置后,重启进入不了系统;
  • 分析:磁盘挂载问题;
  • 输入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删除整行),保存退出;重启即可;

转载于:https://my.oschina.net/u/3706694/blog/1563683

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值