零距离接触软RAID0和RAID5以及逻辑卷LVM

一、创建一个可用空间为1G的RAID1设备,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录

1、首先手动给虚拟机添加两块硬盘

2、添加硬盘后,无需关机,直接让内核扫描添加的磁盘

[root@centos6 ~]# echo '- - -' > /sys/class/scsi_host/host2/scan     #通知内核扫描硬盘,如还是没有显示,将host2更改为0或1
[root@centos6 ~]# lsblk     #查看内核是否已扫描到添加的硬盘,也可以用"fdisk -l"命令查看硬盘设备
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
├─sda3   8:3    0  9.8G  0 part /testdir
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
sdc      8:32   0   20G  0 disk

3、对添加的硬盘进行分区

[root@centos6 ~]# fdisk /dev/sdb     #对添加的硬盘"sdb"进行分区

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n     #新增一个分区
Command action
   e   extended
   p   primary partition (1-4)
p     #选择为主分区
Partition number (1-4): 1     #选择主分区编号为1
First cylinder (1-2610, default 1):      #直接回车键选择起始柱面的默认值为1
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +1G     #给新增的分区磁盘容量为1G

Command (m for help): t     #选择分区类型
Selected partition 1
Hex code (type L to list codes): fd     #选择分区类型为fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w     #分区完毕后,保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.     #未有显示报警信息,无需使用命令"partx"让内核扫描硬盘分区
Syncing disks.
[root@centos6 ~]# fdisk -l /dev/sdb     #查看磁盘"sdb"分区情况

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xdf758fca

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         132     1060258+  fd  Linux raid autodetect      #已显示分区,切显示的类型为fd,也就是"Linux raid autodetect"

对于另一块磁盘"sdc"的分区,不再做演示,按"sdb"分区的步骤操作即可

4、制作1G的RAID1设备

[root@centos6 ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -c 512 /dev/sd{bc}1     #创建一个 1G RAID1的设备
mdadm: You haven't given enough devices (real or missing) to create this array
[root@centos6 ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -c 512 /dev/sd{b,c}1
mdadm: Note: this array has metadata at the start and     #提示说软raid的不能用作启动分区
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array?             
Continue creating array? (y/n) y     #确认创建软raid1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.     #提示创建成功
[root@centos6 ~]# mdadm -D /dev/md0     #查看raid1的信息
/dev/md0:
        Version : 1.2
  Creation Time : Sat Aug  6 20:27:22 2016
     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 : Sat Aug  6 20:27:28 2016
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : centos6:0  (local to host centos6)
           UUID : 1dbeb9dc:e22b62df:7338c4e7:f754fcd6
         Events : 17

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
[root@centos6 ~]#

5、对"md0"进行格式,并创建文件系统为ext4

[root@centos6 ~]# mkfs -t ext4 /dev/md0     #将raid0中的"md0"进行格式化文件系统为"ext4"
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
66240 inodes, 264800 blocks
13240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7360 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376

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

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

6、将"md0"挂载到/backup目录下,并在配置文件中填写挂载记录,使得开机自动挂载

[root@centos6 ~]# echo -e "`blkid /dev/md0 |cut -d ' ' -f2`\t /backup\t ext4 defaults\t 0\t 0" >> /etc/fstab     #将挂载信息写入到配置文件当中,建议填写UUID,重启电脑后名称会变
[root@centos6 ~]# mkdir /backup     #创建要挂载目录
[root@centos6 ~]# mount -a     #加载配置文件中的所有文件系统
[root@centos6 ~]# mount |grep '/dev/md0'     #查看是否已挂载
/dev/md0 on /backup type ext4 (rw)
[root@centos6 ~]# reboot     #重启电脑
[root@centos6 ~]# mount     #查看挂载的文件系统
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /testdir type ext4 (rw)
/dev/md127 on /backup type ext4 (rw)     #原来的名称"md0"已变成"md127"
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@centos6 ~]# mdadm -D /dev/md127     #查看挂载分区
/dev/md127:
        Version : 1.2
  Creation Time : Sat Aug  6 20:27:22 2016
     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 : Sat Aug  6 21:20:47 2016
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : centos6:0  (local to host centos6)
           UUID : 1dbeb9dc:e22b62df:7338c4e7:f754fcd6
         Events : 21

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1     #显示为之前的两个分区创建的raid0,如需开机自动挂载,需写入配置文件/etc/fstab中
       1       8       33        1      active sync   /dev/sdc1

二、创建由三块硬盘组成的可用空间为2G的RAID5设备,要求其chunk大小为256k,文件系统为ext4,开机可自动挂载至/mydata目录

1、首先手动给虚拟机添加两块硬盘

2、添加硬盘后,无需关机,直接让内核扫描添加的磁盘

[root@centos6 ~]# echo '- - -' > /sys/class/scsi_host/host2/scan     #通知内核扫描硬盘,如还是没有显示,将host2更改为0或1
[root@centos6 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
├─sda3   8:3    0  9.8G  0 part /testdir
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
sdc      8:32   0   20G  0 disk 
sdd      8:48   0   20G  0 disk

3、对添加的硬盘进行分区

[root@centos6 ~]# fdisk /dev/sdb     #对添加的硬盘"sdb"进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x0f25c5ba.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n     #新增一个分区
Command action
   e   extended
   p   primary partition (1-4)
p     #选择为主分区
Partition number (1-4): 1     #选择主分区编号为1
First cylinder (1-2610, default 1):      #直接回车键选择起始柱面的默认值为1
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G     #给新增的分区磁盘容量为2G

Command (m for help): t     #选择分区类型
Selected partition 1
Hex code (type L to list codes): fd     #选择分区类型为fd
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): w     #分区完毕后,保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.     #未有显示报警信息,无需使用命令"partx"让内核扫描硬盘分区
Syncing disks.
[root@centos6 ~]# fdisk -l /dev/sdb     #查看磁盘"sdb"分区情况

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0f25c5ba

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  fd  Linux raid autodetect     #已显示分区,切显示的类型为fd,也就是"Linux raid autodetect"

对于另外两块磁盘"sdc"和"sdd"的分区,不再做演示,按"sdb"分区的步骤操作即可

4、制作2G的RAID5设备,且chunk大小为256k

[root@centos6 ~]# fdisk -l /dev/sd[b-d] |grep '^/dev/sd[b-d]'     #查看三块磁盘分区的情况
/dev/sdb1               1         262     2104483+  fd  Linux raid autodetect
/dev/sdc1               1         262     2104483+  fd  Linux raid autodetect
/dev/sdd1               1         262     2104483+  fd  Linux raid autodetect
[root@centos6 ~]# mdadm -C /dev/md5 -a yes -l 5 -n 3 -c 256 /dev/sd{b,c,d}1     #创建raid5并命名为"md5",chunk大小为256
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@centos6 ~]# mdadm -D /dev/md5     #查看创建后的信息
/dev/md5:
        Version : 1.2
  Creation Time : Sat Aug  6 23:02:18 2016
     Raid Level : raid5
     Array Size : 4204544 (4.01 GiB 4.31 GB)
  Used Dev Size : 2102272 (2.00 GiB 2.15 GB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Sat Aug  6 23:02:29 2016
          State : clean 
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0

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

           Name : centos6:5  (local to host centos6)
           UUID : 592b4f57:8c5842b2:8b2814b2:f0de1c28
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
       3       8       49        2      active sync   /dev/sdd1

5、对"md5"进行格式,并创建文件系统为ext4

[root@centos6 ~]# mkfs -t ext4 -L 'MYDATA' -m 3 -b 4096 /dev/md5     #将"md5"格式化为ext4的文件系统,卷标为"MYDATA",预留给管理员的百分比为3%,块大小为4K
mke2fs 1.41.12 (17-May-2010)
Filesystem label=MYDATA
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
262944 inodes, 1051136 blocks
31534 blocks (3.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1077936128
33 block groups
32768 blocks per group, 32768 fragments per group
7968 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

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

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

6、将"md5"挂载到/mydata目录下,并在配置文件中填写挂载记录,使得开机自动挂载

[root@centos6 ~]# echo -e "`blkid /dev/md5 | cut -d' ' -f3`\t /mydata\t ext4\t defaults\t 0  0" >> /etc/fstab     ##将挂载信息写入到配置文件当中,建议填写UUID,重启电脑后名称会变
[root@centos6 ~]# tail -1 !$     #查看填写的情况
tail -1 /etc/fstab
UUID="9a583c7c-4fe0-4208-a19c-9133c83b112d"	 /mydata	 ext4	 defaults	 0  0
[root@centos6 ~]# mkdir /mydata     #创建挂目录"/mydata"
[root@centos6 ~]# mount -a
[root@centos6 ~]# mount |grep '/dev/md5'     #查看是否已挂载
/dev/md5 on /mydata type ext4 (rw)

7、测试是否可以启动开机挂载

[root@centos6 ~]# reboot     #重启电脑
[root@centos6 ~]# mount     #查看挂载的文件系统
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /testdir type ext4 (rw)
/dev/md127 on /mydata type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@centos6 ~]# mdadm -D /dev/md127     #查看raid情况信息
/dev/md127:
        Version : 1.2
  Creation Time : Sat Aug  6 23:02:18 2016
     Raid Level : raid5     
     Array Size : 4204544 (4.01 GiB 4.31 GB)
  Used Dev Size : 2102272 (2.00 GiB 2.15 GB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Sat Aug  6 23:20:09 2016
          State : clean 
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 256K

           Name : centos6:5  (local to host centos6)
           UUID : 592b4f57:8c5842b2:8b2814b2:f0de1c28
         Events : 22

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1     #显示为之前的三个分区创建的raid5,如需开机自动挂载,需写入配置文件/etc/fstab中
       1       8       33        1      active sync   /dev/sdc1
       3       8       49        2      active sync   /dev/sdd1


三、创建和扩展逻辑卷

1、创建pv卷(10G作为参考)

首先手动给虚拟机添加两块20G的硬盘,接下来创建pv卷

[root@centos6 ~]# echo '- - -' > /sys/class/scsi_host/host2/scan     #通知内核扫描硬盘,如还是没有显示,将host2更改为0或1
[root@centos6 ~]# lsblk     #查看内核是否扫描到添加的硬盘
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom  
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0  200M  0 part /boot
├─sda2   8:2    0 97.7G  0 part /
├─sda3   8:3    0  9.8G  0 part /testdir
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0   20G  0 disk 
sdc      8:32   0   20G  0 disk
[root@centos6 ~]# fdisk /dev/sdb     #对新增的磁盘"sdb"进行分区测试
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x69e6c6bc.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n     #新增一个分区
Command action
   e   extended
   p   primary partition (1-4)
p     #新增的分区选择为主分区
Partition number (1-4): 1
First cylinder (1-2610, default 1):      #直接回车键默认起始柱面为1
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G     #给新增的主分区添加容量为10G

Command (m for help): t     #选择分区类型
Selected partition 1
Hex code (type L to list codes): 8e     #将新增的分区分为8e类型,8e类型为(Linux LVM)
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w     #分区完毕,保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.     #未有显示报警信息,无需使用命令"partx"让内核扫描硬盘分区
Syncing disks.
[root@centos6 ~]# fdisk -l /dev/sdb |tail -2     #查看分区的分区类型
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1306    10490413+  8e  Linux LVM
[root@centos6 ~]# pvcreate /dev/sdb1     #将分区"sdb1"创建为pv卷
  Physical volume "/dev/sdb1" successfully created

2、创建vg卷

[root@centos6 ~]# vgcreate myvg /dev/sdb1     #创建vg卷
  Volume group "myvg" successfully created

3、创建lv卷(逻辑卷)

[root@centos6 ~]# lvcreate -L 2G -n mylv myvg     #创建lv卷,大小为2G,命名为mylv
  Logical volume "mylv" created.
[root@centos6 ~]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a----- 2.00g
[root@centos6 ~]# ls -l /dev/mapper/myvg-mylv     #查看逻辑卷设备名称
lrwxrwxrwx. 1 root root 7 Aug  6 21:09 /dev/mapper/myvg-mylv -> ../dm-0

4、格式化设备"myvg-mylv"为ext4文件系统

[root@centos6 ~]# mkfs -t ext4 /dev/mapper/myvg-mylv     #将设备"myvg-mylv"格式化为ext4文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

5、逻辑卷的扩展与缩减

[root@centos6 ~]# mkdir /mydata     #创建挂载目录"mydata"
[root@centos6 ~]# mount /dev/mapper/myvg-mylv /mydata/     #将逻辑卷"myvg-mylv"挂载到目录"mydata
[root@centos6 ~]# cp /etc/issue /mydata/     #复制文件到该挂载的目录下
[root@centos6 ~]# cat /mydata/issue     #查看内容未有遗漏
CentOS release 6.8 (Final)
Kernel \r on an \m

[root@centos6 ~]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-ao---- 2.00g
[root@centos6 ~]# lvextend -L 5G /dev/mapper/myvg-mylv      #扩展逻辑卷"mylv"的容量到5G
 Size of logical volume myvg/mylv changed from 2.00 GiB (512 extents) to 5.00 GiB (1280 extents).
 Logical volume mylv successfully resized.
[root@centos6 ~]# df -h     #查看逻辑卷"mylv"的容量未有扩展到5G
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              96G  3.5G   88G   4% /
tmpfs                 932M  372K  931M   1% /dev/shm
/dev/sda1             190M   39M  142M  22% /boot
/dev/sda3             9.5G   22M  9.0G   1% /testdir
/dev/mapper/myvg-mylv
                      2.0G  3.1M  1.9G   1% /mydata
[root@centos6 ~]# resize2fs /dev/mapper/myvg-mylv      #将物理卷的容量扩展,未有指明扩展多少,因此按逻辑卷"myvg-mylv"的容量扩展到5G
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/myvg-mylv is mounted on /mydata; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/myvg-mylv to 1310720 (4k) blocks.
The filesystem on /dev/mapper/myvg-mylv is now 1310720 blocks long.

[root@centos6 ~]# df -h     #查看逻辑卷"mylv"的容量是否有扩展到5G
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              96G  3.5G   88G   4% /
tmpfs                 932M  372K  931M   1% /dev/shm
/dev/sda1             190M   39M  142M  22% /boot
/dev/sda3             9.5G   22M  9.0G   1% /testdir
/dev/mapper/myvg-mylv
                      4.9G  4.0M  4.7G   1% /mydata    #已显示扩展到5G
[root@centos6 ~]# umount /dev/mapper/myvg-mylv      #取消挂载  
[root@centos6 ~]# e2fsck -f /dev/mapper/myvg-mylv      #检查文件系统,并且修复
e2fsck 1.41.12 (17-May-2010)
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/mapper/myvg-mylv: 12/655360 files (0.0% non-contiguous), 58672/2621440 blocks
[root@centos6 ~]# resize2fs /dev/mapper/myvg-mylv 2G     #缩减逻辑卷大小为2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/myvg-mylv to 524288 (4k) blocks.
The filesystem on /dev/mapper/myvg-mylv is now 524288 blocks long.
[root@centos6 ~]# lvs     #查看逻辑卷"myvg-mylv"信息
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a----- 5.00g      #显示为5G
[root@centos6 ~]# lvreduce -L 2G /dev/mapper/myvg-mylv      #缩减物理卷的大小为2G
  WARNING: Reducing active logical volume to 2.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce myvg/mylv? [y/n]: y     #确认是否要缩圈,有风险(Tips:实际生产环境中不建议缩减,容易丢失数据)
  Size of logical volume myvg/mylv changed from 3.00 GiB (768 extents) to 2.00 GiB (512 extents).
  Logical volume mylv successfully resized.
[root@centos6 ~]# mount /dev/mapper/myvg-mylv /mydata/     #重新挂载到"/mydata"目录下
[root@centos6 ~]# df -h     #查看逻辑卷"mylv"的容量是否有缩减到2G
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              96G  3.5G   88G   4% /
tmpfs                 932M  372K  931M   1% /dev/shm
/dev/sda1             190M   39M  142M  22% /boot
/dev/sda3             9.5G   22M  9.0G   1% /testdir
/dev/mapper/myvg-mylv
                      2.0G  3.1M  1.9G   1% /mydata     #已显示缩减到2G
[root@centos6 ~]# cat /mydata/issue     #查看逻辑卷myvg-mylv中的内容是否有损,查看内容属于完整性(如果数据占据的磁盘容量大于缩减的容量,数据会有损坏和丢失,建议不缩减,如要缩减,
CentOS release 6.8 (Final)               尽量保持逻辑卷的容量大于数据的容量)
Kernel \r on an \m

原创文章,作者:Aleen,如若转载,请注明出处:http://www.178linux.com/42066

(0)
AleenAleen
上一篇 2016-09-01
下一篇 2016-09-01

相关推荐

  • 马哥教育网络班22期+第1周课程练习

    一、描述计算机的组成及其功能。 组成:CPU (运算器+控制器),存诸器(内存与硬盘),输入设备,输出设备。 运算器:对数据进行加工处理的部件(包括算述运算与逻辑运算)。 控制器:负责从存储器取出指令,按指令的要求发出控制信号,使各部件协调的,一步步的完成各种操作。 存储器:计算机记忆或暂存数据的部件 输入设备:人机接口,负责输入信息(数据与指令)转成计算机…

    Linux干货 2016-08-15
  • shell三剑客之grep

    正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符、及这些特定字符的组合,组成一个“规则字符串”,这个“规则字符串”用来表达对字符串的一种过滤逻辑。 给定一个正则表达式和另一个字符串,我们可以达到如下的目的: 1. 给定的字符串是否符合正则表达式的过滤逻辑(称作“匹配”); 2. 可以通过正则表达式,从字符串中获取我们想要的特定部分。 正…

    Linux干货 2016-08-08
  • 从Linux小白到大牛——与狼共舞的日子11

    马哥教育网络班21期+第10周课程练习 1、详细描述一次加密通讯的过程,结合图示最佳。 加密过程 1.使用单向加密算法,提取A的文件的特征码。 2.使用A的私钥对提取出来的特征码进行加密,把加密后的特征码附加在A的文件的后面。 3.使用对称加密对刚刚的A的文件和加密后的特征码进行加密,生成对称加密密钥 4.使用B的公钥对第3步骤的对称加密的密钥进行加密,加密…

    Linux干货 2016-12-05
  • 马哥教育网络班21期+第6周课程练习

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; [root@localhost ~]# cp /etc/rc.d/rc.sysinit /tmp/ [root@localho…

    Linux干货 2016-08-15
  • 初学Linux之标准 I/O 和管道

    前面我们已经了解了文件系统的部分内容,我们可以通过 ls 命令让当前目录下的内容都显示在屏幕上,也可以使用 pwd 命令,显示当前的所在的目录路径。但是我们输入的是命令,本身并没有输入“显示”这类命令和要求,但是系统就自动的在屏幕上输出我们命令指定的信息。由此可以想象到,系统自身有默认的一种输出方式,同时,有输出就有输入,当输入的和系统无关,系统也会自动提示错误,以上就是我们接下来要了解的基础内容——标准 I/O。具体的涉及内容包括:三种 I/O 设备,把 I/O 重定向入文件,tr 命令的使用,使用管道链接命令。

    2017-12-02
  • 马哥教育第20期一班第一周作业

    一、利用echo将下图弄成闪烁;字体自带颜色且有下滑线? [root@centos7 ~]# echo -e "\033[31m\033[4m\033[5m\0052\0052\0052\0052\0052\0052\0052\n \0052\0052\0052\0052\0052\n &…

    Linux干货 2016-07-29

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-01 15:31

    文章操作性较强,建议能lvm的工作原理进行一个详细的介绍。