LVM逻辑卷操作(PV、VG、LV及XFS的扩容)-实验笔记

LVM作为操作非常灵活的磁盘操作模式,还是有必要熟练的。

ENV:

[root@centos7 ~]# uname -r
3.10.0-514.el7.x86_64
[root@centos7 ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
[root@centos7 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0    5G  0 disk 
sdb           8:16   0    5G  0 disk 
sdc           8:32   0    5G  0 disk 
sdd           8:48   0    5G  0 disk 
sde           8:64   0    5G  0 disk 
sdf           8:80   0    5G  0 disk 
sdg           8:96   0    5G  0 disk 
sdh           8:112  0    8G  0 disk 
├─sdh1        8:113  0    1G  0 part /boot
└─sdh2        8:114  0    7G  0 part 
  ├─cl-root 253:0    0  6.2G  0 lvm  /
  └─cl-swap 253:1    0  820M  0 lvm  [SWAP]
sr0          11:0    1 1024M  0 rom 

上面的ENV为系统环境,为了操作LVM,下面还要进行卷操作,以加深操作。

整个过程为PVcreate->VGcreate—>LVcreate:

[root@centos7 ~]# pvcreate /dev/sda
  Physical volume "/dev/sda" successfully created.
[root@centos7 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@centos7 ~]# vgcreate vgsys /dev/sda /dev/sdb    
  Volume group "vgsys" successfully created
[root@centos7 ~]# vgdisplay 
  --- Volume group ---
  VG Name               vgsys
  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               9.99 GiB
  PE Size               4.00 MiB
  Total PE              2558
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2558 / 9.99 GiB
  VG UUID               T2eygA-LOhE-zjMo-Ocrc-pnI2-l7as-20WMxA
   
  --- Volume group ---
  VG Name               cl
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               7.00 GiB
  PE Size               4.00 MiB
  Total PE              1791
  Alloc PE / Size       1791 / 7.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               XDjUdW-Lk2W-dLnv-ErFe-YPq4-vPTk-VDrqmH
   
[root@centos7 ~]# lvcreate -n lvsys -L 500M vgsys 
  Logical volume "lvsys" created.
[root@centos7 ~]# mkfs.xfs -f /dev/vgsys/lvsys 
meta-data=/dev/vgsys/lvsys       isize=512    agcount=4, agsize=32000 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=128000, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos7 ~]# lvdisplay /dev/vgsys/lvsys 
  --- Logical volume ---
  LV Path                /dev/vgsys/lvsys
  LV Name                lvsys
  VG Name                vgsys
  LV UUID                JzBZCe-oLME-GZ29-Xed4-2KOj-xh9l-boYEJN
  LV Write Access        read/write
  LV Creation host, time centos7, 2019-05-09 18:39:47 +0800
  LV Status              available
  # open                 0
  LV Size                500.00 MiB
  Current LE             125
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
[root@centos7 ~]# mkdir /mnt/LVM
[root@centos7 ~]# echo "/dev/vgsys/lvsys /mnt/LVM xfs defaults 0 0" >> /etc/fstab
[root@centos7 ~]# mount -a
 

到此,前期的卷操作完成,任务环境也布置完成。

1.扩展卷:

[root@centos7 ~]# resize2fs /dev/vgsys/lvsys 
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/vgsys/lvsys
Couldn't find valid filesystem superblock.

出现错误了,有没有,最高兴的就是看到错误了,这样才有意思^V^.

其实最新的xfs格式分区不能使用resize2fs了,而是有专用的xfs_grows

[root@centos7 ~]# xfs_growfs -h
xfs_growfs: invalid option -- 'h'
Usage: xfs_growfs [options] mountpoint

Options:
        -d          grow data/metadata section
        -l          grow log section
        -r          grow realtime section
        -n          don't change anything, just show geometry
        -i          convert log from external to internal format
        -t          alternate location for mount table (/etc/mtab)
        -x          convert log from internal to external format
        -D size     grow data/metadata section to size blks
        -L size     grow/shrink log section to size blks
        -R size     grow realtime section to size blks
        -e size     set realtime extent size to size blks
        -m imaxpct  set inode max percent to imaxpct
        -V          print version information

换这个命令再操作一次:

[root@centos7 ~]# xfs_growfs /dev/vgsys/lvsys 
xfs_growfs: /dev/vgsys/lvsys is not a mounted XFS filesystem

还出错,不过这次提示的就明显了,说是没有挂载,那挂载试试:

[root@centos7 ~]# mount /dev/vgsys/lvsys /mnt/LVM/
[root@centos7 ~]# xfs_growfs /dev/vgsys/lvsys 
meta-data=/dev/mapper/vgsys-lvsys isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1310720 to 1835008

这次操作成功了,找了下xfs_growfs的man文档,其中写有这个xfs是支持挂载操作的,真的是很方便啊


xfs_growfs(8)               System Manager's Manual              xfs_growfs(8)

NAME
       xfs_growfs, xfs_info - expand an XFS filesystem

SYNOPSIS
       xfs_growfs  [  -dilnrx  ] [ -D size ] [ -e rtextsize ] [ -L size ] [ -m
       maxpct ] [ -t mtab ] [ -R size ] mount-point
       xfs_growfs -V

       xfs_info [ -t mtab ] mount-point
       xfs_info -V

DESCRIPTION
       xfs_growfs expands an existing XFS filesystem (see xfs(5)).  The mount-
       point argument is the pathname of the directory where the filesystem is
       mounted. The filesystem must be mounted to  be  grown  (see  mount(8)).
       The  existing contents of the filesystem are undisturbed, and the added
       space becomes available for additional file storage.

学习Linux要善于看man文档,系统命令都可以在这个帮助文档中找到详细的说明和应用。

那有没有缩小呢??

[root@centos7 ~]# xfs  //xfs后直接tab补齐,可以看到下面列的所有xfs命令,可以看到是没有缩小了
xfs_admin      xfs_estimate   xfsinvutil     xfs_mkfile     xfs_rtcp
xfs_bmap       xfs_freeze     xfs_io         xfs_ncheck     
xfs_copy       xfs_fsr        xfs_logprint   xfs_quota      
xfs_db         xfs_growfs     xfs_mdrestore  xfs_repair     
xfsdump        xfs_info       xfs_metadump   xfsrestore 

没发现有缩小的操作,但不排除其他方法,但可能性可能小些,毕竟以后都是向大容量扩容的,已经不再和以前的文件系统一样支持缩小功能了,就不再找了。

2.删除卷

有安装就有删除了,go on!

[root@centos7 ~]# umount /dev/vgsys/lvsys 
[root@centos7 ~]# lvremove /dev/vgsys/lvsys 
Do you really want to remove active logical volume vgsys/lvsys? [y/n]: y
  Logical volume "lvsys" successfully removed
[root@centos7 ~]# vgremove vgsys 
  Volume group "vgsys" successfully removed
[root@centos7 ~]# pvremove /dev/sda /dev/sdb
  Labels on physical volume "/dev/sda" successfully wiped.
  Labels on physical volume "/dev/sdb" successfully wiped.

好了,操作完成了。

你可能感兴趣的:(Linux)