CentOS下LVM 增加、扩容逻辑卷

分类:CentOS教程 阅读:23574 次

1.查看硬盘分区情况

#fdisk -l

注:假设新增一个硬盘的设备文件名为/dev/sdb

2.开始分区

#fdisk /dev/sdb

3.查看指令帮助信息

Command (m for help): m

4.查看已有分区表

Command (m for help): p

Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 60800 488375968 7 HPFS/NTFS

注:可以看出此硬盘已经有一个分区,且所有的柱面都已分配

5.删除原有分区

Command (m for help): d

6.再次查看分区表

Command (m for help): p

Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

7.新增分区

Command (m for help): n

Command action
e extended
p primary partition (1-4)

8.选择分区类型(主分区、扩展分区)、第几个分区

p

1

9.设置分区的柱面范围,这里开始与结束都默认,直接回车

10.查看分区表

Command (m for help): p

Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 60800 488375968+ 83 Linux

11.更改分区的类型

Command (m for help): t
Selected partition 1
Hex code (type L to list codes):L

注:如果有多个分区,会出现提示选择分区

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

12.将磁盘格式设置为linux LVM

Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

13.再次查看分区表

Command (m for help): p

Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 60800 488375968+ 8e Linux LVM

14.保存,退出fdisk

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

Calling ioctl() to re-read partition table.
Syncing disks.

如果出错,使用partprobe指令重载分区表

15.查看硬盘分区情况

#fdisk -l

Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 60800 488375968+ 8e Linux LVM

16.查看系统中已有的物理卷

#pvdisplay

--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 297.99 GB / not usable 20.87 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 9535
Free PE 0
Allocated PE 9535
PV UUID oa2rNU-Tz2c-N1W0-AKcV-9UnE-ctdp-38dFQd

17.建立物理卷

#pvcreate /dev/sdb1

Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created

18.将新物理卷加入到卷组中

#vgextend VolGroup00 /dev/sdb1

Volume group "VolGroup00" successfully extended

19.将新的空间加到原有逻辑卷中去

#lvextend -L+500G /dev/VolGroup00/LogVol00

20.激活扩容的LVM分区

#resize2fs -p /dev/VolGroup00/LogVol00

21.如果不扩容,可以增加逻辑卷

#lvcreate -L 200G -n lvol0 VolGroup00

Logical volume "lvol0" created

22.删除逻辑卷

#lvremove /dev/mapper/VolGroup00-lvol0

23.查看已经存在的逻辑卷

#lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID ipf0Gk-3xXU-vN0I-cXbm-ZKLD-XUju-mDe02Z
LV Write Access read/write
LV Status available
# open 1
LV Size 48.81 GB
Current LE 1562
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol02
VG Name VolGroup00
LV UUID RybA0Q-5B8T-bOwA-SsPK-Prai-qsix-kCeWWI
LV Write Access read/write
LV Status available
# open 1
LV Size 49.91 GB
Current LE 1597
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol03
VG Name VolGroup00
LV UUID czznK0-VsUK-VAtj-Vbam-PDJS-1yZt-A6BPgK
LV Write Access read/write
LV Status available
# open 1
LV Size 195.31 GB
Current LE 6250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID zvLpEL-Dj8Y-a0XG-4H7q-ZPaa-XUXY-0ln7qw
LV Write Access read/write
LV Status available
# open 1
LV Size 3.94 GB
Current LE 126
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3

24.正式新增逻辑卷

#lvcreate -L 500G -n LogVol04 VolGroup00

25.格式化新增逻辑卷

#mkfs.ext3 /dev/mapper/VolGroup00-LogVol04

26.挂载逻辑卷

#mount /dev/mapper/VolGroup00-LogVol04 /data

27.编辑/etc/fstab将新增逻辑卷设置开机挂载,新增下面一行

/dev/VolGroup00/LogVol04 /data ext3 defaults 1 2

28.测试挂载

mount -a

29.查看并删除物理卷

查看挂载情况

#df -h
/dev/mapper/VolGroup00-LogVol04
296G 245M 281G 1% /backup

卸载

#umount /backup

删除逻辑卷

#lvremove /dev/mapper/VolGroup00-LogVol04

查看物理卷

#pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 297.99 GB / not usable 20.87 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 9535
Free PE 0
Allocated PE 9535
PV UUID oa2rNU-Tz2c-N1W0-AKcV-9UnE-ctdp-38dFQd

--- Physical volume ---
PV Name /dev/sdb1
VG Name VolGroup00
PV Size 465.75 GB / not usable 1.66 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 14904
Free PE 5304
Allocated PE 9600
PV UUID avEKz2-t5Ko-jsn0-Pvuh-h8DJ-GV0o-ZQfBOL

将物理卷从卷组中移除

#vgreduce VolGroup00 /dev/sdb1

删除物理卷

#pvremove /dev/sdb1

这样就可以重新进行格式化磁盘