Linux LVM全面实践

1.磁盘分区

[root@ol6-121-rac1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd8bb2864.
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-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +5G Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (655-1305, default 655):
Using default value 655
Last cylinder, +cylinders or +size{K,M,G} (655-1305, default 1305):
Using default value 1305 Command (m for help): p Disk /dev/sdb: 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: 0xd8bb2864 Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1305 5229157+ 83 Linux Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@ol6-121-rac1 ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@ol6-121-rac1 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 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: 0xd8bb2864 Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1305 5229157+ 83 Linux

2.创建PV


[root@ol6-121-rac1 ~]# pvcreate /dev/sdb{1,2}

  Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
[root@ol6-121-rac1 ~]# pvscan
PV /dev/sda2 VG vg_ol6121rac1 lvm2 [11.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [5.01 GiB]
PV /dev/sdb2 lvm2 [4.99 GiB]
Total: 3 [21.50 GiB] / in use: 1 [11.51 GiB] / in no VG: 2 [10.00 GiB]
[root@ol6-121-rac1 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_ol6121rac1
PV Size 11.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2946
Free PE 0
Allocated PE 2946
PV UUID YEG40A-wEWW-9F8Z-bgcL-PWvA-7sef-FP12my "/dev/sdb1" is a new physical volume of "5.01 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 5.01 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID p2nXS7-MmpX-Pawj-ThU3-k1NQ-t5Rc-hqKtb4 "/dev/sdb2" is a new physical volume of "4.99 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2 ----PV名
VG Name ----分配的VG,因为没有分配,所以是空
PV Size 4.99 GiB ----PV的大小
Allocatable NO ---是否被分配
PE Size 0 ---PE的大小
Total PE 0 ----共分配的PE数
Free PE 0 ----没有被LV用掉的PE
Allocated PE 0 ----尚可被分配的PE数量
PV UUID M31k1o-JGJx-3OrN-DmNf-W8uJ-SXBB-JdSviW
由于PE是在创建VG的时候才指定,所以这里的PE都显示0
[root@ol6-121-rac1 ~]# pvdisplay ---这里显示已经被VG使用的PV(与上面做个对比)
--- Physical volume ---
PV Name /dev/sdb1
VG Name datavg
PV Size 5.01 GiB / not usable 10.10 MiB
Allocatable yes
PE Size 512.00 MiB
Total PE 10
Free PE 10
Allocated PE 0
PV UUID p2nXS7-MmpX-Pawj-ThU3-k1NQ-t5Rc-hqKtb4

3.创建VG

创建格式:vgcreate -s N[mgt] VG名称 PV名称
[root@ol6--rac1 ~]# vgcreate -s 512M datavg /dev/sdb1   ---“-s”后面加PE的大小,单位可以是m,                                                                                  g,t
Volume group "datavg" successfully created
[root@ol6--rac1 ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "datavg" using metadata type lvm2
Found volume group "vg_ol6121rac1" using metadata type lvm2
[root@ol6--rac1 ~]# pvscan
PV /dev/sdb1 VG datavg lvm2 [5.00 GiB / 5.00 GiB free]
PV /dev/sda2 VG vg_ol6121rac1 lvm2 [11.51 GiB / free]
PV /dev/sdb2 lvm2 [4.99 GiB] ---,没有被使用的PV
Total: [21.49 GiB] / in use: [16.51 GiB] / in no VG: [4.99 GiB]
[root@ol6--rac1 ~]# vgdisplay datavg
--- Volume group ---
VG Name datavg
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 5.00 GiB
PE Size 512.00 MiB
Total PE
Alloc PE / Size /
Free PE / Size / 5.00 GiB
VG UUID wtuMSA-qOM7-eslo-BeiR-N8pJ-PVic-ZQXDXu
扩展VG
[root@ol6--rac1 ~]# vgextend datavg /dev/sdb2
Volume group "datavg" successfully extended
[root@ol6--rac1 ~]# vgdisplay datavg
--- Volume group ---
VG Name datavg
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 9.50 GiB
PE Size 512.00 MiB
Total PE
Alloc PE / Size /
Free PE / Size / 9.50 GiB
VG UUID wtuMSA-qOM7-eslo-BeiR-N8pJ-PVic-ZQXDXu

4.创建LV

创建格式:lvcreate -L N[mgt] -n LV名称 VG名称   或者  lvcreate -l N -n LV名称 VG名称
说明:-L 后面加容量 -l 后面加PE的个数
[root@ol6--rac1 ~]# lvcreate -L 5G -n datalv datavg 创建一个5G的LV
Logical volume "datalv" created
[root@ol6--rac1 ~]# vgdisplay datavg
--- Volume group ---
VG Name datavg
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 9.50 GiB
PE Size 512.00 MiB
Total PE
Alloc PE / Size / 5.00 GiB
Free PE / Size / 4.50 GiB
VG UUID wtuMSA-qOM7-eslo-BeiR-N8pJ-PVic-ZQXDXu [root@ol6--rac1 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/datavg/datalv
LV Name datalv
VG Name datavg
LV UUID sZ5JSE-YkRc-QxLA-GzWT-lLSR-s0WY-b0R8Pv
LV Write Access read/write
LV Creation host, time ol6--rac1.localdomain, -- :: +
LV Status available
# open
LV Size 5.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : [root@ol6--rac1 ~]# ll /dev/datavg/datalv
lrwxrwxrwx root root Mar : /dev/datavg/datalv -> ../dm-
删除LV:lvremove /dev/datavg/datalv ---注意:要加绝对路径
扩展LV
[root@ol6--rac1 ~]# lvresize -l + /dev/datavg/datalv 绝对路径
Extending logical volume datalv to 9.50 GiB
Logical volume datalv successfully resized
[root@ol6--rac1 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/datavg/datalv
LV Name datalv
VG Name datavg
LV UUID j5Wvb3-ZFiz-5PyG-gfdp-NPb4-BdRq-PhT1wm
LV Write Access read/write
LV Creation host, time ol6--rac1.localdomain, -- :: +
LV Status available
# open
LV Size 9.50 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :

5. 创建文件系统

[root@ol6--rac1 ~]# mkfs -t ext4 /dev/datavg/datalv   ---格式化,注意LV全名
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@ol6--rac1 ~]# mount /dev/datavg/datalv /oradata/ ---挂载
[root@ol6--rac1 ~]# df -lhT ---查看
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_ol6121rac1-lv_root
ext4 .4G .9G .1G % /
tmpfs tmpfs 499M 100K 499M % /dev/shm
/dev/sda1 ext4 485M 55M 405M % /boot
/dev/sr0 iso9660 .5G .5G % /media/OL6. x86_64 Disc
/dev/mapper/datavg-datalv
ext4 .4G 150M .8G % /oradata

——————————————————————————

Lookers-on see most of the game.-- Smedley

旁观者清

——————————————————————————

上一篇:【linux】linux系统中常见配置文件说明


下一篇:Java获取随机数的几种方法