Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370559
  • 博文数量: 110
  • 博客积分: 4642
  • 博客等级: 准将
  • 技术积分: 1404
  • 用 户 组: 普通用户
  • 注册时间: 2005-03-10 10:15
文章分类

全部博文(110)

文章存档

2012年(17)

2011年(22)

2010年(49)

2009年(20)

2008年(2)

分类:

2009-09-29 21:48:53

Linux LVM ---逻辑卷管理器(LVM

1〉〉三个基本的概念

PV  物理卷

VG  可以说是一个或者多个PV转成的也可以说是多个LV组成的

LV  逻辑卷

 

官方文档

 

 

fdisk /dev/hda (IDE) fdisk /dev/sda(SCSI)

n选项划出区,w选项后重新启动系统生效。这个重启实在是个问题,这在

pvcreate /dev/hdaXX

转换成/组成vg

vgcreate XXvg /dev/hdaXX

从vg上划分LV

lvcreate –L+50M –n lv01 XXvg

格式化LV

mke2fs –j /dev/XXvg/lv01

挂载已经格式化的LV

mkdir /data
mount /dev/XXvg/lv01 /data

2〉〉LV扩容

RHEL 3
LVM 1.0
; df –h
; umount /data
; e2fsadm –L +10M /dev/rootvg/lv01
; mount /dev/rootvg/lv01 /data
; df -h
 
RHEL 4
LVM2.0以上了

; df –h
; lvextend –L +10M /dev/rootvg/lv01
; ext2online /dev/rootvg/lv01
; df –h

 

 

Note:RHEL 4無需umount filesystem

 

Appendix:

[转自blog]

和创建普通分区的步骤差不多,只是多了一步要设定分区的ID,LVM的系统ID8e.


[root@localhost /]# fdisk -l ---------------------------->查看分区信息

Disk /dev/sda: 146.8 GB, 146814976000 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/dev/sda1 * 1 3824 30716248+ 83 Linux
/dev/sda2 3825 7648 30716280 83 Linux
/dev/sda3 7649 8170 4192965 82 Linux swap / Solaris
/dev/sda4 8171 17849 77746567+ 5 Extended
/dev/sda5 8171 10603 19543041 83 Linux
[root@localhost /]# fdisk /dev/sda ------------------->对/dev/sda进行分区

The number of cylinders for this disk is set to 17849.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n -------------------->新建一个分区
First cylinder (10604-17849, default 10604):
Using default value 10604
Last cylinder or +size or +sizeM or +sizeK (10604-17849, default 17849): +500M ------>创建一个500M的分区

Command (m for help): m ----------------------->查看fdisk帮助
h: unknown command
Command action
   a toggle a bootable flag
   b edit bsd disklabel
   c toggle the dos compatibility flag
   d delete a partition
   l list known partition types
   m print this menu
   n add a new partition
   o create a new empty DOS partition table
   p print the partition table
   q quit without saving changes
   s create a new empty Sun disklabel
   t change a partition's system id
   u change display/entry units
   v verify the partition table
   w write table to disk and exit
   x extra functionality (experts only)

Command (m for help): t ------------------------>改变一个分区的ID(属性)
Partition number (1-6): 6
Hex code (type L to list codes): L ------------------------>查看分区代码

0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris
1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx
5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data
6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
           
Hex code (type L to list codes): 8e --------------------------->选择linux LVM
Changed system type of partition 6 to 8e (Linux LVM)

Command (m for help): w ------------------------->保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost /]# partprobe --------------------->让分区立退生效
[root@localhost /]# fdisk -l

Disk /dev/sda: 146.8 GB, 146814976000 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/dev/sda1 * 1 3824 30716248+ 83 Linux
/dev/sda2 3825 7648 30716280 83 Linux
/dev/sda3 7649 8170 4192965 82 Linux swap / Solaris
/dev/sda4 8171 17849 77746567+ 5 Extended
/dev/sda5 8171 10603 19543041 83 Linux
/dev/sda6 10604 10665 497983+ 8e Linux LVM ---------->刚才新建的LVM分区
[root@localhost /]# mke2fs -j /dev/sda6 ----------->格式化此分区
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
124928 inodes, 497980 blocks
24899 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
61 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks
:
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

创建物理卷:

#pvcreate /dev/sda6 ----------------->将sda6创建物理卷
#pvdisplay --------------->查看创建的物理卷

 


创建卷组:
#vgcreate xxvg /dev/sda6
#vgdisplay --------------->查看创建的卷组
,逻辑卷的大小调整:

调大:
[root@localhost /]# lvresize -L 300M /dev/xxvg/lv01
[root@localhost /]# lvdisplay

调小:
调小的时间要先缩小文件系统,不然可能会造成资料丢失:
[root@localhost /]# resize2fs /dev/xxvg/lv01 250M ---------->调整文件系统的大小
[root@localhost /]# lvresize -L 250M /dev/xxvg/lv01 ---------->调整逻辑卷的大小
[root@localhost /]# lvresize -L 250M /dev/xxvg/lv01


逻辑卷的扩容:
我们先再新建一个物理卷,和上面同样的方法:
[root@localhost /]# fdisk /dev/sda
Command (m for help): w
[root@localhost /]# partprobe
[root@localhost /]# pvcreate /dev/sda7
Physical volume "/dev/sda7" successfully created
[root@localhost /]# vgextend xxvg /dev/sda7 ---------->将/dev/sda7增加到逻辑卷组中
Volume group "xxvg" successfully extended
[root@localhost /]# vgdisplay
逻辑卷的删除:

[root@localhost /]# umount /mnt -------------------->先umount分区
[root@localhost /]# lvremove /dev/xxvg/lv01 -------------------->移除逻辑卷
Do you really want to remove active logical volume "cxktest"? [y/n]: y
Logical volume "cxktest" successfully removed
[root@localhost/]#vgremove xxvg -------------------->移除卷组
Volume group "xxvg" successfully removed
[root@localhost /]# pvremove /dev/sda6 --------------------->移除物理卷
Labels on physical volume "/dev/sda6" successfully wiped
[root@localhost /]# pvremove /dev/sda7
Labels on physical volume "/dev/sda7" successfully wiped
[root@localhost/]#fdisk /dev/sda --------------------->删除物理分区

The number of cylinders for this disk is set to 17849.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): d
Partition number (1-7): 7

Command (m for help): d
Partition number (1-6): 6

Command (m for help): p

Disk /dev/sda: 146.8 GB, 146814976000 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot Start End Blocks Id System
/dev/sda1 * 1 3824 30716248+ 83 Linux
/dev/sda2 3825 7648 30716280 83 Linux
/dev/sda3 7649 8170 4192965 82 Linux swap / Solaris
/dev/sda4 8171 17849 77746567+ 5 Extended
/dev/sda5 8171 10603 19543041 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.


阅读(552) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~