8月12日 作业和练习

  1. 创建一个可用空间为1G的RAID1设备,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录
[root@centos6 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  5.8G  0 rom  /media/CDROM
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 39.1G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
sdd      8:48   0   80G  0 disk 
├─sdd1   8:49   0    1G  0 part 
└─sdd2   8:50   0    1G  0 part   ---创建两个raid分区,创建时注意修改id为raid
sdc      8:32   0  150G  0 disk 
[root@centos6 ~]#mdadm -C /dev/md0 -a yes -l 1 -n2 /dev/sdd{1,2}  ---创建raid1
[root@centos6 ~]#mdadm -D /dev/md0---查看
[root@centos6 ~]#cat /proc/mdstat  --也可以查看
Personalities : [raid1] 
md0 : active raid1 sdd2[1] sdd1[0]
      1059200 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>
[root@centos6 ~]#mdadm -Ds /dev/md0 >/etc/mdadm.conf    ---生成配置文件
[root@centos6 ~]#mkfs.ext4 /dev/md0 ---在raid1上创建文件系统
[root@centos6 ~]#vim /etc/fstab ---修改配置文件
UUID=7467a4d3-12c7-4b47-8acf-23b7e4d0daec  /mnt/md0 ext4  defaults      0  0
[root@centos6 ~]#mkdir /mnt/md0
[root@centos6 ~]#mount -a
[root@centos6 ~]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4787816  42916956  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208   49016  38088192   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         6049912 6049912         0 100% /media/CDROM
/dev/md0         1009760    1304    955496   1% /mnt/md0
[root@centos6 ~]#cd /mnt/md0
[root@centos6 md0]#ls
lost+found
[root@centos6 md0]#cp /etc/fstab .  ---复制一个文件到该目录
[root@centos6 md0]#ls
fstab  lost+found
[root@centos6 md0]#mdadm /dev/md0 -f /dev/sdd1  ---模拟/dev/sdd1设备损坏
mdadm: set /dev/sdd1 faulty in /dev/md0
[root@centos6 md0]#mdadm -D /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Aug  9 11:23:29 2017
     Raid Level : raid1
     Array Size : 1059200 (1034.38 MiB 1084.62 MB)
  Used Dev Size : 1059200 (1034.38 MiB 1084.62 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 11:35:47 2017
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 1
  Spare Devices : 0

           Name : centos6.magedu.com:0  (local to host centos6.magedu.com)
           UUID : 88f0cd55:64c0cbc3:158f4d8a:76f1031a
         Events : 19

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       50        1      active sync   /dev/sdd2

       0       8       49        -      faulty   /dev/sdd1   ---标记为坏的状态
[root@centos6 md0]#cat /proc/mdstat
Personalities : [raid1] 
md0 : active raid1 sdd2[1] sdd1[0](F)
      1059200 blocks super 1.2 [2/1] [_U]
      
unused devices: <none>
[root@centos6 md0]#ls   ---但仍然可以看到磁盘的内容
fstab  lost+found
[root@centos6 ~]#umount /dev/md0  ---取消挂载
[root@centos6 ~]#mdadm -S /dev/md0  ---停止raid设备
mdadm: stopped /dev/md0
[root@centos6 ~]#mdadm --zero-superblock /dev/sdd2  ---清除磁盘上的raid信息

总结:raid1的两个设备互为镜像,有容错性,一个磁盘损坏,另外一个磁盘可以正常使用。

  1. 创建由三块硬盘组成的可用空间为2G的RAID5设备,要求其chunk大小为256k,文件系统为ext4,开机可自动挂载至/mydata目录
[root@centos6 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  5.8G  0 rom  /media/CDROM
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 39.1G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
sdd      8:48   0   80G  0 disk 
├─sdd1   8:49   0    1G  0 part 
├─sdd2   8:50   0    1G  0 part 
├─sdd3   8:51   0    1K  0 part 
├─sdd5   8:53   0    1G  0 part 
└─sdd6   8:54   0    1G  0 part 
sdc      8:32   0  150G  0 disk 
[root@centos6 ~]#mdadm -C /dev/md1 -a yes -l 5 -n3 -x1 -c 256 /dev/sdd{1,2,5,6}
mdadm: /dev/sdd1 appears to contain an ext2fs file system
       size=5253220K  mtime=Tue Aug  8 11:04:03 2017
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@centos6 ~]#mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Wed Aug  9 11:52:23 2017
     Raid Level : raid5
     Array Size : 2118144 (2.02 GiB 2.17 GB)
  Used Dev Size : 1059072 (1034.25 MiB 1084.49 MB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 11:52:38 2017
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 256K  ---chunk大小256k

           Name : centos6.magedu.com:1  (local to host centos6.magedu.com)
           UUID : dfccfead:c3849109:105526da:967bc8f7
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       50        1      active sync   /dev/sdd2
       4       8       53        2      active sync   /dev/sdd5

       3       8       54        -      spare   /dev/sdd6  ---备用设备
[root@centos6 ~]#mkfs.ext4 /dev/md1
[root@centos6 ~]#vim /etc/fstab 
UUID=6db71b7f-aa71-482c-b32a-db6f93078623    /mnt/md1   ext4 defaults  0 0
[root@centos6 ~]#mkdir /mnt/md1
[root@centos6 ~]#mount -a
[root@centos6 ~]#df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        48G  4.6G   41G  11% /
tmpfs           491M   76K  491M   1% /dev/shm
/dev/sda3        39G   48M   37G   1% /app
/dev/sda1       969M   35M  885M   4% /boot
/dev/sr0        5.8G  5.8G     0 100% /media/CDROM
/dev/md1        2.0G  3.1M  1.9G   1% /mnt/md1
[root@centos6 ~]#mdadm /dev/md1 -f /dev/sdd5
mdadm: set /dev/sdd5 faulty in /dev/md1
[root@centos6 ~]#mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Wed Aug  9 11:52:23 2017
     Raid Level : raid5
     Array Size : 2118144 (2.02 GiB 2.17 GB)
  Used Dev Size : 1059072 (1034.25 MiB 1084.49 MB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 11:59:56 2017
          State : clean, degraded, recovering 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 1
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 256K

 Rebuild Status : 34% complete

           Name : centos6.magedu.com:1  (local to host centos6.magedu.com)
           UUID : dfccfead:c3849109:105526da:967bc8f7
         Events : 25

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       50        1      active sync   /dev/sdd2
       3       8       54        2      spare rebuilding   /dev/sdd6

       4       8       53        -      faulty   /dev/sdd5
[root@centos6 ~]#cd /mnt/md1
[root@centos6 md1]#ls
lost+found
[root@centos6 md1]#cp /etc/fstab .
[root@centos6 md1]#ls ---磁盘仍然可以使用
fstab  lost+found
[root@centos6 md1]#mdadm -r /dev/md1 /dev/sdd5  --移除设备
mdadm: hot removed /dev/sdd5 from /dev/md1
[root@centos6 md1]#mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Wed Aug  9 11:52:23 2017
     Raid Level : raid5
     Array Size : 2118144 (2.02 GiB 2.17 GB)
  Used Dev Size : 1059072 (1034.25 MiB 1084.49 MB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 12:01:47 2017
          State : clean 
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 256K

           Name : centos6.magedu.com:1  (local to host centos6.magedu.com)
           UUID : dfccfead:c3849109:105526da:967bc8f7
         Events : 38

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       50        1      active sync   /dev/sdd2
       3       8       54        2      active sync   /dev/sdd6  ---可以看到/dev/sdd5已经被移除
[root@centos6 md1]#mdadm -a /dev/md1 /dev/sdd5  ---,模拟一个磁盘损坏之后,只有先把它移除才能重新加上
mdadm: added /dev/sdd5
[root@centos6 md1]#mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Wed Aug  9 11:52:23 2017
     Raid Level : raid5
     Array Size : 2118144 (2.02 GiB 2.17 GB)
  Used Dev Size : 1059072 (1034.25 MiB 1084.49 MB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 12:04:52 2017
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 256K

           Name : centos6.magedu.com:1  (local to host centos6.magedu.com)
           UUID : dfccfead:c3849109:105526da:967bc8f7
         Events : 39

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       50        1      active sync   /dev/sdd2
       3       8       54        2      active sync   /dev/sdd6

       4       8       53        -      spare   /dev/sdd5
       3       8       54        2      active sync   /dev/sdd6
[root@centos6 md1]#mdadm /dev/md1 -f /dev/sdd6
mdadm: set /dev/sdd6 faulty in /dev/md1
[root@centos6 md1]#mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Wed Aug  9 11:52:23 2017
     Raid Level : raid5
     Array Size : 2118144 (2.02 GiB 2.17 GB)
  Used Dev Size : 1059072 (1034.25 MiB 1084.49 MB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 12:06:37 2017
          State : clean, degraded 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 256K

           Name : centos6.magedu.com:1  (local to host centos6.magedu.com)
           UUID : dfccfead:c3849109:105526da:967bc8f7
         Events : 42

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       50        1      active sync   /dev/sdd2
       4       0        0        4      removed

       3       8       54        -      faulty   /dev/sdd6
[root@centos6 md1]#ls  ---又破坏一个设备,仍然可以使用,说明raid5可以通过异或校验位找回损坏磁盘的数据
fstab  lost+found
[root@centos6 md1]#mdadm /dev/md1 -a /dev/sdd4  ---添加一块磁盘做为备用磁盘
mdadm: added /dev/sdd4
[root@centos6 md1]#mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Wed Aug  9 11:52:23 2017
     Raid Level : raid5
     Array Size : 2118144 (2.02 GiB 2.17 GB)
  Used Dev Size : 1059072 (1034.25 MiB 1084.49 MB)
   Raid Devices : 3
  Total Devices : 5
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 12:16:16 2017
          State : clean 
 Active Devices : 3
Working Devices : 5
 Failed Devices : 0
  Spare Devices : 2

         Layout : left-symmetric
     Chunk Size : 256K

           Name : centos6.magedu.com:1  (local to host centos6.magedu.com)
           UUID : dfccfead:c3849109:105526da:967bc8f7
         Events : 64

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       50        1      active sync   /dev/sdd2
       4       8       53        2      active sync   /dev/sdd5

       3       8       54        -      spare   /dev/sdd6
       5       8       52        -      spare   /dev/sdd4
[root@centos6 md1]#mdadm -G /dev/md1 -n4 -a /dev/sdd4  ---增加新的raid成员
mdadm: added /dev/sdd4
[root@centos6 md1]#mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Wed Aug  9 11:52:23 2017
     Raid Level : raid5
     Array Size : 2118144 (2.02 GiB 2.17 GB)
  Used Dev Size : 1059072 (1034.25 MiB 1084.49 MB)
   Raid Devices : 4
  Total Devices : 5
    Persistence : Superblock is persistent

    Update Time : Wed Aug  9 12:18:52 2017
          State : clean, reshaping 
 Active Devices : 4
Working Devices : 5
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 256K

 Reshape Status : 3% complete
  Delta Devices : 1, (3->4)

           Name : centos6.magedu.com:1  (local to host centos6.magedu.com)
           UUID : dfccfead:c3849109:105526da:967bc8f7
         Events : 80

    Number   Major   Minor   RaidDevice State
       0       8       49        0      active sync   /dev/sdd1
       1       8       50        1      active sync   /dev/sdd2
       4       8       53        2      active sync   /dev/sdd5
       5       8       52        3      active sync   /dev/sdd4

       3       8       54        -      spare   /dev/sdd6
删除raid
[root@centos6 ~]#umount /dev/md1
[root@centos6 ~]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4787852  42916920  11% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208   49016  38088192   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         6049912 6049912         0 100% /media/CDROM
[root@centos6 ~]#mdadm -S /dev/md1  ---停止raid设备
mdadm: stopped /dev/md1
[root@centos6 ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  5.8G  0 rom  /media/CDROM
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 39.1G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
sdd      8:48   0   80G  0 disk 
├─sdd1   8:49   0    1G  0 part 
├─sdd2   8:50   0    1G  0 part 
├─sdd3   8:51   0    1K  0 part 
├─sdd5   8:53   0    1G  0 part 
├─sdd6   8:54   0    1G  0 part 
└─sdd4   8:52   0    1G  0 part 
sdc      8:32   0  150G  0 disk 
[root@centos6 ~]#mdadm --zero-superblock /dev/sdd2  ---清除文件系统上的raid信息
[root@centos6 ~]#mdadm --zero-superblock /dev/sdd5
[root@centos6 ~]#mdadm --zero-superblock /dev/sdd6
[root@centos6 ~]#mdadm --zero-superblock /dev/sdd4
[root@centos6 ~]#blkid
/dev/sda1: UUID="a056e3b8-7cc2-4aea-9308-9b0744741394" TYPE="ext4" /dev/sda2: UUID="07e3094b-c50d-4568-aee5-b2f76d91c962" TYPE="ext4" 
/dev/sda3: UUID="4a2031c3-8595-489e-bc6d-1e2c31860c7b" TYPE="ext4" 
/dev/sda5: UUID="953b7594-f906-4d3e-8a3a-a6bb79b1c900" TYPE="swap" 
/dev/sdd1: UUID="af9d834a-18c4-4f10-af33-8e5ed7adbaf0" TYPE="ext4" 
[root@centos6 etc]#rm -rf /etc/mdadm.conf  ---删除配置文件
[root@centos6 etc]#vim /etc/fstab   ---修改
  1. 创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/mnt/testlv录目
[root@centos7 ~]#pvcreate /dev/sdb{1,2}
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdb2" successfully created.
[root@centos7 ~]#pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb1     lvm2 ---  15.00g 15.00g
  /dev/sdb2     lvm2 ---   5.00g  5.00g
[root@centos7 ~]#vgcreate testvg -s 16MB /dev/sdb{1,2}
  Volume group "testvg" successfully created
[root@centos7 ~]#vgdisplay 
  --- Volume group ---
  VG Name               testvg
  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               19.97 GiB
  PE Size               16.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / 19.97 GiB
  VG UUID               TkwNjr-nCIY-0At0-r3Pz-xC36-kKz0-iiihVM
   [root@centos7 ~]#lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created.
[root@centos7 ~]#lvs
  LV     VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  testlv testvg -wi-a----- 5.00g                     
[root@centos7 ~]#mkfs.ext4 /dev/testvg/testlv 
[root@centos7 ~]#mkdir [root@centos7 ~]#mkdir /mnt/testlv
[root@centos7 ~]#mount /dev/testvg/testlv /mnt/testlv/
[root@centos7 ~]#df
Filesystem                1K-blocks     Used Available Use% Mounted on
/dev/sda2                  52403200 15345352  37057848  30% /
devtmpfs                     918932        0    918932   0% /dev
tmpfs                        933644       84    933560   1% /dev/shm
tmpfs                        933644    20912    912732   3% /run
tmpfs                        933644        0    933644   0% /sys/fs/cgroup
/dev/sda3                  52403200  1052276  51350924   3% /app
/dev/sda1                   1038336   172280    866056  17% /boot
tmpfs                        186732       12    186720   1% /run/user/0
/dev/sr0                    8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/testvg-testlv   5029504    20472   4730504   1% /mnt/testlv
[root@centos7 ~]#mount /dev/testvg/testlv /mnt/testlv/
[root@centos7 ~]#df
Filesystem                1K-blocks     Used Available Use% Mounted on
/dev/sda2                  52403200 15345352  37057848  30% /
devtmpfs                     918932        0    918932   0% /dev
tmpfs                        933644       84    933560   1% /dev/shm
tmpfs                        933644    20912    912732   3% /run
tmpfs                        933644        0    933644   0% /sys/fs/cgroup
/dev/sda3                  52403200  1052276  51350924   3% /app
/dev/sda1                   1038336   172280    866056  17% /boot
tmpfs                        186732       12    186720   1% /run/user/0
/dev/sr0                    8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/testvg-testlv   5029504    20472   4730504   1% /mnt/testlv
  1. 新建用户archlinux,要求其家目录为/mnt/testlv/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录
[root@centos7 testlv]#useradd -d /mnt/testlv/archlinux archlinux
[root@centos7 testlv]#id archlinux
uid=1006(archlinux) gid=1008(archlinux) groups=1008(archlinux)
[root@centos7 testlv]#getent passwd archlinux
archlinux:x:1006:1008::/mnt/testlv/archlinux:/bin/bash
[root@centos7 testlv]#ls
archlinux  lost+found
[root@centos7 testlv]#su - archlinux 
[archlinux@centos7 ~]$cp -a /etc/pam.d/ .
[archlinux@centos7 ~]$ls 
pam.d
  1. 扩展testlv至7G,要求archlinux用户的文件不能丢失
[root@centos7 testlv]#cp -a archlinux/ /app
[root@centos7 testlv]#cd /app
[root@centos7 app]#ls
archlinux  f1  home  httpd24  mbrcentos7  music  music.sh  test
[root@centos7 app]#lvextend -r -L 7G /dev/testvg/testlv 
  Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).
  Logical volume testvg/testlv successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/testvg-testlv is mounted on /mnt/testlv; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/testvg-testlv is now 1835008 blocks long.

[root@centos7 app]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                NQqqYq-NZv3-Wxck-MVU7-C0VP-A9D8-cjgarA
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 20:11:18 +0800
  LV Status              available
  # open                 1
  LV Size                7.00 GiB
  Current LE             448
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@centos7 app]#df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/sda2                   50G   15G   36G  30% /
devtmpfs                   898M     0  898M   0% /dev
tmpfs                      912M   84K  912M   1% /dev/shm
tmpfs                      912M   21M  892M   3% /run
tmpfs                      912M     0  912M   0% /sys/fs/cgroup
/dev/sda3                   50G  1.1G   49G   3% /app
/dev/sda1                 1014M  169M  846M  17% /boot
tmpfs                      183M   12K  183M   1% /run/user/0
/dev/sr0                   7.8G  7.8G     0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/testvg-testlv  6.8G   23M  6.4G   1% /mnt/testlv
[root@centos7 archlinux]#du -sh pam.d/
164K    pam.d/
[root@centos7 archlinux]#du -sh pam.d/
164K    pam.d/
文件并没有丢失
  1. 收缩testlv至3G,要求archlinux用户的文件不能丢失
[root@centos7 ~]#umount /mnt/testlv/
[root@centos7 ~]#df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       52403200 15345320  37057880  30% /
devtmpfs          918932        0    918932   0% /dev
tmpfs             933644       84    933560   1% /dev/shm
tmpfs             933644    20916    912728   3% /run
tmpfs             933644        0    933644   0% /sys/fs/cgroup
/dev/sda3       52403200  1052524  51350676   3% /app
/dev/sda1        1038336   172280    866056  17% /boot
tmpfs             186732       12    186720   1% /run/user/0
/dev/sr0         8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
[root@centos7 ~]#fsck -f /dev/testvg/testlv 
fsck from util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found.  Create<y>? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/mapper/testvg-testlv: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/testvg-testlv: 71/458752 files (0.0% non-contiguous), 67378/1835008 blocks
[root@centos7 ~]#resize2fs /dev/testvg/testlv 3G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 786432 blocks long.
[root@centos7 ~]#lvreduce -L 3G /dev/testvg/testlv 
  WARNING: Reducing active logical volume to 3.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/testlv? [y/n]: y
  Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).
  Logical volume testvg/testlv successfully resized.
[root@centos7 ~]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                NQqqYq-NZv3-Wxck-MVU7-C0VP-A9D8-cjgarA
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 20:11:18 +0800
  LV Status              available
  # open                 0
  LV Size                3.00 GiB
  Current LE             192
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   [root@centos7 archlinux]#du -sh pam.d/
164K    pam.d/
文件没有丢失
  1. 对testlv创建快照,并尝试基于快照备份数据,验正快照的功能
[root@centos7 archlinux]#lvcreate -L 500M -s -n testlv-snapshot -p r /dev/testvg/testlv  Using default stripesize 64.00 KiB.
  Rounding up size to full physical extent 512.00 MiB
  Logical volume "testlv-snapshot" created.
[root@centos7 archlinux]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                NQqqYq-NZv3-Wxck-MVU7-C0VP-A9D8-cjgarA
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 20:11:18 +0800
  LV snapshot status     source of
                         testlv-snapshot [active]
  LV Status              available
  # open                 1
  LV Size                3.00 GiB
  Current LE             192
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/testvg/testlv-snapshot
  LV Name                testlv-snapshot
  VG Name                testvg
  LV UUID                2YBbh6-wgD1-ZUl3-BgSB-Qnet-QvR0-rYefPc
  LV Write Access        read only
  LV Creation host, time centos7.magedu.com, 2017-08-12 20:46:34 +0800
  LV snapshot status     active destination for testlv
  LV Status              available
  # open                 0
  LV Size                3.00 GiB
  Current LE             192
  COW-table size         512.00 MiB
  COW-table LE           32
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
[root@centos7 archlinux]#cd pam.d/
[root@centos7 pam.d]#ls
atd                     gdm-pin           ppp                sudo
chfn                    gdm-smartcard     remote             sudo-i
chsh                    liveinst          runuser            su-l
config-util             login             runuser-l          system-auth
crond                   other             screen             system-auth-ac
cups                    passwd            setup              systemd-user
fingerprint-auth        password-auth     smartcard-auth     vlock
fingerprint-auth-ac     password-auth-ac  smartcard-auth-ac  vmtoolsd
gdm-autologin           pluto             smtp               vsftpd
gdm-fingerprint         polkit-1          smtp.postfix       xserver
gdm-launch-environment  postlogin         sshd
gdm-password            postlogin-ac      su
[root@centos7 pam.d]#touch f1
[root@centos7 pam.d]#ls
atd                     gdm-password      postlogin-ac       su
chfn                    gdm-pin           ppp                sudo
chsh                    gdm-smartcard     remote             sudo-i
config-util             liveinst          runuser            su-l
crond                   login             runuser-l          system-auth
cups                    other             screen             system-auth-ac
f1                      passwd            setup              systemd-user
fingerprint-auth        password-auth     smartcard-auth     vlock
fingerprint-auth-ac     password-auth-ac  smartcard-auth-ac  vmtoolsd
gdm-autologin           pluto             smtp               vsftpd
gdm-fingerprint         polkit-1          smtp.postfix       xserver
gdm-launch-environment  postlogin         sshd
[root@centos7 testlv]#ls
archlinux  fstab  lost+found
[root@centos7 testlv]#vim fstab 
  1 #
  2 UUID=e7e1738b-58ae-49d3-9f7e-c62988ead392 /                       xfs     defaults
           0 0
  3 UUID=348930fe-f95e-40e6-90ff-83c66b3f2e9a /app                    xfs     defaults
           0 0
  4 UUID=dfbab032-681e-4e34-a16e-2f5e1eda5f32 /boot                   xfs     defaults
           0 0
  5 UUID=6145ae5c-6ebd-4655-a52f-e90f9b5a9e58 swap                    swap    defaults
           0 0
  6 UUID=4da949dd-b453-4a9e-9a10-6397b5296519   /home                 ext4     grpquota
        0  0
                                                                                   
"fstab" 6L, 470C written
[root@centos7 testlv]#cd 
[root@centos7 ~]#umount /mnt/testlv/ ---注意,此步骤很重要,如果不取消挂载就会发货快照是恢复不了的
[root@centos7 ~]#df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       52403200 15345416  37057784  30% /
devtmpfs          918932        0    918932   0% /dev
tmpfs             933644       84    933560   1% /dev/shm
tmpfs             933644    20932    912712   3% /run
tmpfs             933644        0    933644   0% /sys/fs/cgroup
/dev/sda3       52403200  1052524  51350676   3% /app
/dev/sda1        1038336   172280    866056  17% /boot
tmpfs             186732       12    186720   1% /run/user/0
/dev/sr0         8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
[root@centos7 ~]#lvconvert --merge /dev/testvg/testlv-snapshot 
  Merging of volume testvg/testlv-snapshot started.
  testlv: Merged: 100.00%
[root@centos7 ~]#lvdisplay  ---恢复快照后快照就没有了
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                d3nXFB-rFGG-iyT2-KUBL-hQV2-06Z4-UQYwxs
  LV Write Access        read/write
  LV Creation host, time centos7.magedu.com, 2017-08-12 20:55:40 +0800
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             640
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@centos7 ~]#mount /dev/testvg/testlv /mnt/testlv/
[root@centos7 ~]#df
Filesystem                1K-blocks     Used Available Use% Mounted on
/dev/sda2                  52403200 15345572  37057628  30% /
devtmpfs                     918932        0    918932   0% /dev
tmpfs                        933644       84    933560   1% /dev/shm
tmpfs                        933644    20920    912724   3% /run
tmpfs                        933644        0    933644   0% /sys/fs/cgroup
/dev/sda3                  52403200  1052524  51350676   3% /app
/dev/sda1                   1038336   172280    866056  17% /boot
tmpfs                        186732       12    186720   1% /run/user/0
/dev/sr0                    8086368  8086368         0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/testvg-testlv  10190100    37108   9612320   1% /mnt/testlv
[root@centos7 ~]#ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Pictures  Templates
Desktop          Downloads  Music                 Public    Videos
[root@centos7 ~]#cd /mnt/testlv/
[root@centos7 testlv]#ls
archlinux  fstab  lost+found
[root@centos7 testlv]#cat fstab ---内容已经恢复

#
# /etc/fstab
# Created by anaconda on Fri Jul 14 11:16:04 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=e7e1738b-58ae-49d3-9f7e-c62988ead392 /                       xfs     defaults        0 0
UUID=348930fe-f95e-40e6-90ff-83c66b3f2e9a /app                    xfs     defaults        0 0
UUID=dfbab032-681e-4e34-a16e-2f5e1eda5f32 /boot                   xfs     defaults        0 0
UUID=6145ae5c-6ebd-4655-a52f-e90f9b5a9e58 swap                    swap    defaults        0 0
UUID=4da949dd-b453-4a9e-9a10-6397b5296519   /home                 ext4     grpquota    0  0
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,590评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,808评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,151评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,779评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,773评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,656评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,022评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,678评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,038评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,756评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,411评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,005评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,973评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,053评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,495评论 2 343

推荐阅读更多精彩内容