一、扩展卷组

扩展卷组相对简单,只需要添加一个物理卷即可,使用的命令是vgextend其格式为:

vgextend VG_NAME /PATH/TO/PV

下面来演示一下扩展卷组的过程:

 

1. 首先准备一块id号位8e的分区,具体过程见前文。

[root@localhost ~]# fdisk/dev/sdc

WARNING: DOS-compatible mode is deprecated. It's stronglyrecommended to
         switch offthe mode (command 'c') and change display units to
         sectors(command 'u').
Command (m for help): p
Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xb8ee6343
   Device Boot      Start         End      Blocks  Id  System
/dev/sdc1              1         654     5253223+ 8e  Linux LVM
/dev/sdc2             655         786    1060290   fd  Linux raid autodetect
/dev/sdc3            787         918     1060290  8e  Linux LVM
/dev/sdc4            919        1305     3108577+  5  Extended
/dev/sdc5            919        1050     1060258+ 8e  Linux LVM
# 选择/dev/sdc5作为物理卷
/dev/sdc6           1051        1182     1060258+ 83  Linux
/dev/sdc7           1183        1305      987966  83  Linux

 

[root@localhost ~]# vgs

# 查看当前的卷组信息
  VG       #PV #LV #SN Attr   VSize VFree
  VolGroup   1  2   0 wz--n- 24.51g    0
  testvg     2  1   0 wz--n-  2.02g 1.02g

2. 为卷组添加物理卷

[root@localhost ~]# vgextendtestvg /dev/sdc5 

No physical volumelabel read from /dev/sdc5
  Physical volume/dev/sdc5 not found
  Physical volume"/dev/sdc5" successfully created
  Volume group"testvg" successfully extended
# 提示卷组扩展成功


[root@localhost ~]# vgs 

VG       #PV #LV #SN Attr   VSize VFree
  VolGroup   1  2   0 wz--n- 24.51g    0
  testvg     3  1   0 wz--n-  3.02g 2.02g
# 当前卷组的大小多了1G


 

到这里VG的扩展就完成了。

VG的扩展不会影响LV的使用,现在我们可以查看一下以前LV中存放的文件:

[root@localhost ~]# cat/mnt/fstab

# /etc/fstab
# Created by anaconda on Wed Jul  9 21:21:40 2014
#
# Accessible filesystems, by reference, are maintained under'/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/orblkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                     ext4   defaults   1 1
UUID=d9512fb3-8dd6-4613-ae55-8e99ba0ef627 /boot   ext4  defaults    1 2
/dev/mapper/VolGroup-lv_swap swap                 swap  defaults   0 0
tmpfs                  /dev/shm                tmpfs   defaults  0 0
# LV中的文件可以照常访问


 

二、缩减卷组

缩减卷组的操作也很容易,要缩减之前,需要先确定要移除的PV,然后使用pvmove命令将此PV上的数据转移至其他的PV,最后使用命令vgreduce从卷组中移除此PV

其中pvmove的基本使用格式为:

pvmove/Path/From/Where [/PATH/To/Where]

如果不指定要移到哪个物理卷上,则会自动分配。

命令 vgreduce的用法格式如下:

vgreduceVG_NAME PV_NAME

现在觉得testvg太大了,想要缩减其体积,可以进行以下操作:

 

1. 首先来查看一下当前卷组的物理卷构成情况

[root@localhost ~]# pvs 

PV         VG       Fmt Attr PSize  PFree
  /dev/sda2  VolGroup lvm2 a--  24.51g   0
  /dev/sdc3  testvg  lvm2 a--   1.01g 8.00m
  /dev/sdc5  testvg  lvm2 a--   1.01g 1.01g
  /dev/sdd3  testvg  lvm2 a--   1.01g 1.01g
# 可以看到卷组testvg由三个物理卷构成


 2. 将要移除的物理卷上的数据转移到其他PV

[root@localhost ~]# pvmove/dev/sdc3 

/dev/sdc3: Moved:1.2%
  /dev/sdc3: Moved:21.9%
  /dev/sdc3: Moved:42.2%
  /dev/sdc3: Moved:62.5%
  /dev/sdc3: Moved:82.8%
  /dev/sdc3: Moved:100.0%

 

3. 使用命令vgreduce移除物理卷

[root@localhost ~]# vgreducetestvg /dev/sdc3 

Removed"/dev/sdc3" from volume group "testvg"
# 提示移除了/dev/sdc3

[root@localhost ~]# vgs 

VG       #PV #LV #SN Attr   VSize VFree
  VolGroup   1  2   0 wz--n- 24.51g    0
  testvg     2  1   0 wz--n-  2.02g 1.02g
# 再次查看VG,可以发现它又还原成2G了


[root@localhost ~]# pvremove/dev/sdc3

  Labels on physicalvolume "/dev/sdc3" successfully wiped
 # 当完成了移除工作后,就可以删除这个PV了

 

注意,移除物理卷和删除物理卷的是两种不同的操作,vgreduce是从指定卷组中移除物理卷,pvremove是将某一个物理卷从当前系统的可用物理卷列表中删除

 

[root@localhost ~]# pvs 

PV         VG       Fmt Attr PSize  PFree
  /dev/sda2  VolGroup lvm2 a--  24.51g   0
  /dev/sdc5  testvg  lvm2 a--   1.01g 1.01g
  /dev/sdd3  testvg  lvm2 a--   1.01g 8.00m
# 删除了物理卷/dev/sdc3之后,将不会再物理卷列表中显示该物理卷


 

注意,尽管缩减VG非常容易,但切记在移除物理卷之前,一定要将该物理卷上的数据移动到同一卷组中的其他物理卷上

 

三、扩展逻辑卷

所谓扩展逻辑卷,其实就是给现有的逻辑卷分配一些新的物理盘区(PE),而分配新PE就意味着为该逻辑卷扩展其物理边界,但是尽管物理边界扩展了,其逻辑边界不会自动扩展,故需要手动扩展。注意,扩展逻辑卷的顺序为先扩展物理边界,再扩展逻辑边界;而缩小逻辑卷的顺序与之相反。

wKiom1P2DNyS91tWAAB9Y_PE3Y8426.png

扩展逻辑卷的主要步骤可以概括为:

1.确定要扩展多大

2.确定当前逻辑卷所在的卷组有足够的空间可用

3.扩展逻辑卷

i.         先扩展物理边界

和扩展卷组的方式向类似,使用命令lvextend来进行扩展,其基本格式为:

lvextend -L [+]SIZE /Path/To/LV

注意,这里的加号+是可选的,但是否使用加号表示的意义是不同的

带上加号+表示表示扩展多大

不带加号表示表示扩展多大

ii.       再扩展逻辑边界

扩展逻辑边界使用的命令是resize2fs,其基本格式为:

resize2fs /Path/To/Device

该命令会自动将要扩展的LV的逻辑边界扩展到其物理边界

下面来演示扩展逻辑卷的具体操作过程:


1. 确定要扩展多大

[root@localhost ~]# lvs

# 查看逻辑卷的大小,现在想将mylv的大小扩展为2G
  LV      VG      Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root VolGroup-wi-ao---- 22.54g                                             
  lv_swap VolGroup-wi-ao----  1.97g                                            
  mylv    testvg  -wi-ao----  1.00g

 

2. 确定当前逻辑卷所在的卷组有足够的空间可用

现在想扩展逻辑卷mylv,但是在扩展之前,需要确定是卷组中是否有足够的空间,故可以查看卷组的大小:

[root@localhost ~]# vgs 

VG       #PV #LV #SN Attr   VSize VFree
  VolGroup   1  2   0 wz--n- 24.51g    0
  testvg     2  1   0 wz--n-  2.02g 1.02g
# 可以看到卷组testvg的总大小为2G,空闲空间为1.02G,可以提供足够的空间让mylv进行扩展

3. 扩展逻辑卷

[root@localhost ~]# lvextend -L+1G /dev/testvg/mylv

# 这里也可以写成 lvextend -L 2G /dev/testvg/mylv 
 Extending logicalvolume mylv to 2.00 GiB
  Logical volume mylvsuccessfully resized
# 提示成功扩展逻辑卷mylv


 虽然提示成功扩展了逻辑卷,但该逻辑卷的可用空间是否真的已经达到2G了呢?可以使用df命令来查看一下:

[root@localhost ~]# df -lh

Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   23G 4.6G   17G  22% /
tmpfs                        499M  112K  499M  1% /dev/shm
/dev/sda1                    485M   35M  426M  8% /boot
/dev/sdb3                    9.9G   36M  9.7G  1% /mydata
/dev/mapper/testvg-mylv     1008M   34M  924M  4% /mnt
# 这里发现逻辑卷mylv的可用空间仍然为1G

 

之所以mylv的可用空间仍为1G,是因为之前扩展的只是物理边界,所以使用resize2fs来对其逻辑边界进行扩展:

[root@localhost ~]# resize2fs/dev/testvg/mylv

resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/testvg/mylv is mounted on /mnt; on-lineresizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/testvg/mylv to 524288(4k) blocks.
The filesystem on /dev/testvg/mylv is now 524288 blockslong.
# 提示在线扩展逻辑卷到524288个块

 

现在再使用df命令来查看一下mylv的可用空间:

[root@localhost ~]# df -lh

Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   23G 4.6G   17G  22% /
tmpfs                        499M  112K  499M  1% /dev/shm
/dev/sda1                    485M   35M  426M  8% /boot
/dev/sdb3                     9.9G   36M 9.7G   1% /mydata
/dev/mapper/testvg-mylv      2.0G   34M  1.9G  2% /mnt
# 现在mylv的可用空间是2G了

 

[root@localhost ~]# cat/mnt/fstab

# /etc/fstab
# Created by anaconda on Wed Jul  9 21:21:40 2014
#
# Accessible filesystems, by reference, are maintained under'/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/orblkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                                         ext4   defaults      1 1
UUID=d9512fb3-8dd6-4613-ae55-8e99ba0ef627 /boot   ext4   defaults      1 2
/dev/mapper/VolGroup-lv_swap swap                 swap   defaults     0 0
# 在线扩展逻辑卷的大小,不会影响其正常使用

 

4 .文件系统检测

扩展LV可能会对文件系统造成损害,故最好在扩展完成了之后,对文件系统进行检测,对文件系统进行检测的命令为fscke2fsck。其中fsck检测所有的文件系统,而e2fsck只检测ext2系列的文件系统。命令e2fsck使用的选项主要有:

-t指定要检测的文件系统类型

-a 与用户交互时自动回答为yes

-f 强行进行检测

-p自动修复

它的基本格式为:

e2fsck[-t FS_Type] [-f] [-p] /Path/to/device

 

现在对刚扩展过的逻辑卷mylv进行检测:

[root@localhost ~]# e2fsck/dev/testvg/mylv

e2fsck 1.41.12 (17-May-2010)
/dev/testvg/mylv is mounted.
e2fsck: Cannot continue, aborting.
# 这里提示逻辑卷被挂载了

 

要检测逻辑卷之前,需要先将其卸载,然后再进行检测:

[root@localhost ~]# umount /mnt

[root@localhost ~]# e2fsck/dev/testvg/mylv

e2fsck 1.41.12 (17-May-2010)
/dev/testvg/mylv: clean, 12/131072 files, 16813/524288blocks
# 这里提示逻辑卷mylv是clean的,说明该逻辑卷运作正常

 

四、逻辑卷的缩减

逻辑卷的缩减是有风险的,其主要步骤为:

1.确定缩减的大小:必须确保逻辑卷中存放的数据,不会超过缩减后的大小。如要将10G的逻辑卷缩减到5G,就必须确保该逻辑卷中现有数据的大小不超过5G

2.缩减逻辑卷

i.         卸载并强行检测文件系统:因为缩减逻辑卷是非常有风险的操作,故必须先检测文件系统

e2fsck -f

注意,如果文件系统不是ext系列的,则需要使用其他工具

ii.       先缩减逻辑边界,它使用的命令格式为:

resize2fs /Path/to/Device SIZE

注意,扩展不需要指定大小,会自动扩展到物理边界,但是缩减必须指定大小

iii.     再缩减物理边界,它使用的命令是:

lvreduce-L [-]SIZE /Path/To/LV

和加号类似,带不带减号意义会有所不同;

带上减号-表示表示缩减多大

不带减号-表示表示缩减多大

 

下面来演示缩减逻辑卷mvlv1G的具体操作过程:

1.卸载逻辑卷

[root@localhost ~]# umount /mnt

[root@localhost ~]# mount

/dev/mapper/VolGroup-lv_root 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/sdb3 on /mydata type ext4 (rw,noatime)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
# 不论是否挂载了,都使用umont命令以确保卸载了设备

 

2.强行检测

[root@localhost ~]# e2fsck -f/dev/testvg/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/testvg/mylv: 12/131072 files (0.0% non-contiguous),16813/524288 blocks

 

3.缩减逻辑边界

[root@localhost ~]# resize2fs/dev/testvg/mylv 1G

# 缩减逻辑卷需要明确指定大小
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/testvg/mylv to 262144 (4k)blocks.
The filesystem on /dev/testvg/mylv is now 262144 blockslong.

 

4.缩减物理边界

[root@localhost ~]# lvreduce -L1G /dev/testvg/mylv 

WARNING: Reducingactive logical volume to 1.00 GiB
  THIS MAY DESTROYYOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
# 缩减有风险,操作需谨慎
  Reducing logicalvolume mylv to 1.00 GiB
  Logical volume mylvsuccessfully resized

 

5.再次检测

[root@localhost ~]# e2fsck -f/dev/testvg/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/testvg/mylv: 12/65536 files (0.0% non-contiguous),12636/262144 blocks

 

6.重新挂载设备

[root@localhost ~]# mount/dev/testvg/mylv /mnt

[root@localhost ~]# cd /mnt

[root@localhost mnt]# ls

fstab  lost+found

[root@localhost mnt]# cat fstab

# /etc/fstab
# Created by anaconda on Wed Jul  9 21:21:40 2014
# Accessible filesystems, by reference, are maintained under'/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/orblkid(8) for more info
/dev/mapper/VolGroup-lv_root /                    ext4    defaults    1 1
UUID=d9512fb3-8dd6-4613-ae55-8e99ba0ef627 /boot  ext4   defaults     1 2
/dev/mapper/VolGroup-lv_swap swap                swap   defaults    0 0
tmpfs                  /dev/shm               tmpfs   defaults    0 0
# 逻辑卷中原来存放的文件可以正常访问


[root@localhost mnt]# df -lh

Filesystem                    Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   23G 4.6G   17G  22% /
tmpfs                        499M  112K  499M  1% /dev/shm
/dev/sda1                    485M   35M  426M  8% /boot
/dev/sdb3                    9.9G   36M  9.7G  1% /mydata
/dev/mapper/testvg-mylv     1008M   34M  924M  4% /mnt
# 逻辑卷mylv的大小已经缩减到1G了


       至此,缩减逻辑卷的操作就完成了,可以看到,不论是扩展还是缩减逻辑卷,都不会影响其中的文件的正常使用。

 

五、创建快照卷

    前文中提到过,快照卷具有文本备份的功能。创建快照卷的基本操作和创建逻辑卷很类似,只不过在使用lvcreate命令的时候使用-s(表示snapshot)选项,并且创建快照卷不需要指定卷组,因为创建快照卷必然是针对某个逻辑卷进行的操作,故快照卷一定和原卷在同一个原卷中。

注意不应该对快照卷中的文件进行修改(写入操作),因为快照卷只是原卷的一个访问通道,因此在创建快照卷时使用-p选项,将其限定为只读访问。故创建快照卷的基本格式为:

lvcreate-L SIZE -s -p -n LV_NAME /Path/to/LV

 

现在演示创建快照卷的过程:

[root@localhost mnt]# cp/etc/inittab ./

[root@localhost mnt]# ls

fstab  inittab  lost+found
# 先复制一个文件到要创建快照卷的逻辑卷中以备使用

 

1.预估快照卷的大小

假设现在这个快照卷只在2个小时中使用,而两个小时里的数据变化量不会超过50MB,所以可以将快照卷的大小设定为50MB

2.创建快照卷

[root@localhost ~]# lvcreate -L50M -s -p r -n mylv-snap /dev/testvg/mylv

# 创建一个50MB的快照卷
# 其访问权限为只读
# 该快照卷的卷名为mylv-snap
# 该快照卷是针对/dev/testvg/mylv创建的 
Rounding up size to full physical extent 52.00 MiB
  Logical volume"mylv-snap" created

[root@localhost ~]# ls/dev/testvg

mylv  mylv-snap

[root@localhost ~]# lvs 

LV        VG      Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root   VolGroup -wi-ao---- 22.54g                                            
  lv_swap   VolGroup -wi-ao----  1.97g                                            
  mylv      testvg  owi-aos---  1.00g                                            
  mylv-snaptestvg   sri-a-s--- 52.00m      mylv    0.02
# 原卷中的数据占快照卷的0.02%

 

3.挂载使用快照卷

[root@localhost ~]# mount -o ro/dev/testvg/mylv-snap /media

# 
由于快照卷是只读的,故以只读方式将该快照卷挂载到
/media
下


[root@localhost ~]# cd /media

[root@localhost media]# ls

fstab  inittab  lost+found
# 它和/mnt下(原卷)中的文件是一样的


[root@localhost media]# mount

/dev/mapper/VolGroup-lv_root 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/sdb3 on /mydata type ext4 (rw,noatime)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/testvg-mylv on /mnt type ext4 (rw)
/dev/mapper/testvg-mylv--snap on /media type ext4 (ro)

 

[root@localhost media]# catinittab

# inittab is only used by upstart for the default runlevel.
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ONYOUR SYSTEM.
# System initialization is started by /etc/init/rcS.conf
# Individual runlevels are started by /etc/init/rc.conf
# Ctrl-Alt-Delete is handled by/etc/init/control-alt-delete.conf
# Terminal gettys are handled by /etc/init/tty.conf and/etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
# For information on how to write upstart event handlers, orhow
# upstart works, see init(5), init(8), and initctl(8).
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOTset initdefault to this)
#   1 - Single usermode
#   2 - Multiuser,without NFS (The same as 3, if you do not have networking)
#   3 - Full multiusermode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOTset initdefault to this)
id:5:initdefault:

 

现在修改原卷/mnt中的inittab

[root@localhost ~]# cd /mnt

[root@localhost mnt]# viminittab

# inittab is only used by upstart for the default runlevel.
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ONYOUR SYSTEM.
# System initialization is started by /etc/init/rcS.conf
# Individual runlevels are started by /etc/init/rc.conf
# Ctrl-Alt-Delete is handled by/etc/init/control-alt-delete.conf
# Terminal gettys are handled by /etc/init/tty.conf and/etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
# For information on how to write upstart event handlers, orhow
# upstart works, see init(5), init(8), and initctl(8).
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOTset initdefault to this)
#   1 - Single usermode
#   2 - Multiuser,without NFS (The same as 3, if you do not have networking)
#   3 - Full multiusermode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOTset initdefault to this)
id:5:initdefault:
New Line
# 新增了一行 New Line

 

这时再查看快照卷中的/media/inittab:

[root@localhost mnt]# cat/media/inittab

# inittab is only used by upstart for the default runlevel.
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ONYOUR SYSTEM.
# System initialization is started by /etc/init/rcS.conf
# Individual runlevels are started by /etc/init/rc.conf
# Ctrl-Alt-Delete is handled by/etc/init/control-alt-delete.conf
# Terminal gettys are handled by /etc/init/tty.conf and/etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
# For information on how to write upstart event handlers, orhow
# upstart works, see init(5), init(8), and initctl(8).
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOTset initdefault to this)
#   1 - Single usermode
#   2 - Multiuser,without NFS (The same as 3, if you do not have networking)
#   3 - Full multiusermode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOTset initdefault to this)
id:5:initdefault:
# 并没有新增的那一行


 现在再复制一个文件到/mnt下:

[root@localhost mnt]# cp/etc/rc.d/init.d/functions ./

[root@localhost mnt]# ls

fstab  functions  inittab lost+found
# 在/mnt下可以看到刚刚复制过来的文件

 

再来查看一下快照卷中的情况:

[root@localhost ~]# cd /media

[root@localhost media]# ls

fstab  inittab  lost+found
# 快照卷中并没有刚才复制到原卷中的functions文件


    由此可以确定快照卷一定是访问的过去某个时间点的文件,其作用是对某个时间点的文件进行备份,当备份使用完成后,就可以将其删除了,故可以将刚才的快照卷进行备份:

[root@localhost media]# tar Jcf/tmp/backup.tar.xz /media/{fstab,inittab}

tar: Removing leading `/' from member names

 

这里只是备份的某一个时刻的数据,如果在该时刻之后数据又发生了修改,则不会备份之后的数据,以后进行数据恢复,也只能恢复到该时刻的状态。如果要备份此后发生改变的数据,则需要用到其他的手段了。

如果使用的是RAID1来备份数据,仍然需要备份数据,因为RAID1只是在某一块盘坏掉的时候仍保证提供服务,即只是保证不会因为硬件损坏而导致数据丢失,并不能代替数据备份。

 

[root@localhost media]# ls /tmp

backup.tar.xz  keyring-r5HZ7n  keyring-xva5ss  pulse-uP5T8Y6V6nIN  virtual-root.qTocN3
# 已经可以看到备份的快照卷了
keyring-bgxXAq keyring-Xi9NCS  orbit-gdm       pulse-yCmeAwocSW1U  virtual-root.U25Mim

[root@localhost media]# cd

[root@localhost ~]# umount/media

 

卸载快照卷之后,就可以移除逻辑卷了

 

六、移除逻辑卷、快照卷、卷组和物理卷

移除逻辑卷和快照卷的方法一样,只要确定某个逻辑卷或快照卷已经没有用了,并且确定该逻辑卷或快照卷已经被卸载了,就可以将其移除。它使用的命令是格式为:

lvremove Path/To/LV_NAME

 

现在移除快照卷mylv-snap

[root@localhost ~]# lvremove/dev/testvg/mylv-snap

Do you really want to remove active logical volumemylv-snap? [y/n]: y
# 移除任何一种卷都是有风险的操作,都会有相应的警告信息
Logical volume "mylv-snap" successfully removed

 

[root@localhost ~]# lvs 

LV      VG      Attr   LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root VolGroup-wi-ao---- 22.54g                                            
  lv_swap VolGroup-wi-ao----  1.97g                                            
  mylv    testvg  -wi-ao----  1.00g
# 已经没有mylv-snap的信息了


 

现在移除逻辑卷mvlv

[root@localhost ~]# umount /mnt

# 要移除逻辑卷之前,必须先卸载逻辑卷
umount: /mnt: device is busy.
        (In some casesuseful info about processes that use
         the device isfound by lsof(8) or fuser(1))
# 由于逻辑卷正在被访问,故无法卸载

 

[root@localhost ~]# fuser -v/mnt

USER        PIDACCESS      COMMAND
/mnt:               root       9445 ..c.. Bash
# 查看正在访问逻辑卷的用户

 

[root@localhost ~]# fuser -km/mnt

/mnt:                9445c
# 强制剔除用户

 

[root@localhost ~]# umount /mnt

# 成功卸载设备


[root@localhost ~]# lvremove/dev/testvg/mylv

Do you really want to remove active logical volume mylv?[y/n]: y
  Logical volume"mylv" successfully removed
# 成功移除逻辑卷mylv


[root@localhost ~]# lvs 

LV    VG      Attr   LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root VolGroup-wi-ao---- 22.54g                                            
  lv_swap VolGroup-wi-ao---- 1.97g 
# 已经没有逻辑卷mylv的信息了

 

移除了逻辑卷之后,就可以移除卷组了,移除卷组使用的命令格式为:

vgremoveVG_NAME

下面移除卷组testvg                                 

[root@localhost ~]# vgremovetestvg 

 Volume group"testvg" successfully removed

 

[root@localhost ~]# vgs 

VG       #PV #LV #SN Attr   VSize VFree
  VolGroup   1  2   0 wz--n- 24.51g    0
# 卷组testvg已经被移除了,这里看不到testvg的相关信息了


 虽然卷组已经移除了,但是物理卷仍然保留:

[root@localhost ~]# pvs 

PV         VG       Fmt Attr PSize  PFree
  /dev/sda2  VolGroup lvm2 a--  24.51g   0
  /dev/sdc5           lvm2 a--   1.01g 1.01g
  /dev/sdd3           lvm2 a--   1.01g 1.01g

 

移除物理卷的方法也很简单,其命令为:

Pvremove/Path/To/Device

现在来移除用来创建逻辑卷的两个设备/dev/sdd3/dev/sdc5

[root@localhost ~]# pvremove/dev/sdc5 

 Labels on physicalvolume "/dev/sdc5" successfully wiped

[root@localhost ~]# pvremove/dev/sdd3  

Labels on physical volume"/dev/sdd3" successfully wiped

[root@localhost ~]# pvs 

PV         VG       Fmt Attr PSize  PFree
  /dev/sda2  VolGroup lvm2 a--  24.51g   0
# 成功移除物理卷,系统恢复到初始状态