• Linux_9/ RAID & LVM


      RAID10 RAID5
    1 ls -l /dev/sd* ls -l /dev/sd*
    2 mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sd[b-e] mdadm -Cv /dev/md0 -a yes -n 3 -l 5 -x 1 /dev/sd[b-e]
    3 mdadm -D /dev/md0 mdadm -D /dev/md0
    4 mkfs.ext4 /dev/md0 mkfs.ext4 /dev/md0
    5 mount /dev/md0 /zhxu/Desktop/rd10/ mount /dev/md0 /root/Desktop/rd5/
    6 vim /etc/fstab vim /etc/fstab
    7 df -h df -h
    8 mdadm -D /dev/md0 mdadm -D /dev/md0
    9 mdadm /dev/md0 -f /dev/sde  
    10 mdadm /dev/md0 -r /dev/sde  
    11 mdadm -D /dev/md0  
    12 mdadm /dev/md0 -a /dev/sde  
    13 mdadm -D /dev/md0  

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    raid 10

    操作步骤:设置(mdadm, mkfs, mount),破坏(faulty,remove),修复(add)

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    0,编辑虚拟机,添加4块大小为20G的硬盘

    [root@localhost Desktop]# ls -l /dev/sd*
    brw-rw----. 1 root disk 8,  0 Nov 15  2018 /dev/sda
    brw-rw----. 1 root disk 8,  1 Nov 15  2018 /dev/sda1
    brw-rw----. 1 root disk 8,  2 Nov 15  2018 /dev/sda2
    brw-rw----. 1 root disk 8, 16 Nov 15  2018 /dev/sdb
    brw-rw----. 1 root disk 8, 32 Nov 15  2018 /dev/sdc
    brw-rw----. 1 root disk 8, 48 Nov 15  2018 /dev/sdd
    brw-rw----. 1 root disk 8, 64 Nov 15  2018 /dev/sde
    [root@localhost Desktop]#

    1, 设置raid

      mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sdb /dev/sdc /dev/sdd /dev/sde

    或者mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sd[b-e]

    mdadm: layout defaults to n2
    mdadm: layout defaults to n2
    mdadm: chunk size defaults to 512K
    mdadm: size set to 20954624K
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md0 started.

    2,检查raid信息

    [root@localhost Desktop]# mdadm -D /dev/md0
    /dev/md0:
            Version : 1.2
      Creation Time : Thu Nov 15 13:46:54 2018
         Raid Level : raid10
         Array Size : 41909248 (39.97 GiB 42.92 GB)
      Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
       Raid Devices : 4
      Total Devices : 4
        Persistence : Superblock is persistent

        Update Time : Thu Nov 15 13:46:54 2018
              State : clean, resyncing
     Active Devices : 4
    Working Devices : 4
     Failed Devices : 0
      Spare Devices : 0

             Layout : near=2
         Chunk Size : 512K

      Resync Status : 5% complete

               Name : localhost.localdomain:0  (local to host localhost.localdomain)
               UUID : debdbc4f:de8a7b45:2874151b:6d237059
             Events : 0

        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           2       8       48        2      active sync   /dev/sdd
           3       8       64        3      active sync   /dev/sde
    [root@localhost Desktop]#

    3,或者查看简要信息

    [root@localhost Desktop]# mdadm -Q /dev/md0
    /dev/md0: 39.97GiB raid10 4 devices, 0 spares. Use mdadm --detail for more detail.
    [root@localhost Desktop]#

    4,格式化

    [root@localhost Desktop]# mkfs.ext4 /dev/md0
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=128 blocks, Stripe width=256 blocks
    2621440 inodes, 10477312 blocks
    523865 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2157969408
    320 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   

    [root@localhost Desktop]#

    5,临时+编辑fstab文件,使其永久生效

    [root@localhost Desktop]# mkdir rd10
    [root@localhost Desktop]# ll rd10/
    total 16
    drwx------. 2 root root 16384 Nov 15 13:52 lost+found

    [root@localhost Desktop]# mount /dev/md0 /zhxu/Desktop/rd10/
    [root@localhost Desktop]# vim /etc/fstab
    添加行:

    /dev/md0                /home/zhxu/Desktop/rd10 ext4    defaults        0 0

    6,重启查看自动挂载信息

    [root@localhost Desktop]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root   18G  2.9G   15G  17% /
    devtmpfs               985M     0  985M   0% /dev
    tmpfs                  994M   84K  994M   1% /dev/shm
    tmpfs                  994M  8.9M  986M   1% /run
    tmpfs                  994M     0  994M   0% /sys/fs/cgroup
    /dev/md0                40G   49M   38G   1% /home/zhxu/Desktop/rd10
    /dev/sda1              497M  119M  379M  24% /boot
    /dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64
    [root@localhost Desktop]#

    假如某块硬盘坏掉(用人为去掉来模拟)

    7,查看

    [root@localhost Desktop]# mdadm -D /dev/md0
    /dev/md0:
            Version : 1.2
      Creation Time : Thu Nov 15 13:46:54 2018
         Raid Level : raid10
         Array Size : 41909248 (39.97 GiB 42.92 GB)
      Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
       Raid Devices : 4
      Total Devices : 4
        Persistence : Superblock is persistent

        Update Time : Thu Nov 15 14:03:40 2018
              State : clean, degraded
     Active Devices : 3
    Working Devices : 3
     Failed Devices : 1
      Spare Devices : 0

             Layout : near=2
         Chunk Size : 512K

               Name : localhost.localdomain:0  (local to host localhost.localdomain)
               UUID : debdbc4f:de8a7b45:2874151b:6d237059
             Events : 27

        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           2       8       48        2      active sync   /dev/sdd
           3       0        0        3      removed

           3       8       64        -      faulty   /dev/sde


    8,失败

    [root@localhost Desktop]# mdadm /dev/md0 -f /dev/sde
    mdadm: set /dev/sde faulty in /dev/md0

    9,移除

    [root@localhost Desktop]# mdadm -r /dev/md0  /dev/sde
    mdadm: hot removed /dev/sde from /dev/md0

    10,查看移除情况

    [root@localhost Desktop]# mdadm -D /dev/md0
    /dev/md0:
            Version : 1.2
      Creation Time : Thu Nov 15 13:46:54 2018
         Raid Level : raid10
         Array Size : 41909248 (39.97 GiB 42.92 GB)
      Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
       Raid Devices : 4
      Total Devices : 3
        Persistence : Superblock is persistent

        Update Time : Thu Nov 15 14:08:56 2018
              State : clean, degraded
     Active Devices : 3
    Working Devices : 3
     Failed Devices : 0
      Spare Devices : 0

             Layout : near=2
         Chunk Size : 512K

               Name : localhost.localdomain:0  (local to host localhost.localdomain)
               UUID : debdbc4f:de8a7b45:2874151b:6d237059
             Events : 30

        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           2       8       48        2      active sync   /dev/sdd
           3       0        0        3      removed
    [root@localhost Desktop]#

    此时修复好硬盘(人为添加来模拟)

    11,

    [root@localhost Desktop]# ls /dev/sd*
    /dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdc  /dev/sdd  /dev/sde

    12,添加回去,并重新查看

    [root@localhost Desktop]# mdadm /dev/md0 -a /dev/sde
    mdadm: added /dev/sde
    [root@localhost Desktop]# mdadm -D /dev/md0
    /dev/md0:
            Version : 1.2
      Creation Time : Thu Nov 15 13:46:54 2018
         Raid Level : raid10
         Array Size : 41909248 (39.97 GiB 42.92 GB)
      Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
       Raid Devices : 4
      Total Devices : 4
        Persistence : Superblock is persistent

        Update Time : Thu Nov 15 14:12:17 2018
              State : clean, degraded, recovering
     Active Devices : 3
    Working Devices : 4
     Failed Devices : 0
      Spare Devices : 1

             Layout : near=2
         Chunk Size : 512K

     Rebuild Status : 18% complete

               Name : localhost.localdomain:0  (local to host localhost.localdomain)
               UUID : debdbc4f:de8a7b45:2874151b:6d237059
             Events : 36

        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           2       8       48        2      active sync   /dev/sdd
           4       8       64        3      spare rebuilding   /dev/sde
    [root@localhost Desktop]#

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    radi 5 + 备份盘

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    0,在虚拟机设置中添加4块新硬盘,大小20G,3块做raid5,一块备份。

    [root@localhost Desktop]# ls -l /dev/sd*
    brw-rw----. 1 root disk 8,  0 Nov 15  2018 /dev/sda
    brw-rw----. 1 root disk 8,  1 Nov 15  2018 /dev/sda1
    brw-rw----. 1 root disk 8,  2 Nov 15  2018 /dev/sda2
    brw-rw----. 1 root disk 8, 16 Nov 15  2018 /dev/sdb
    brw-rw----. 1 root disk 8, 32 Nov 15  2018 /dev/sdc
    brw-rw----. 1 root disk 8, 48 Nov 15  2018 /dev/sdd
    brw-rw----. 1 root disk 8, 64 Nov 15  2018 /dev/sde
    [root@localhost Desktop]#

    1, raid 5
    [root@localhost Desktop]# mdadm -Cv /dev/md0 -a yes -n 3 -l 5 -x 1 /dev/sd[b-e]
    mdadm: layout defaults to left-symmetric
    mdadm: layout defaults to left-symmetric
    mdadm: chunk size defaults to 512K
    mdadm: size set to 20954624K
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md0 started.
    [root@localhost Desktop]#

    2,

    2.1,或者简要信息查看

    [root@localhost Desktop]# mdadm -Q /dev/md0
    /dev/md0: 39.97GiB raid5 3 devices, 1 spare. Use mdadm --detail for more detail.
    [root@localhost Desktop]#

    2.2,或者查看详细信息

    [root@localhost Desktop]# mdadm -D /dev/md0
    /dev/md0:
            Version : 1.2
      Creation Time : Wed Nov 14 22:15:38 2018
         Raid Level : raid5
         Array Size : 41909248 (39.97 GiB 42.92 GB)
      Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
       Raid Devices : 3
      Total Devices : 4
        Persistence : Superblock is persistent

        Update Time : Wed Nov 14 22:17:32 2018
              State : clean
     Active Devices : 3
    Working Devices : 4
     Failed Devices : 0
      Spare Devices : 1

             Layout : left-symmetric
         Chunk Size : 512K

               Name : localhost.localdomain:0  (local to host localhost.localdomain)
               UUID : e69bb0ac:aaa28a5c:5ad94b81:5e62cf3f
             Events : 18

        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           4       8       48        2      active sync   /dev/sdd

           3       8       64        -      spare   /dev/sde
    [root@localhost Desktop]#

    3,格式化

    [root@localhost Desktop]# mkfs.ext4 /dev/md0
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=128 blocks, Stripe width=256 blocks
    2621440 inodes, 10477312 blocks
    523865 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2157969408
    320 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   

    [root@localhost Desktop]#

    4,挂载

    4.1, 临时+永久挂载

    [root@localhost Desktop]# mkdir rd5
    [root@localhost Desktop]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root   18G  2.9G   15G  17% /
    devtmpfs               985M     0  985M   0% /dev
    tmpfs                  994M  140K  994M   1% /dev/shm
    tmpfs                  994M  8.9M  986M   1% /run
    tmpfs                  994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1              497M  119M  379M  24% /boot
    [root@localhost Desktop]# mount /dev/md0 /root/Desktop/rd5/

    [root@localhost Desktop]# vim /etc/fstab

    添加行:
    /dev/md0                /root/Desktop/rd5       ext4    defaults        0 0

     4.2,重启并查看是否挂载成功

    [root@localhost Desktop]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root   18G  2.9G   15G  17% /
    devtmpfs               985M     0  985M   0% /dev
    tmpfs                  994M  140K  994M   1% /dev/shm
    tmpfs                  994M  8.9M  986M   1% /run
    tmpfs                  994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1              497M  119M  379M  24% /boot
    /dev/md0                40G   49M   38G   1% /root/Desktop/rd5

    5,cp一些测试文件到挂载的/home/zhxu/disk路径(此处省略),并尝试破坏(从虚拟机设置中移除一个硬盘),检查md信息


    [root@localhost disk]# mdadm -D /dev/md0
    /dev/md0:
            Version : 1.2
      Creation Time : Wed Nov 14 22:15:38 2018
         Raid Level : raid5
         Array Size : 41909248 (39.97 GiB 42.92 GB)
      Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
       Raid Devices : 3
      Total Devices : 4
        Persistence : Superblock is persistent

        Update Time : Wed Nov 14 22:30:11 2018
              State : clean, degraded, recovering
     Active Devices : 2
    Working Devices : 3
     Failed Devices : 1
      Spare Devices : 1

             Layout : left-symmetric
         Chunk Size : 512K

     Rebuild Status : 78% complete

               Name : localhost.localdomain:0  (local to host localhost.localdomain)
               UUID : e69bb0ac:aaa28a5c:5ad94b81:5e62cf3f
             Events : 36

        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           3       8       64        2      spare rebuilding   /dev/sde  #备用盘开始顶替被破坏的硬盘

           4       8       48        -      faulty   /dev/sdd
    [root@localhost disk]#
    [root@localhost disk]# mdadm -D /dev/md0
    /dev/md0:
            Version : 1.2
      Creation Time : Wed Nov 14 22:15:38 2018
         Raid Level : raid5
         Array Size : 41909248 (39.97 GiB 42.92 GB)
      Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
       Raid Devices : 3
      Total Devices : 4
        Persistence : Superblock is persistent

        Update Time : Wed Nov 14 22:30:38 2018
              State : clean
     Active Devices : 3
    Working Devices : 3
     Failed Devices : 1
      Spare Devices : 0

             Layout : left-symmetric
         Chunk Size : 512K

               Name : localhost.localdomain:0  (local to host localhost.localdomain)
               UUID : e69bb0ac:aaa28a5c:5ad94b81:5e62cf3f
             Events : 43

        Number   Major   Minor   RaidDevice State
           0       8       16        0      active sync   /dev/sdb
           1       8       32        1      active sync   /dev/sdc
           3       8       64        2      active sync   /dev/sde  #顶替并同步完毕

           4       8       48        -      faulty   /dev/sdd
    [root@localhost disk]#

    6,检查原来disk中数据是否丢失:NO

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    LVM逻辑卷管理

      新建 扩大 缩小 快照卷
    1 ls /dev/sd* umount lv_dir/ umount lv_dir/ lvcreate -L 300M -s -n SNAP /dev/juanzu/luojj
    2 pvcreate /dev/sdb /dev/sdc df -h
    df -h umount /home/zhxu/disk/
    3 vgcreate storage /dev/sd[b,c] lvextend -L 290M /dev/storage/vo e2fsck -f /dev/storage/vo lvconvert --merge /dev/juanzu/SNAP
    4 vgdisplay e2fsck -f /dev/storage/vo resize2fs /dev/storage/vo  200M mount /dev/juanzu/luojj /home/zhxu/disk/
    5 lvcreate -n vo -l 37  storage resize2fs /dev/storage/vo lvreduce /dev/storage/vo -L 200M  
    6 lvdisplay mount -a mount -a  
    7 mkfs.ext4 /dev/storage/vo df -h df -h  
    8 mkdir lv_dir      
    9 mount /dev/storage/vo lv_dir/  若格式为xfs,而不是ext4:    
    10 vim /etc/fstab  mount /dev/linuxprobe/vo /root/lv_dir
       
    11 mount -a  xfs_growfs /dev/linuxprobe/vo    
    12 dh -f      

     

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    1,新加硬盘(省略)后,使新硬盘支持LVM

    [root@localhost ~]# ls -l /dev/sd*
    brw-rw----. 1 root disk 8,  0 Nov 15  2018 /dev/sda
    brw-rw----. 1 root disk 8,  1 Nov 15  2018 /dev/sda1
    brw-rw----. 1 root disk 8,  2 Nov 15  2018 /dev/sda2
    brw-rw----. 1 root disk 8, 16 Nov 15  2018 /dev/sdb
    brw-rw----. 1 root disk 8, 32 Nov 15  2018 /dev/sdc
    [root@localhost ~]#
    [root@localhost ~]# pvcreate /dev/sdb /dev/sdc
      Physical volume "/dev/sdb" successfully created
      Physical volume "/dev/sdc" successfully created
    [root@localhost ~]#

    2,合并卷组vg

    [root@localhost ~]# vgcreate juanzu /dev/sdb /dev/sdc
      Volume group "juanzu" successfully created
    [root@localhost ~]#

    3,查看卷组信息

    [root@localhost ~]#
    [root@localhost ~]# vgdisplay juanzu
      --- Volume group ---
      VG Name               juanzu
      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               39.99 GiB
      PE Size               4.00 MiB
      Total PE              10238
      Alloc PE / Size       0 / 0   
      Free  PE / Size       10238 / 39.99 GiB  #两个硬盘size之和
      VG UUID               BxUbV1-EqP3-JtDU-W0Kt-xMHd-grYz-ry9Tvb
     

    4,生成逻辑卷

    [root@localhost ~]# lvcreate -n luojj -l 100 juanzu  #逻辑卷名称luojj,大小100X4M,从卷组juanzu中提取
      Logical volume "luojj" created
    [root@localhost ~]#

    5,查看逻辑卷大小

    [root@localhost ~]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/juanzu/luojj
      LV Name                luojj
      VG Name                juanzu
      LV UUID                6YAeLn-BXDv-KjCU-EwJ9-Ulxq-Et5e-1NnQXs
      LV Write Access        read/write
      LV Creation host, time localhost.localdomain, 2018-11-14 23:29:09 +0800
      LV Status              available
      # open                 0
      LV Size                400.00 MiB  #逻辑卷大小,一个PE=4MB,l=100
      Current LE             100
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:2
       
      --- Logical volume ---
      LV Path                /dev/rhel/swap
      LV Name                swap
      VG Name                rhel
      LV UUID                KA7zrA-KKgi-asMx-Q8cD-qNrw-wdqK-P0T91g
      LV Write Access        read/write
      LV Creation host, time localhost, 2018-11-02 17:20:14 +0800
      LV Status              available
      # open                 2
      LV Size                2.00 GiB
      Current LE             512
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:1
       
      --- Logical volume ---
      LV Path                /dev/rhel/root
      LV Name                root
      VG Name                rhel
      LV UUID                M3nmdd-LtNH-MJj4-j8lA-p1nS-c8R8-S7hCle
      LV Write Access        read/write
      LV Creation host, time localhost, 2018-11-02 17:20:15 +0800
      LV Status              available
      # open                 1
      LV Size                17.51 GiB
      Current LE             4482
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:0

    6,格式化

    [root@localhost ~]# mkfs.ext4 /dev/juanzu/luojj
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=1024 (log=0)
    Fragment size=1024 (log=0)
    Stride=0 blocks, Stripe width=0 blocks
    102400 inodes, 409600 blocks
    20480 blocks (5.00%) reserved for the super user
    First data block=1
    Maximum filesystem blocks=34078720
    50 block groups
    8192 blocks per group, 8192 fragments per group
    2048 inodes per group
    Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (8192 blocks): done
    Writing superblocks and filesystem accounting information: done

    [root@localhost ~]#  

    7,临时+永久挂载,并重启查看

    [root@localhost zhxu]# mount /dev/juanzu/luojj disk/
    [root@localhost zhxu]# vim /etc/fstab

    添加行:

    /dev/juanzu/luojj  /home/root/Desktop/lvm_dir  ext4  defaults  0 0

    重启查看:
    [root@localhost zhxu]# df -h
    Filesystem                Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root      18G  2.9G   15G  17% /
    devtmpfs                  985M     0  985M   0% /dev
    tmpfs                     994M  148K  994M   1% /dev/shm
    tmpfs                     994M  8.9M  986M   1% /run
    tmpfs                     994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1                 497M  119M  379M  24% /boot
    /dev/sr0                  3.5G  3.5G     0 100% /run/media/zhxu/RHEL-7.0 Server.x86_64
    /dev/mapper/juanzu-luojj  380M  2.3M  354M   1% /home/zhxu/disk
    [root@localhost zhxu]#

    8,扩大或缩小

    8.1 扩大

    8.1.1 卸载

    [root@localhost zhxu]# umount disk/

    8.1.2 扩容

    [root@localhost zhxu]# lvextend -L 800M /dev/juanzu/luojj
      Extending logical volume luojj to 800.00 MiB
      Logical volume luojj successfully resized
    [root@localhost zhxu]#

    8.1.3 检查系统文件是否完整

    [root@localhost zhxu]# e2fsck -f /dev/juanzu/luojj
    e2fsck 1.42.9 (28-Dec-2013)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/juanzu/luojj: 11/102400 files (0.0% non-contiguous), 23456/409600 blocks
    [root@localhost zhxu]#

    8.1.4 通知文件系统变更大小

    [root@localhost zhxu]# resize2fs /dev/juanzu/luojj
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/juanzu/luojj to 819200 (1k) blocks.
    The filesystem on /dev/juanzu/luojj is now 819200 blocks long.

    [root@localhost zhxu]#

    8.1.5 再次挂载,并查看扩容信息

    [root@localhost zhxu]# mount /dev/juanzu/luojj disk/
    [root@localhost zhxu]# df -h
    Filesystem                Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root      18G  2.9G   15G  17% /
    devtmpfs                  985M     0  985M   0% /dev
    tmpfs                     994M  148K  994M   1% /dev/shm
    tmpfs                     994M  8.9M  986M   1% /run
    tmpfs                     994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1                 497M  119M  379M  24% /boot
    /dev/sr0                  3.5G  3.5G     0 100% /run/media/zhxu/RHEL-7.0 Server.x86_64
    /dev/mapper/juanzu-luojj  767M  2.5M  721M   1% /home/zhxu/disk
    [root@localhost zhxu]#


    8.2 减小

    8.2.1 卸载

    [root@localhost zhxu]#
    [root@localhost zhxu]# umount disk/

    8.2.2 检查是否可以减小
    [root@localhost zhxu]# e2fsck -f /dev/juanzu/luojj
    e2fsck 1.42.9 (28-Dec-2013)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/juanzu/luojj: 11/204800 files (0.0% non-contiguous), 36617/819200 blocks
    [root@localhost zhxu]#
    8.2.3 通知系统要减小

    [root@localhost zhxu]# resize2fs /dev/juanzu/luojj 3000M
    resize2fs 1.42.9 (28-Dec-2013)
    The containing partition (or device) is only 819200 (1k) blocks.
    You requested a new size of 3072000 blocks.  #减小3000M太多,不允许

    [root@localhost zhxu]#
    [root@localhost zhxu]# resize2fs /dev/juanzu/luojj 300M
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/juanzu/luojj to 307200 (1k) blocks.
    The filesystem on /dev/juanzu/luojj is now 307200 blocks long.  #减小300M,可以

    [root@localhost zhxu]#

    8.2.4 减小300M

    [root@localhost zhxu]# lvreduce -L 300M /dev/juanzu/luojj
      WARNING: Reducing active logical volume to 300.00 MiB
      THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce luojj? [y/n]: y
      Reducing logical volume luojj to 300.00 MiB
      Logical volume luojj successfully resized
    [root@localhost zhxu]#
    8.2.5 挂载并查看

    [root@localhost zhxu]# mount /dev/juanzu/luojj disk/
    [root@localhost zhxu]# df -h
    Filesystem                Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root      18G  2.9G   15G  17% /
    devtmpfs                  985M     0  985M   0% /dev
    tmpfs                     994M  148K  994M   1% /dev/shm
    tmpfs                     994M  9.0M  986M   1% /run
    tmpfs                     994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1                 497M  119M  379M  24% /boot
    /dev/sr0                  3.5G  3.5G     0 100% /run/media/zhxu/RHEL-7.0 Server.x86_64
    /dev/mapper/juanzu-luojj  283M  2.1M  262M   1% /home/zhxu/disk

    8.3 快照卷

    快照卷前后相等

    快照卷:一次性

    8.3.1 创建快照卷

    [root@localhost disk]# lvcreate -L 300M -s -n SNAP /dev/juanzu/luojj
      Logical volume "SNAP" created
    [root@localhost disk]#
    8.3.2 清空原目录的文件

    [root@localhost disk]# ls
    aliases                  dnsmasq.conf  gshadow        ld.so.cache               my.cnf             radvd.conf        sudoers
    aliases.db               dracut.conf   gshadow-       ld.so.conf                nanorc             rc.local          sudo-ldap.conf
    anacrontab               drirc         hba.conf       libaudit.conf             netconfig          redhat-release    sysctl.conf
    asound.conf              e2fsck.conf   host.conf      libuser.conf              networks           request-key.conf  system-release
    at.deny                  enscript.cfg  hostname       locale.conf               nfsmount.conf      resolv.conf       system-release-cpe
    bashrc                   environment   hosts          localtime                 nsswitch.conf      rpc               trusted-key.key
    brltty.conf              ethertypes    hosts.allow    login.defs                nsswitch.conf.bak  rsyncd.conf       updatedb.conf
    chrony.conf              exports       hosts.deny     logrotate.conf            numad.conf         rsyslog.conf      usb_modeswitch.conf
    chrony.keys              favicon.png   idmapd.conf    lost+found                oddjobd.conf       rwtab             vconsole.conf
    colord.conf              filesystems   inittab        machine-id                os-release         securetty         vimrc
    cron.deny                fprintd.conf  inputrc        magic                     passwd             services          virc
    crontab                  fstab         ipsec.conf     mail.rc                   passwd-            sestatus.conf     wgetrc
    crypttab                 fuse.conf     ipsec.secrets  makedumpfile.conf.sample  pbm2ppa.conf       shadow            wvdial.conf
    csh.cshrc                gdbinit       issue          man_db.conf               pinforc            shadow-           yum.conf
    csh.login                GREP_COLORS   issue.net      mke2fs.conf               pnm2ppa.conf       shells
    DIR_COLORS               group         kdump.conf     motd                      printcap           sos.conf
    DIR_COLORS.256color      group-        krb5.conf      mtab                      profile            statetab
    DIR_COLORS.lightbgcolor  grub2.cfg     ksmtuned.conf  mtools.conf               protocols          sudo.conf
    [root@localhost disk]# rm -rf *
    [root@localhost disk]# ls
    [root@localhost disk]#

    8.3.3 恢复快照卷

    [root@localhost disk]# ls -l /dev/juanzu/
    total 0
    lrwxrwxrwx. 1 root root 7 Nov 15 00:15 luojj -> ../dm-2
    lrwxrwxrwx. 1 root root 7 Nov 15 00:15 SNAP -> ../dm-3
    [root@localhost disk]# cd ~
    [root@localhost ~]# umount /home/zhxu/disk/
    [root@localhost ~]# lvconvert --merge /dev/juanzu/SNAP
      Merging of volume SNAP started.
      luojj: Merged: 100.0%
      Merge of snapshot into logical volume luojj has finished.
      Logical volume "SNAP" successfully removed  #快照卷,一次性
    [root@localhost ~]#

    8.3.4 挂载并检查挂载情况,及恢复快照情况

    [root@localhost ~]# cd /home/zhxu/disk/
    [root@localhost disk]# ls
    [root@localhost disk]#
    [root@localhost disk]# mount /dev/juanzu/luojj /home/zhxu/disk/
    [root@localhost disk]#
    [root@localhost disk]# df -h
    Filesystem                Size  Used Avail Use% Mounted on
    /dev/mapper/rhel-root      18G  2.9G   15G  17% /
    devtmpfs                  985M     0  985M   0% /dev
    tmpfs                     994M  148K  994M   1% /dev/shm
    tmpfs                     994M  9.0M  986M   1% /run
    tmpfs                     994M     0  994M   0% /sys/fs/cgroup
    /dev/sda1                 497M  119M  379M  24% /boot
    /dev/sr0                  3.5G  3.5G     0 100% /run/media/zhxu/RHEL-7.0 Server.x86_64
    /dev/mapper/juanzu-luojj  283M  3.0M  261M   2% /home/zhxu/disk
    [root@localhost disk]# ls  /home/zhxu/disk/
    adjtime                  drirc         hosts           lost+found                passwd-           shells
    aliases                  e2fsck.conf   hosts.allow     machine-id                pbm2ppa.conf      sos.conf
    aliases.db               enscript.cfg  hosts.deny      magic                     pinforc           statetab
    anacrontab               environment   idmapd.conf     mail.rc                   pnm2ppa.conf      sudo.conf
    asound.conf              ethertypes    inittab         makedumpfile.conf.sample  printcap          sudoers
    at.deny                  exports       inputrc         man_db.conf               profile           sudo-ldap.conf
    bashrc                   favicon.png   ipsec.conf      mke2fs.conf               protocols         sysctl.conf
    brltty.conf              filesystems   ipsec.secrets   motd                      radvd.conf        system-release
    chrony.conf              fprintd.conf  issue           mtab                      rc.local          system-release-cpe
    chrony.keys              fstab         issue.net       mtools.conf               redhat-release    trusted-key.key
    colord.conf              fuse.conf     kdump.conf      my.cnf                    request-key.conf  updatedb.conf
    cron.deny                gdbinit       krb5.conf       nanorc                    resolv.conf       usb_modeswitch.conf
    crontab                  GREP_COLORS   ksmtuned.conf   netconfig                 rpc               vconsole.conf
    crypttab                 group         ld.so.cache     networks                  rsyncd.conf       vimrc
    csh.cshrc                group-        ld.so.conf      nfsmount.conf             rsyslog.conf      virc
    csh.login                grub2.cfg     libaudit.conf   nsswitch.conf             rwtab             wgetrc
    DIR_COLORS               gshadow       libuser.conf    nsswitch.conf.bak         securetty         wvdial.conf
    DIR_COLORS.256color      gshadow-      locale.conf     numad.conf                services          yum.conf
    DIR_COLORS.lightbgcolor  hba.conf      localtime       oddjobd.conf              sestatus.conf
    dnsmasq.conf             host.conf     login.defs      os-release                shadow
    dracut.conf              hostname      logrotate.conf  passwd                    shadow-
    [root@localhost disk]#
    8.4 LVM 删除

    8.4.1 编辑fstab,删除添加的挂载信息

    8.4.2 卸载

    umount /home/zhxu/disk

    8.4.3 lvremove /dev/juanzu/luojj

    8.4.4 vgremove juanzu

    8.4.5 pvremove /dev/sdb; pvremove /dev/sdc

    ------ 时间永远是公平的,你付出多少时间,时间就回报你多少。
  • 相关阅读:
    理解WebKit和Chromium: Web应用和Web运行环境
    理解WebKit和Chromium: 网页渲染的基本过程
    【闲谈】我的大学
    使用GDAL将下载的Google卫星图像转为带坐标的tif
    Linux下使用GDAL进行开发(automake使用)
    Linux下编译GDAL
    【Unity技巧】统一管理回调函数——观察者模式
    【Unity技巧】使用单例模式Singleton
    【Unity插件】LitJson杂谈
    理解WebKit和Chromium:Chromium资源磁盘缓存
  • 原文地址:https://www.cnblogs.com/zhxu/p/9960714.html
Copyright © 2020-2023  润新知