1、LVM背景介绍
在AIX中,磁盘管理策略是一种Logical Volume Management的方法。简单的说,就是将存储划分为物理卷PV(Phsical Volume)、逻辑卷组VG(Logical Volume Group)和逻辑卷LV(Logical Volume)三个层次进行管理。
物理卷是我们最直观的磁盘或者分区,操作系统中可能有多种存储设备。在LVM中,都将其视为物理卷对象(PV)。
若干物理卷可以划归到一个逻辑组织中进行统一管理,这就是逻辑卷组(Logical Volume Group)。LVG类似于一个存储池,无论或大或小的PV被纳入到LVG中,都是进行统一管理。对使用者而言,LVG是一个统一的虚拟“存储”。在LVG内部,数据存储是以Physical Partition(PP)的方式进行划分管理。所以我们在度量LVM的容量的时候,PP个数是一个重要指标。
LVG是一个存储池对象,并不能直接作为存储。我们需要在LVG中划分出若干块进行使用,这就是LV(Logical Volume)。LV有自己的度量单位,和PP类似,成为LP(Logical Partition)。通常PP和LP是相同的。
创建LV之后,还要将其和特定目录进行关联,这个过程成为加载mount。下面是一个比较典型的LV存储结构。
# df -g
Filesystem GB blocks Free %Used Iused %Iused Mounted on
/dev/hd4 10.00 9.82 2% 10016 1% /
/dev/hd2 10.00 8.06 20% 42464 3% /usr
/dev/hd9var 30.00 29.72 1% 6289 1% /var
/dev/hd3 15.00 14.99 1% 47 1% /tmp
/dev/hd1 5.00 5.00 1% 5 1% /home
/dev/hd11admin 0.50 0.50 1% 5 1% /admin
/proc - - - - - /proc
/dev/hd10opt 5.00 4.86 3% 6970 1% /opt
/dev/livedump 0.50 0.50 1% 4 1% /var/adm/ras/livedump
/aha - - - 18 1% /aha
/dev/datalv01 2500.00 2499.62 1% 4 1% /db
File system中对应的各种磁盘,就是LV逻辑卷对象。使用LVM方法有很多好处,其中最大的就是可以动态进行空间拓展。比如,原有的LVG空间不足,可以直接加入一块新盘到LVG中,之后拓展extend逻辑卷空间。
2、环境介绍
下面我们就在AIX 7.1环境下进行创建和拓展试验。
# oslevel
当前系统中已经包括了两个逻辑卷组,分别为默认操作系统rootvg和ebsdbvg。
# lsvg
rootvg
ebsdbvg
# lspv
各个LV对应AIX目录结构,都有自己的空间限额和使用情况。
3、创建逻辑卷Logical Volume
当前ebsdbvg逻辑卷组情况如下:
# lsvg ebsdbvg
VOLUME GROUP: ebsdbvg VG IDENTIFIER: 00f67f7d00004c000000014b5edcb051
VG STATE: active PP SIZE: 1024 megabyte(s)
VG PERMISSION: read/write TOTAL PPs: 3071 (3144704 megabytes)
MAX LVs: 512 FREE PPs: 570 (583680 megabytes)
LVs: 2 USED PPs: 2501 (2561024 megabytes)
OPEN LVs: 2 QUORUM: 2 (Enabled)
TOTAL PVs: 1 VG DESCRIPTORS: 2
STALE PVs: 0 STALE PPs: 0
ACTIVE PVs: 1 AUTO ON: yes
MAX PPs per VG: 130048
MAX PPs per PV: 4064 MAX PVs: 32
LTG size (Dynamic): 512 kilobyte(s) AUTO SYNC: no
HOT SPARE: no BB POLICY: relocatable
PV RESTRICTION: none INFINITE RETRY: no
DISK BLOCK SIZE: 512
创建卷组之前要明确当前空间情况,使用lsvg结果中,对PP(Physical Partition)的使用情况是有明确的显示。在上面中,总计有3071个PP,已经使用2501个PP(占2500GB左右,每个PP大概1GB)。
当前ebsdbvg下,逻辑卷情况如下:
# lsvg -l ebsdbvg
ebsdbvg:
LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT
datalv01 jfs2 2500 2500 1 open/syncd /db
loglv00 jfs2log 1 1 1 open/syncd N/A
创建logical volume,使用smitty可以通过层级菜单进入功能模块,也可以使用快键关键字直接进入最近的模块。创建logical volume,使用smitty mklv进入。
首先要求输入Logical Volume Group名称,也就是在哪一个Volume Group上进行创建。
* VOLUME GROUP name [archlv]
注意,在smitty中,F3和F4非常有用。F3是表示Cancel和退出用途,而F4是打开输入项备选框,通过上下键进行控制。
从备选框中选择出testmisvg。进入新增加LV表单填写项目。
Add a Logical Volume
Type or select values in entry fields.
Press Enter AFTER making all desired changes.
[TOP] [Entry Fields]
Logical volume NAME [archlv]
* VOLUME GROUP name ebsdbvg
* Number of LOGICAL PARTITIONS [450] #
PHYSICAL VOLUME names [hdisk2] +
Logical volume TYPE [jfs2] +
POSITION on physical volume middle +
RANGE of physical volumes minimum +
MAXIMUM NUMBER of PHYSICAL VOLUMES [] #
to use for allocation
Number of COPIES of each logical 1 +
partition
Mirror Write Consistency? active +
Allocate each logical partition copy yes +
on a SEPARATE physical volume?
RELOCATE the logical volume during yes +
reorganization?
Logical volume LABEL []
MAXIMUM NUMBER of LOGICAL PARTITIONS [512] #
Enable BAD BLOCK relocation? yes +
SCHEDULING POLICY for writing/reading parallel +
[MORE...9]
F1=Help F2=Refresh F3=Cancel F4=List
F5=Reset F6=Command F7=Edit F8=Image
F9=Shell F10=Exit Enter=Do
注意: Logical Volume Name中填写要创建LV名称,Logical Partitions数量就是用于指定创建LV的大小。区别是不像我们创建其他空间直接指定大小,而是指定LV的个数。之前,我们通过简单计算可以看到一个LV的大小。所以可以指定个数计算出来。另一个注意的就是volume type,相当于格式化时候的文件类型。现在普遍推荐有日志机制的jsf2作为LV格式,如果不指定就默认选择jsf。可以通过F6查看对应的命令为: /usr/sbin/mklv -y'archlv' -t'jfs2' ebsdbvg 450 hdisk2
命令行判断添加成功,并且可以看到分配LP情况。
# lsvg -l ebsdbvg
ebsdbvg:
LV NAME TYPE LPs PPs PVs LV STATE MOUNT POINT
datalv01 jfs2 2500 2500 1 open/syncd /db
loglv00 jfs2log 1 1 1 open/syncd N/A
archlv jfs2 450 450 1 closed/syncd N/A
# lslv datalv01
LOGICAL VOLUME: datalv01 VOLUME GROUP: ebsdbvg
LV IDENTIFIER: 00f67f7d00004c000000014b5edcb051.1 PERMISSION: read/write
VG STATE: active/complete LV STATE: opened/syncd
TYPE: jfs2 WRITE VERIFY: off
MAX LPs: 2500 PP SIZE: 1024 megabyte(s)
COPIES: 1 SCHED POLICY: parallel
LPs: 2500 PPs: 2500
STALE PPs: 0 BB POLICY: relocatable
INTER-POLICY: minimum RELOCATABLE: yes
INTRA-POLICY: middle UPPER BOUND: 32
MOUNT POINT: /db LABEL: /db
DEVICE UID: 0 DEVICE GID: 0
DEVICE PERMISSIONS: 432
MIRROR WRITE CONSISTENCY: on/ACTIVE
EACH LP COPY ON A SEPARATE PV ?: yes
Serialize IO ?: NO
INFINITE RETRY: no
注意:此时我们只是创建了磁盘,在AIX中,还有进行mount过程。将这个磁盘挂载在目录下。
# mkdir /db_arch
在smitty中,manfs可以直接建立file system与logical volume之间的关系。
# smitty manfs
Add / Change / Show / Delete File Systems
Move cursor to desired item and press Enter.
Enhanced Journaled File Systems
Journaled File Systems
CDROM File Systems
Network File System (NFS)
选择Enhanced Journaled File Systems,进入配置项目。
Enhanced Journaled File Systems
Move cursor to desired item and press Enter.
Add an Enhanced Journaled File System
Add an Enhanced Journaled File System on a Previously Defined Logical Volume
Change / Show Characteristics of an Enhanced Journaled File System
Remove an Enhanced Journaled File System
Manage Quotas for an Enhanced Journaled File System
Defragment an Enhanced Journaled File System
List Snapshots for an Enhanced Journaled File System
Create Snapshot for an Enhanced Journaled File System
Mount Snapshot for an Enhanced Journaled File System
Remove Snapshot for an Enhanced Journaled File System
Unmount Snapshot for an Enhanced Journaled File System
Change Snapshot for an Enhanced Journaled File System
Rollback an Enhanced Journaled File System to a Snapshot
选择add,填写表单,建立LV与File System之间的关系。
Add an Enhanced Journaled File System
Type or select values in entry fields.
Press Enter AFTER making all desired changes.
[Entry Fields]
* LOGICAL VOLUME name archlv +
* MOUNT POINT [/db_arch]
Mount AUTOMATICALLY at system restart? yes +
PERMISSIONS read/write +
Mount OPTIONS [] +
Block Size (bytes) 4096 +
Logical Volume for Log +
Inline Log size (MBytes) [] #
Extended Attribute Format +
ENABLE Quota Management? no +
Enable EFS? no +
Allow internal snapshots? no +
Mount GROUP []
填写上关联的logical volume名称和对应的目录。此外,推荐选择上自动重启系统加载。需要等待一小会,命令结果如下:
COMMAND STATUS
Command: OK stdout: yes stderr: no
Before command completion, additional instructions may appear below.
File system created successfully.
471844596 kilobytes total disk space.
New File System size is 943718400
注意:此时并没有加载上目录。
df -g看不到该分区被挂载上,需要手工执行:mount /db_arch
额外说明一下,在smitty中可以查看到File System的属性信息,其中有详细的空间情况。
Type or select values in entry fields.
Press Enter AFTER making all desired changes.
[TOP] [Entry Fields]
File system name /testlv01
NEW mount point [/testlv01]
SIZE of file system
Unit Size 512bytes +
Number of units [2621440] #
Mount GROUP []
Mount AUTOMATICALLY at system restart? yes +
PERMISSIONS read/write +
Mount OPTIONS [] +
Start Disk Accounting? no +
Block Size (bytes) 4096
Inline Log? no
Inline Log size (MBytes) [0] #
在Size of file system中,记录每个单元512bytes,一共有2621440个单元。计算:2621440*512=1342177280 bytes=1.25GB,与df –g情况相符合。
4、调整LV和文件系统大小
当我们的空间使用耗尽之后,如果Logical Volume Group允许,我们就可以进行空间拓展调整LV的大小。
使用smitty lvsc命令,进入调整界面。
[root@TESTMIS:/]#smitty lvsc
Set Characteristic of a Logical Volume
Move cursor to desired item and press Enter.
Change a Logical Volume
Rename a Logical Volume
Increase the Size of a Logical Volume
Add a Copy to a Logical Volume
Remove a Copy from a Logical Volume
选择increase the size of a logical volume。
Increase the Size of a Logical Volume
Type or select values in entry fields.
Press Enter AFTER making all desired changes.
[Entry Fields]
* LOGICAL VOLUME name testmislv01
* Number of ADDITIONAL logical partitions [5] #
PHYSICAL VOLUME names [] +
POSITION on physical volume middle +
RANGE of physical volumes minimum +
MAXIMUM NUMBER of PHYSICAL VOLUMES [64] #
to use for allocation
Allocate each logical partition copy yes +
on a SEPARATE physical volume?
File containing ALLOCATION MAP []
注意:输入的是一个增加LP个数的取值,含义是在原来基础上增加多少个LP。执行之后,我们就可以看到testmislv01的LP个数增加。
[root@TESTMIS:/]#lslv testmislv01
LOGICAL VOLUME: testmislv01 VOLUME GROUP: testmisvg
LV IDENTIFIER: 00f7fcc800004c000000013c7051ca49.1 PERMISSION: read/write
VG STATE: active/complete LV STATE: opened/syncd
TYPE: jfs2 WRITE VERIFY: off
MAX LPs: 512 PP SIZE: 128 megabyte(s)
COPIES: 1 SCHED POLICY: parallel
LPs: 15 PPs: 15
STALE PPs: 0 BB POLICY: relocatable
但是,对应的目录testlv01空间没有变化。
[root@TESTMIS:/]#df -g
Filesystem GB blocks Free %Used Iused %Iused Mounted on
(篇幅原因,有省略……)
/dev/livedump 0.25 0.25 1% 4 1% /var/adm/ras/livedump
/dev/testmislv01 1.25 1.25 1% 4 1% /testlv01
这里需要进行手工的空间调整,调整File System的大小属性。
[root@TESTMIS:/]#smitty manfs
Add / Change / Show / Delete File Systems
Move cursor to desired item and press Enter.
Enhanced Journaled File Systems --选择增强日志文件系统
Journaled File Systems
CDROM File Systems
Network File System (NFS)
Enhanced Journaled File Systems
Move cursor to desired item and press Enter.
Add an Enhanced Journaled File System
Add an Enhanced Journaled File System on a Previously Defined Logical Volume
Change / Show Characteristics of an Enhanced Journaled File System
Remove an Enhanced Journaled File System
Manage Quotas for an Enhanced Journaled File System
Defragment an Enhanced Journaled File System
List Snapshots for an Enhanced Journaled File System
注意:这里面我们是输入512byte的单元个数值,从原来的2621440修改为3932160。
[TOP] [Entry Fields]
File system name /testlv01
NEW mount point [/testlv01]
SIZE of file system
Unit Size 512bytes +
Number of units [2621440] #
修改
Change / Show Characteristics of an Enhanced Journaled File System
Type or select values in entry fields.
Press Enter AFTER making all desired changes.
[TOP] [Entry Fields]
File system name /testlv01
NEW mount point [/testlv01]
SIZE of file system
Unit Size 512bytes +
Number of units [3932160] #
这其中的依据是10LP上升到15个LP,换算之后总大小为3932160个unit。合计:3932160*512=1.875GB。
执行命令如下:
Before command completion, additional instructions may appear below.
Filesystem size changed to 3932160
此时检查df –g,就可以发现容量变化。
[root@TESTMIS:/]#df -g | grep testmis
/dev/testmislv01 1.88 1.87 1% 4 1% /testlv01