码迷,mamicode.com
首页 > 其他好文 > 详细

lvm及磁盘故障案列

时间:2018-04-12 10:32:13      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:lvm

lvm讲解
  1. 把磁盘/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
  2. 创建物理卷

    用yum provides ”/*/pvcreate“命令查找lvm包,yum install -y lvm2安装

    • 可以用partprobe命令生成/dev/sdb1文件
    • 使用pvreate /dev/sdb1 命令分别创建三个物理卷
      [root@aminglinux-02 ~]# 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.
      [root@aminglinux-02 ~]# pvcreate /dev/sdb2
      Physical volume ”/dev/sdb2“ successfully created.
      [root@aminglinux-02 ~]# 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查看系统中的物理卷
      [root@aminglinux-02 ~]# 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查看物理卷
      [root@aminglinux-02 ~]# 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
  3. 创建卷组,vgcreate
    [root@aminglinux-02 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2
    Volume group ”vg1“ successfully created
    • vgdisplay和vgs查看卷组信息
      [root@aminglinux-02 ~]# 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
      [root@aminglinux-02 ~]# vgs
      VG  #PV #LV #SN Attr   VSize VFree
      vg1   2   0   0 wz--n- 1.99g 1.99g
      [root@aminglinux-02 ~]# 
    • vgremove删除卷组命令
  4. 创建逻辑卷,lvcreate -L 100M -n lv1 vg1从vg1里面划分名为lv1,大小为100M的逻辑卷
    [root@aminglinux-02 ~]# lvcreate -L 100M -n lv1 vg1
    Logical volume ”lv1“ created.
  5. 格式化,mkfs.ext4 /dev/vg1/lv1
  6. 挂载逻辑卷
    [root@aminglinux-02 ~]# mount /dev/vg1/lv1 /mnt/
    [root@aminglinux-02 ~]# 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
  7. 扩容逻辑卷
    • 先umount(xfs不能卸载)
    • lvresize -L 200M /dev/vg1/lv1 重新设置卷大小
      [root@aminglinux-02 ~]# 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执行)
      [root@aminglinux-02 ~]# 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执行)
      root@aminglinux-02 ~]# 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文件系统需要执行
  8. 缩减逻辑卷(xfs不支持)
    • 先umount
    • e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
    • resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
    • lvresize -L 100M /dev/vg1/lv1 重新设置卷大小
  9. 扩容卷组
    • 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及磁盘故障案列

标签:lvm

原文地址:http://blog.51cto.com/akui2521/2097224

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!