4-管理LVM
2016.6.14
LVM管理命令
- 常见命令
功能 | PV管理命令 | VG管理命令 | LV管理命令 |
---|---|---|---|
Scan 扫描 | pvscan | vgscan | lvscan |
Create 建立 | pvcreate | vgcreate | lvcreate |
Display 显示 | pvdisplay | vgdisplay | lvdisplay |
Remove 移除 | pvremove | vgremove | lvremove |
Extend 扩展 | vgextend | lvextend | |
educe 减少 | vgreduce | lvreduce |
格式
- pvcreate 设备名1 设备名2 ...
- vgcreate 卷组名 物理卷名1(设备名1) 物理卷名2(设备名2)
- lvcreate -L 容量大小 -n 逻辑卷名 卷组名
- lvextend -L +大小 /dev/卷组名/逻辑卷名
一般步骤
LVM应用案例
- 需求描述
- 公司准备在Internet中搭建邮件服务,面向全国各地的员工及部分VIP客户提供电子邮箱空间
- 由于用户数量众多,邮件存储需要大量的空间,考虑到动态扩容的需要,计划增加两块SCSI硬盘并构建LVM逻辑卷(挂载到“/mailbox”目录下)专门用于存放邮件数据
- 推荐步骤
创建物理卷pvcreate
- 使用fdisk命令规划两个分区,将类型设置为“8e”
- 使用pvcreate命令转换上述分区为物理卷
- pvcreate /dev/sdb2 /dev/sdc1
当前硬盘的信息:
[root@test1 jason]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0003aa34
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVM
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xe1ca40dd
Device Boot Start End Blocks Id System
/dev/sdb1 1 5221 41937651 83 Linux
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00000000
Disk /dev/sdd: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00000000
Disk /dev/mapper/vg_test-lv_root: 38.1 GB, 38126223360 bytes
255 heads, 63 sectors/track, 4635 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
直接从sdb中分出来2遇到问题:
[root@test1 jason]# fdisk /dev/sdb
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): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xe1ca40dd
Device Boot Start End Blocks Id System
/dev/sdb1 1 5221 41937651 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
No free sectors available
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
No free sectors available
有可能是之前格式化过:
删除分区:
Command (m for help): d
Selected partition 1
删除后查看:
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xe1ca40dd
Device Boot Start End Blocks Id System
创建两个primary partition:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-5221, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): +10G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-5221, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-5221, default 5221): +10G
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xe1ca40dd
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2612 10490445 83 Linux
转换分区并保存:
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xe1ca40dd
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2612 10490445 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@test1 jason]#
给sdc分primary partition,并转换成LVM类型:
[root@test1 jason]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf5a3b5cd.
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^H
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xf5a3b5cd
Device Boot Start End Blocks Id System
/dev/sdc1 1 1306 10490413+ 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xf5a3b5cd
Device Boot Start End Blocks Id System
/dev/sdc1 1 1306 10490413+ 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@test1 jason]#
接下来检测: 少了一个“/”
[root@test1 jason]# partprobe dev/sdb
Error: Could not stat device dev/sdb - No such file or directory.
继续检测:
[root@test1 jason]# partprobe /dev/sdb
[root@test1 jason]# partprobe /dev/sdb
sdb sdb1 sdb2
[root@test1 jason]# partprobe /dev/sdc
sdc sdc1
[root@test1 jason]# partprobe /dev/sdc
sdc sdc1
成功
用fdisk查看
[root@test1 jason]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0003aa34
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 5222 41430016 8e Linux LVM
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0xe1ca40dd
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2612 10490445 8e Linux LVM
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xf5a3b5cd
Device Boot Start End Blocks Id System
/dev/sdc1 1 1306 10490413+ 8e Linux LVM
Disk /dev/sdd: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00000000
Disk /dev/mapper/vg_test-lv_root: 38.1 GB, 38126223360 bytes
255 heads, 63 sectors/track, 4635 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: 0x00000000
Disk /dev/mapper/vg_test-lv_swap: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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: 0x00000000
[root@test1 jason]#
创建物理卷(pv)
[root@test1 jason]# pvcreate /dev/sdb2 /dev/sdc1
dev_is_mpath: failed to get device for 8:18
Physical volume "/dev/sdb2" successfully created
dev_is_mpath: failed to get device for 8:33
Physical volume "/dev/sdc1" successfully created
[root@test1 jason]#
使用pvscan查看物理卷:
[root@test1 jason]# pvscan
PV /dev/sda2 VG vg_test lvm2 [39.51 GiB / 0 free]
PV /dev/sdb2 lvm2 [10.00 GiB]
PV /dev/sdc1 lvm2 [10.00 GiB]
Total: 3 [59.52 GiB] / in use: 1 [39.51 GiB] / in no VG: 2 [20.01 GiB]
使用pvdisplay查看物理卷
[root@test1 jason]# pvdisply
bash: pvdisply: command not found
[root@test1 jason]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_test
PV Size 39.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 10114
Free PE 0
Allocated PE 10114
PV UUID 0bgw6M-VMw5-vvfC-PDXn-xC1i-Dfl2-n46oe4
"/dev/sdb2" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID th789t-FFbo-1AXt-4L9k-VXSj-Sxj8-YWDQCW
"/dev/sdc1" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc1
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID UwnR1F-mn5a-0Ml4-Xfag-WErZ-pgfg-TAwWI6
[root@test1 jason]#
创建卷组vgcreate
- 使用vgcreate命令创建卷组mail_store
- 包括物理卷:/dev/sdb1、/dev/sdc1
- vgcreate mail_store /dev/sdb2 /dev/sdc1
创建卷组
[root@test1 jason]# vgcreate mail_store /dev/sdb2 /dev/sdc1
Volume group "mail_store" successfully created
用vgscan查看卷组
[root@test1 jason]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "mail_store" using metadata type lvm2
Found volume group "vg_test" using metadata type lvm2
用vgdisplay查看卷组
[root@test1 jason]# vgdisplay
--- Volume group ---
VG Name mail_store
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 20.00 GiB
PE Size 4.00 MiB
Total PE 5120
Alloc PE / Size 0 / 0
Free PE / Size 5120 / 20.00 GiB
VG UUID hwMvw8-OPN7-qefx-0o85-xUuK-4Ppa-7YYY9J
--- Volume group ---
VG Name vg_test
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 39.51 GiB
PE Size 4.00 MiB
Total PE 10114
Alloc PE / Size 10114 / 39.51 GiB
Free PE / Size 0 / 0
VG UUID DS0LdR-wOIR-fVbQ-TRtq-idUZ-UfZ5-9XYWOF
[root@test1 jason]#
创建逻辑卷lvcreate
- 使用lvcreate命令创建逻辑卷mbox
- 从卷组mail_store上划出120G空间
- 使用mkfs命令创建ext4文件系统,挂载到/mail目录下
创建逻辑卷
[root@test1 jason]# lvcreate -L 20G -n mbox mail_store
Logical volume "mbox" created
使用lvscan查看逻辑卷
[root@test1 jason]# lvscan
ACTIVE '/dev/mail_store/mbox' [20.00 GiB] inherit
ACTIVE '/dev/vg_test/lv_root' [35.51 GiB] inherit
ACTIVE '/dev/vg_test/lv_swap' [4.00 GiB] inherit
使用lvdisplay查看逻辑卷
[root@test1 jason]# lvdisplay
--- Logical volume ---
LV Path /dev/mail_store/mbox
LV Name mbox
VG Name mail_store
LV UUID Zfywiv-iBTO-hyOG-USXW-7u7n-h9tV-OcP3fk
LV Write Access read/write
LV Creation host, time test1, 2016-06-14 15:45:48 +0800
LV Status available
# open 0
LV Size 20.00 GiB
Current LE 5120
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg_test/lv_root
LV Name lv_root
VG Name vg_test
LV UUID lj0Fej-Um7y-MY2b-of5r-yhYK-XHGI-5ElFeL
LV Write Access read/write
LV Creation host, time test, 2016-05-24 00:01:47 +0800
LV Status available
# open 1
LV Size 35.51 GiB
Current LE 9090
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_test/lv_swap
LV Name lv_swap
VG Name vg_test
LV UUID fp7Ls7-YX8y-vzOR-wDOA-Sxhw-iFxA-mfKQF6
LV Write Access read/write
LV Creation host, time test, 2016-05-24 00:01:52 +0800
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@test1 jason]#
将逻辑卷格式化成ext4文件系统
[root@test1 jason]# mkfs -t ext4 /dev/mail_store/mbox
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
挂载逻辑卷前
[root@test1 jason]# mount
/dev/mapper/vg_test-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)
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /mnt type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
[root@test1 jason]#
挂载逻辑卷到mailbox
[root@test1 jason]# mount /dev/mail_store/mbox /mailbox/
[root@test1 jason]# mount
/dev/mapper/vg_test-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)
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /mnt type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/mapper/mail_store-mbox on /mailbox type ext4 (rw)
[root@test1 jason]#
为逻辑卷扩容
- 使用lvextend命令为逻辑卷mbox扩从容量
- 从卷组mail_store上再划出10GB改逻辑卷mbox
- 使用resize2fs命令更新系统识别的文件系统大小
lvextend失败案例:
[root@test1 jason]# lvextend -L 3G /dev/mail_store/mbox
New size given (768 extents) not larger than existing size (5120 extents)
Run `lvextend --help' for more information.
[root@test1 jason]# lvextend -L 100G /dev/mail_store/mbox
Extending logical volume mbox to 100.00 GiB
Insufficient free space: 20480 extents needed, but only 0 available
[root@test1 jason]#
从sdc上面创建新的分区sdc2.把sdc2创建成物理卷(pv),作拓展用
[root@test1 jason]# fdisk /dev/sdc
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): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xf5a3b5cd
Device Boot Start End Blocks Id System
/dev/sdc1 1 1306 10490413+ 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-2610, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xf5a3b5cd
Device Boot Start End Blocks Id System
/dev/sdc1 1 1306 10490413+ 8e Linux LVM
/dev/sdc2 1307 2610 10474380 83 Linux
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
sdc2没有被识别
[root@test1 jason]# pvcreate /dev/sdc2
Device /dev/sdc2 not found (or ignored by filtering).
检测sdc:
[root@test1 jason]# partprobe /dev/sdc
sdc sdc1
[root@test1 jason]# partprobe /dev/sdc
sdc sdc1
[root@test1 jason]# partprobe /dev/sdc2
Error: Could not stat device /dev/sdc2 - No such file or directory.
[root@test1 jason]# partx /dev/sdc
sdc sdc1
[root@test1 jason]# partx /dev/sdc
sdc sdc1
[root@test1 jason]# partx -a /dev/sdc
sdc sdc1
[root@test1 jason]# partx -a /dev/sdc
sdc sdc1
重启之后:
[root@test1 jason]#
[root@test1 jason]# partprobe /dev/sdc
sdc sdc1 sdc2
[root@test1 jason]# partprobe /dev/sdc
sdc sdc1 sdc2
[root@test1 jason]# partprobe /dev/sdc
现在能检测到sdc2
将sdc2创建成物理卷
[root@test1 jason]# pvcreate /dev/sdc2
dev_is_mpath: failed to get device for 8:34
Physical volume "/dev/sdc2" successfully created
[root@test1 jason]#
卷组拓展失败:
[root@test1 jason]# vgextend /dev/sdc2 mail_store
Volume group "sdc2" not found
卷组拓展成功:
[root@test1 jason]# vgextend mail_store /dev/sdc2
Volume group "mail_store" successfully extended
查看拓展后卷组信息
[root@test1 jason]# vgdisplay
--- Volume group ---
VG Name mail_store
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 29.98 GiB
PE Size 4.00 MiB
Total PE 7676
Alloc PE / Size 5120 / 20.00 GiB
Free PE / Size 2556 / 9.98 GiB //可以看出来这里空闲的9.98G就是从sdc2拓展而来
VG UUID hwMvw8-OPN7-qefx-0o85-xUuK-4Ppa-7YYY9J
--- Volume group ---
VG Name vg_test
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 39.51 GiB
PE Size 4.00 MiB
Total PE 10114
Alloc PE / Size 10114 / 39.51 GiB
Free PE / Size 0 / 0
VG UUID DS0LdR-wOIR-fVbQ-TRtq-idUZ-UfZ5-9XYWOF
[root@test1 jason]#
逻辑卷拓展失败
[root@test1 jason]# lvextend -L 5G mbox
Path required for Logical Volume "mbox"
Please provide a volume group name
Run `lvextend --help' for more information.
[root@test1 jason]# lvextend -L 5G /dev/mail_store/mbox mbox
Physical Volume "mbox" not found in Volume Group "mail_store"
[root@test1 jason]# lvextend -L 5G /dev/mail_store/mbox
New size given (1280 extents) not larger than existing size (5120 extents)
Run `lvextend --help' for more information.
[root@test1 jason]#
man lvextend
Examples
Extends the size of the logical volume "vg01/lvol10" by 54MiB on physical volume
/dev/sdk3. This is only possible if /dev/sdk3 is a member of volume group vg01 and there
are enough free physical extents in it:
lvextend -L +54 /dev/vg01/lvol10 /dev/sdk3
Extends the size of logical volume "vg01/lvol01" by the amount of free space on physical
volume /dev/sdk3. This is equivalent to specifying "-l +100%PVS" on the command line:
lvextend /dev/vg01/lvol01 /dev/sdk3
Extends a logical volume "vg01/lvol01" by 16MiB using physical extents /dev/sda:8-9 and
/dev/sdb:8-9 for allocation of extents:
lvextend -L+16M vg01/lvol01 /dev/sda:8-9 /dev/sdb:8-9
继续失败:
[root@test1 jason]# man lvextend
[root@test1 jason]# lvextend -L +5G /dev/mail_store/mbox /dev/sdb3
Physical Volume "/dev/sdb3" not found in Volume Group "mail_store"
[root@test1 jason]# lvextend -L +5G /dev/mail_store/mbox /dev/sdb2
No free extents on physical volume "/dev/sdb2".
No specified PVs have space available
[root@test1 jason]# lvextend -L +5G /dev/mail_store/mbox mail_store
Physical Volume "mail_store" not found in Volume Group "mail_store"
成功:
[root@test1 jason]# lvextend -L +5G /dev/mail_store/mbox /dev/sdc2
Extending logical volume mbox to 25.00 GiB
Logical volume mbox successfully resized
注意你这里只加了5G,所以后面的结果并不是完全使用了sdc2的10G。
[root@test1 jason]# lvscan
ACTIVE '/dev/mail_store/mbox' [25.00 GiB] inherit
ACTIVE '/dev/vg_test/lv_root' [35.51 GiB] inherit
ACTIVE '/dev/vg_test/lv_swap' [4.00 GiB] inherit
使用lvdisplay查看逻辑卷信息
[root@test1 jason]# lvdisplay
--- Logical volume ---
LV Path /dev/mail_store/mbox
LV Name mbox
VG Name mail_store
LV UUID Zfywiv-iBTO-hyOG-USXW-7u7n-h9tV-OcP3fk
LV Write Access read/write
LV Creation host, time test1, 2016-06-14 15:45:48 +0800
LV Status available
# open 0
LV Size 25.00 GiB
Current LE 6400
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg_test/lv_root
LV Name lv_root
VG Name vg_test
LV UUID lj0Fej-Um7y-MY2b-of5r-yhYK-XHGI-5ElFeL
LV Write Access read/write
LV Creation host, time test, 2016-05-24 00:01:47 +0800
LV Status available
# open 1
LV Size 35.51 GiB
Current LE 9090
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_test/lv_swap
man resize2fs:
SYNOPSIS
resize2fs [ -fFpPM ] [ -d debug-flags ] [ -S RAID-stride ] device [ size ]
第一次执行resize2fs
[root@test1 jason]# resize2fs /dev/mail_store/mbox
resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/mail_store/mbox' first.
执行e2fsck:
[root@test1 jason]# e2fsck -f /dev/mail_store/mbox
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/mail_store/mbox: 11/1310720 files (0.0% non-contiguous), 126289/5242880 blocks
第二次执行resize2fs:
[root@test1 jason]# resize2fs /dev/mail_store/mbox
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mail_store/mbox to 6553600 (4k) blocks.
The filesystem on /dev/mail_store/mbox is now 6553600 blocks long.
[root@test1 jason]#
[root@test1 jason]# lvscan
ACTIVE '/dev/mail_store/mbox' [25.00 GiB] inherit
ACTIVE '/dev/vg_test/lv_root' [35.51 GiB] inherit
ACTIVE '/dev/vg_test/lv_swap' [4.00 GiB] inherit
[root@test1 jason]# lvdisplay
--- Logical volume ---
LV Path /dev/mail_store/mbox
LV Name mbox
VG Name mail_store
LV UUID Zfywiv-iBTO-hyOG-USXW-7u7n-h9tV-OcP3fk
LV Write Access read/write
LV Creation host, time test1, 2016-06-14 15:45:48 +0800
LV Status available
# open 0
LV Size 25.00 GiB
Current LE 6400
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/vg_test/lv_root
LV Name lv_root
VG Name vg_test
LV UUID lj0Fej-Um7y-MY2b-of5r-yhYK-XHGI-5ElFeL
LV Write Access read/write
LV Creation host, time test, 2016-05-24 00:01:47 +0800
LV Status available
# open 1
LV Size 35.51 GiB
Current LE 9090
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_test/lv_swap
LV Name lv_swap
VG Name vg_test
LV UUID fp7Ls7-YX8y-vzOR-wDOA-Sxhw-iFxA-mfKQF6
LV Write Access read/write
LV Creation host, time test, 2016-05-24 00:01:52 +0800
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
[root@test1 jason]#
因为刚才为了识别sdc2重启,但是重启之后,mount就被撤销了,所以先重新mount,然后使用df -h查看:
[root@test1 jason]# mount /dev/mail_store/mbox /mailbox/
[root@test1 jason]# mount
/dev/mapper/vg_test-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)
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /mnt type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/mapper/mail_store-mbox on /mailbox type ext4 (rw)
[root@test1 jason]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_test-lv_root 35G 13G 21G 39% /
tmpfs 932M 0 932M 0% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/sr0 4.2G 4.2G 0 100% /mnt
/dev/mapper/mail_store-mbox 25G 172M 24G 1% /mailbox
[root@test1 jason]#
查看mount信息:
[root@test1 jason]# mount
/dev/mapper/vg_test-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)
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /mnt type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/mapper/mail_store-mbox on /mailbox type ext4 (rw)
查看UUID
[root@test1 jason]# blkid /dev/sdb1
/dev/sdb1: UUID="8c475c04-aae8-4b2c-8e91-f93b9f26cf59" TYPE="ext4"
修改fstab,使逻辑卷可以自动挂载
[root@test1 jason]# blkid /dev/sdb1 >> /etc/fstab
[root@test1 jason]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue May 24 00:02:03 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_test-lv_root / ext4 defaults 1 1
UUID=a844ed1c-d5cf-4898-90f7-e9f040f4426e /boot ext4 defaults 1 2
/dev/mapper/vg_test-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/sr0 /mnt iso9660 defaults 0 0
UUID=8c475c04-aae8-4b2c-8e91-f93b9f26cf59 / ext4 defaults 0 0
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq
[root@test1 jason]# mount -a
mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so