lvm及磁盘故障案列
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lvm及磁盘故障案列相关的知识,希望对你有一定的参考价值。
lvm讲解- 把磁盘/dev/sdb分为三个区,t可以指定类型,类型为LVM(id为8e)
设备 Boot Start End Blocks Id System /dev/sdb1 2048 2099199 1048576 8e Linux LVM /dev/sdb2 2099200 4196351 1048576 8e Linux LVM /dev/sdb3 4196352 6293503 1048576 8e Linux LVM
- 创建物理卷
用yum provides ”/*/pvcreate“命令查找lvm包,yum install -y lvm2安装
- 可以用partprobe命令生成/dev/sdb1文件
- 使用pvreate /dev/sdb1 命令分别创建三个物理卷
[[email protected] ~]# pvcreate /dev/sdb1 WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdb1. Physical volume “/dev/sdb1” successfully created. [[email protected] ~]# pvcreate /dev/sdb2 Physical volume ”/dev/sdb2“ successfully created. [[email protected] ~]# pvcreate /dev/sdb3 WARNING: dos signature detected on /dev/sdb3 at offset 510. Wipe it? [y/n]: y Wiping dos signature on /dev/sdb3. Physical volume “/dev/sdb3” successfully created.
- 使用pvdisplay查看系统中的物理卷
[[email protected] ~]# pvdisplay ”/dev/sdb1“ is a new physical volume of ”1.00 GiB“ --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 1.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID qrwO8j-8kOv-OfEh-bNed-9TcG-5Qyq-scRpyb “/dev/sdb2” is a new physical volume of “1.00 GiB” --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 1.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID hPPtFs-Dfmo-zrnZ-mYUA-41Sy-wgfy-Zz0M4P “/dev/sdb3” is a new physical volume of “1.00 GiB” --- NEW Physical volume --- PV Name /dev/sdb3 VG Name PV Size 1.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID HrV293-eP3T-YJTM-vakP-eKXR-ykLg-xoFq66
- pvs查看物理卷
[[email protected] ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 --- 1.00g 1.00g /dev/sdb2 lvm2 --- 1.00g 1.00g /dev/sdb3 lvm2 --- 1.00g 1.00g
- 创建卷组,vgcreate
[[email protected] ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 Volume group ”vg1“ successfully created
- vgdisplay和vgs查看卷组信息
[[email protected] ~]# vgdisplay --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 1.99 GiB PE Size 4.00 MiB Total PE 510 Alloc PE / Size 0 / 0 Free PE / Size 510 / 1.99 GiB VG UUID ufmtbK-zC4s-wsL2-mBEP-HlMy-Vg2Q-dPnkgV
[[email protected] ~]# vgs VG #PV #LV #SN Attr VSize VFree vg1 2 0 0 wz--n- 1.99g 1.99g [[email protected] ~]#
- vgremove删除卷组命令
- vgdisplay和vgs查看卷组信息
- 创建逻辑卷,lvcreate -L 100M -n lv1 vg1从vg1里面划分名为lv1,大小为100M的逻辑卷
[[email protected] ~]# lvcreate -L 100M -n lv1 vg1 Logical volume ”lv1“ created.
- 格式化,mkfs.ext4 /dev/vg1/lv1
- 挂载逻辑卷
[[email protected] ~]# mount /dev/vg1/lv1 /mnt/ [[email protected] ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/sda3 28G 1.2G 27G 5% / devtmpfs 483M 0 483M 0% /dev tmpfs 493M 0 493M 0% /dev/shm tmpfs 493M 6.8M 486M 2% /run tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/sda1 197M 109M 88M 56% /boot tmpfs 99M 0 99M 0% /run/user/0 /dev/mapper/vg1-lv1 93M 1.6M 85M 2% /mnt
- 扩容逻辑卷
- 先umount(xfs不能卸载)
- lvresize -L 200M /dev/vg1/lv1 重新设置卷大小
[[email protected] ~]# lvresize -L 200M /dev/vg1/lv1 Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents). Logical volume vg1/lv1 successfully resized.
- e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext4执行)
[[email protected] ~]# e2fsck -f /dev/vg1/lv1 e2fsck 1.42.9 (28-Dec-2013) 第一步: 检查inode,块,和大小 第二步: 检查目录结构 第3步: 检查目录连接性 Pass 4: Checking reference counts 第5步: 检查簇概要信息 /dev/vg1/lv1: 11/25688 files (9.1% non-contiguous), 8896/102400 blocks
- resize2fs /dev/vg1/lv1 更新逻辑卷信息(ext4执行)
[email protected] ~]# resize2fs /dev/vg1/lv1 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks. The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
- xfs_growfs /dev/vg1/lv1 xfs文件系统需要执行
- 缩减逻辑卷(xfs不支持)
- 先umount
- e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
- resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
- lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
- 扩容卷组
- fdisk /dev/sdb新增/dev/sdb3(8e)
- pvcreate /dev/sdb3创建物理卷
- vgextend vg1 /dev/sdb3加入卷组
- lvresize -L 500M /dev/vg1/lv1重新设置卷大小
硬盘故障案例
- 做完lvm进不了系统,由于磁盘挂载错误,磁盘不能正常挂载到挂载点
- 输入root密码可以进入,删除错误的挂载点,vim /etc/fstab删除最后一行
- 重启
以上是关于lvm及磁盘故障案列的主要内容,如果未能解决你的问题,请参考以下文章