1. 程式人生 > >lvm及磁盤故障案列

lvm及磁盤故障案列

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及磁盤故障案列