system-storage-manager 是红帽RHEL7系统自带的一款存储管理工具 可以简化存储管理

本次实验使用一台Centos7的虚拟机,新添加3块8G的scsi硬盘 通过ssm自动完成lvm的创建 文件系统创建 挂载

[root@localhost ~]# yum -y install system-storage-manager

# 查看本机的存储信息
[root@localhost ~]# ssm list
--------------------------------
Device        Total  Mount point  
--------------------------------
/dev/sda   20.00 GB  PARTITIONED  
/dev/sda1   1.00 GB  /boot        
/dev/sda2   2.00 GB  SWAP         
/dev/sda3  10.00 GB  /            
/dev/sdb    8.00 GB               
/dev/sdc    8.00 GB               
/dev/sdd    8.00 GB               
--------------------------------
-------------------------------------------------------------------
Volume     Volume size  FS    FS size       Free  TypeMount point  
-------------------------------------------------------------------
/dev/sda1      1.00 GB  ext4  1.00 GB  827.75 MB  part/boot        
/dev/sda3     10.00 GB  xfs   9.99 GB    8.74 GB  part/            
-------------------------------------------------------------------
[root@localhost ~]# ls /media/
cdrom  lv1  lv2

# 使用 sd{b..d} 创建vg0/lv1 并格式化为 xfs 挂载到 /media/lv1 

[root@localhost ~]# ssm create -s 400M -n lv1 -p vg0 --fstype xfs /dev/sd{b..d} /media/lv1
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdc" successfully created.
  Physical volume "/dev/sdd" successfully created.
  Volume group "vg0" successfully created
  Logical volume "lv1" created.
meta-data=/dev/vg0/lv1           isize=512    agcount=4, agsize=25600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=102400, 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@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda3             10G  1.3G  8.8G  13% /
/dev/sda1            976M   97M  812M  11% /boot
/dev/mapper/vg0-lv1  397M   21M  377M   6% /media/lv1

# 扩容 /dev/vg0/lv1 增加60M
[root@localhost ~]# ssm resize -s +60M vg0/lv1
  Size of logical volume vg0/lv1 changed from 400.00 MiB (100 extents) to 460.00 MiB (115 extents).
  Logical volume vg0/lv1 successfully resized.

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda3             10G  1.3G  8.8G  13% /
/dev/sda1            976M   97M  812M  11% /boot
/dev/mapper/vg0-lv1  457M   21M  437M   5% /media/lv1

# 创建一个vg0/lv1 的逻辑卷大小200M 使用ext4文件系统 挂载到 /media/lv2

[root@localhost ~]# ssm create -s 200M -n lv2 --fstype ext4 -p vg0 /media/lv2
  Logical volume "lv2" created.
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
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

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

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/sda3             10G  1.3G  8.8G  13% /
/dev/sda1            976M   97M  812M  11% /boot
/dev/mapper/vg0-lv1  457M   21M  437M   5% /media/lv1
/dev/mapper/vg0-lv2  190M  1.6M  175M   1% /media/lv2

# vg0/lv2 缩小 40M 如果没有卸载会提示卸载处理完后会自动挂载
[root@localhost ~]# ssm resize -s-40M vg0/lv2
Do you want to unmount "/media/lv2" ? [Y|n] y
fsck from util-linux 2.23.2
/dev/mapper/vg0-lv2: 11/51200 files (0.0% non-contiguous), 12115/204800 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg0-lv2 to 163840 (1k) blocks.
The filesystem on /dev/mapper/vg0-lv2 is now 163840 blocks long.

  Size of logical volume vg0/lv2 changed from 200.00 MiB (50 extents) to 160.00 MiB (40 extents).
  Logical volume vg0/lv2 successfully resized.
[root@localhost ~]# lvs
  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv1  vg0 -wi-ao---- 460.00m                                                  
  lv2  vg0 -wi-ao---- 160.00m          

[root@localhost ~]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/sda3           xfs        10G  1.3G  8.8G  13% /
/dev/sda1           ext4      976M   97M  812M  11% /boot
/dev/mapper/vg0-lv1 xfs       457M   21M  437M   5% /media/lv1
/dev/mapper/vg0-lv2 ext4      151M  1.6M  139M   2% /media/lv2

删除创建的 lvm vg pv

[root@localhost ~]# ssm remove -h
usage: ssm remove [-h] [-a] [items [items ...]]

positional arguments:
  items       Items to remove. Item could be device, pool, or volume.

optional arguments:
  -h, --help  show this help message and exit
  -a, --all   Remove all pools in the system.
[root@localhost ~]# ssm remove vg0/lv1 vg0/lv2
Do you really want to remove active logical volume vg0/lv1? [y/n]: y
  Logical volume "lv1" successfully removed
Do you really want to remove active logical volume vg0/lv2? [y/n]: y
  Logical volume "lv2" successfully removed
[root@localhost ~]# ssm remove vg0
  Volume group "vg0" successfully removed
[root@localhost ~]# ssm remove /dev/sd{b..d}
SSM Info: Unable to remove '/dev/sdb'
SSM Info: Unable to remove '/dev/sdc'
SSM Info: Unable to remove '/dev/sdd'
SSM Error (2001): Nothing was removed!
[root@localhost ~]# pvremove /dev/sd{b..d}
  Labels on physical volume "/dev/sdb" successfully wiped.
  Labels on physical volume "/dev/sdc" successfully wiped.
  Labels on physical volume "/dev/sdd" successfully wiped.