零距離接觸軟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.www58058.com/42066

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

相關推薦

  • 銘記今天

        2016年10月19日,我做了一個很艱難的決定,選擇了馬哥24期網絡全程班,就算是沖動也好,無論對錯都要堅持下去。 從出來工作之后,一直做銷售這塊,雖然跟電腦有關,但是其中的艱苦只有自己明白。慢慢的年級上來了,手中沒有什么技術,做人生活,總覺得少了什么,總覺得自己以后會被社會淘汰,心一天一天著急。在后選擇了一個從來都沒有涉及的運維…

    Linux干貨 2016-10-19
  • Linux基礎之權限管理(含SUID\SGID\STICKY和ACL)

    概述     Linux系統是一個多人多任務的操作系統,系統上同時可能有很多人登錄,每個人都會利用系統上的各類資源完成一定的操作。那么如何合理的規范這些用戶的行為,保證資源的合理分配,則就需要用到權限管理的相關內容了。權限管理是Linux系統上最基礎,也是最重要的一部分內容,本章就簡要說明下權限管理的相關內容。內容主要…

    Linux干貨 2016-08-04
  • 二進制安裝mysql(mariadb)

    實驗環境: ~]# lsb_release -a Distributor ID: CentOSDescription: CentOS Linux release 7.4.1708 (Core)Release: 7.4.1708Codename: Core 去官方下載mariadb: https://downloads.mariadb.org/ 本人將自己的文…

    2018-01-22
  • Shell編程 詳解特殊變量之位置參數

    今天我們來探討shell編程的特殊變量:位置變量。 首先我創建了一個testargs.sh的小腳本: #!/usr/bin/env bash # # Author: jacky18676887374@aliyun.com # date: 20160813-19:30:59 # Vervion:&nb…

    Linux干貨 2016-08-15
  • 常用RAID級別介紹

    RAID是什么         磁盤陣列(Redundant Arrays of Independent Disks,RAID),磁盤陣列是將多個價格便宜的磁盤按照一定的組合方式組成具有高容量的磁盤組,按照不同的組合方式可以達到不同的效果,如:可以提升磁盤的存取效率,可提高磁盤的…

    Linux干貨 2016-02-14
  • N25期–第十三周作業

    1、 建立samba共享,共享目錄為/data,要求:(描述完整的過程)  1)共享名為shared,工作組為magedu;  2)添加組develop,添加用戶gentoo,centos和ubuntu,其中gentoo和centos以develop為附加組,ubuntu不屬于develop組;密碼均為用戶名;  3)添加sam…

    Linux干貨 2017-04-05

評論列表(1條)

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

    文章操作性較強,建議能lvm的工作原理進行一個詳細的介紹。

欧美性久久久久