LVM应用实例
案例的环境和需求描述如下:公司准备在Internet中搭建邮件服务器(RHEL 6系统平台),面向全国各地的员工及部分VIP客户提供电子邮箱空间。由于用户数量众多,邮件存储需要大量的空间,考虑到动态扩容的需要,计划增加两块SCSI硬盘并构建LVM逻辑卷 (挂载到“/mailbox”目录下)专门用于存放邮件数据。
根据上述案例环境和需求,推荐的操作步骤如下所述。
(1 )关闭服务器主机,打开机箱,正确挂接两块SCSI新硬盘。
(2 )开启服务器主机,并执行“fdisk -I”命令进行检查,确认已识别新增的硬盘(sdb、 sdc )。
(3)在新磁盘中进行分区,将每块硬盘的所有空间划分为一个独立的主分区,并将分区类型更改为“8e”分好区后使用“fdisk- l”命令查看,确认结果如下所示。
一、格式化、转换分区类型
1.把sdb2转换成LVM类型的分区:
[root@test2 /]# 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): 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): p
Disk /dev/sdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0xa8f24694
Device Boot Start End Blocks Id System
/dev/sdb1 1 2612 20980858+ 83 Linux
/dev/sdb2 2613 5224 20980890 8e Linux LVM
/dev/sdb3 5225 10443 41921617+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@test2 /]#
2.创建sdc2分区,并转变成LVM类型:
[root@test2 /]# 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): n
Command action
e extended
p primary partition (1-4)
2
Invalid partition number for type `2‘
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (2613-10443, default 2613):
Using default value 2613
Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +20F
Unsupported suffix: ‘F‘.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
2^N: K (KibiByte), M (MebiByte), G (GibiByte)
Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +20G
Command (m for help): P
Disk /dev/sdc: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x8967e34e
Device Boot Start End Blocks Id System
/dev/sdc1 1 2612 20980858+ 83 Linux
/dev/sdc2 2613 5224 20980890 83 Linux
Command (m for help): T
Partition number (1-4): be
Partition number (1-4): 2
Hex code (type L to list codes): b
Changed system type of partition 2 to b (W95 FAT32)
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): p
Disk /dev/sdc: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0x8967e34e
Device Boot Start End Blocks Id System
/dev/sdc1 1 2612 20980858+ 83 Linux
/dev/sdc2 2613 5224 20980890 8e Linux LVM
Command (m for help):
3.保存
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)
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
4.探测
[root@test2 /]# partx /dev/sdc
sdc sdc1
[root@test2 /]# partx /dev/sdc
sdc sdc1
[root@test2 /]# partx -a /dev/sdc
sdc sdc1
[root@test2 /]# partx -a /dev/sdc
sdc sdc1
[root@test2 jason]# partprobe /dev/sdc
sdc sdc1 sdc2
[root@test2 jason]# partprobe /dev/sdc
[root@test2 jason]# pvscan
PV /dev/sda2 VG vg_jason lvm2 [19.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [20.01 GiB]
PV /dev/sdb2 lvm2 [20.01 GiB]
Total: 3 [59.53 GiB] / in use: 1 [19.51 GiB] / in no VG: 2 [40.02 GiB]
[root@test2 jason]#
二、创建Logical Volume
1.创建pv
[root@test2 jason]# pvcreate /dev/sdc2
Physical volume "/dev/sdc2" successfully created
[root@test2 jason]#
[root@test2 jason]# pvscan
PV /dev/sda2 VG vg_jason lvm2 [19.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [20.01 GiB]
PV /dev/sdb2 lvm2 [20.01 GiB]
PV /dev/sdc2 lvm2 [20.01 GiB]
Total: 4 [79.53 GiB] / in use: 1 [19.51 GiB] / in no VG: 3 [60.03 GiB]
[root@test2 jason]#
2.创建 VG
[root@test2 jason]# lvscan
ACTIVE ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit
[root@test2 jason]# pvcreate mail_store /dev/sdb2 /dev/sdc2
Device mail_store not found (or ignored by filtering).
dev_is_mpath: failed to get device for 8:18
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdc2" successfully created
[root@test2 jason]#
[root@test2 jason]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg_jason" using metadata type lvm2
[root@test2 jason]# vgcreate mail_store /dev/sdb2 /dev/sdc2
Volume group "mail_store" successfully created
[root@test2 jason]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "mail_store" using metadata type lvm2
Found volume group "vg_jason" using metadata type lvm2
[root@test2 jason]#
[root@test2 jason]# lvcreate -L 35G -n mbox mail_store
Logical volume "mbox" created
[root@test2 jason]# lvscan
ACTIVE ‘/dev/mail_store/mbox‘ [35.00 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit
[root@test2 jason]#
3.创建LV
[root@test2 jason]# lvscan
ACTIVE ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit
[root@test2 jason]# lvcreate -L 35G -n mbox mail_store
Logical volume "mbox" created
[root@test2 jason]# lvscan
ACTIVE ‘/dev/mail_store/mbox‘ [35.00 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit
[root@test2 jason]#
[root@test2 /]# mkdir /mailbox
4.格式化:
[root@test2 /]# mkfs.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
2293760 inodes, 9175040 blocks
458752 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
280 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, 7962624
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@test2 /]#
5.挂载并查看:
[root@test2 /]# mount /dev/mail_store/mbox /mailbox/
[root@test2 /]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% /
tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm
/dev/sda1 ext4 485M 40M 421M 9% /boot
/dev/sdc1 ext4 20G 421M 19G 3% /home
/dev/mapper/mail_store-mbox ext4 35G 176M 33G 1% /mailbox
[root@test2 /]#
三、拓展篇:
1.在虚拟机中新建一个100G的硬盘(略):
2.只建一个分区,并转换成为LVM类型:
[root@test2 jason]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xef9a8da9.
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-13054, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):
Using default value 13054
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/sdd: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0xef9a8da9
Device Boot Start End Blocks Id System
/dev/sdd1 1 13054 104856223+ 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@test2 jason]#
[root@test2 jason]# partprobe /dev/sdd
sdd sdd1
[root@test2 jason]# partprobe /dev/sdd
3.创建pv:
[root@test2 jason]# pvcreate /dev/sdd1
dev_is_mpath: failed to get device for 8:49
Physical volume "/dev/sdd1" successfully created
vg拓展mail_store:
[root@test2 jason]# vgextend mail_store /dev/sdd1
Volume group "mail_store" successfully extended
vgdisplay mail_store:
[root@test2 jason]# vgdisplay mail_store
--- 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 140.01 GiB
PE Size 4.00 MiB
Total PE 35843
Alloc PE / Size 8960 / 35.00 GiB
Free PE / Size 26883 / 105.01 GiB
VG UUID yHpVfR-lbFL-vs9A-mzgz-m800-JLE2-Dt2z6F
[root@test2 jason]#
4.LV扩容
[root@test2 jason]# lvextend -L +85G mbox mail_store
Path required for Logical Volume "mbox"
Please provide a volume group name
Run `lvextend --help‘ for more information.
[root@test2 jason]# lvextend -L +85G /dev/mail_store/mbox
Extending logical volume mbox to 120.00 GiB
Logical volume mbox successfully resized
[root@test2 jason]# lvscan
ACTIVE ‘/dev/mail_store/mbox‘ [120.00 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_root‘ [17.51 GiB] inherit
ACTIVE ‘/dev/vg_jason/lv_swap‘ [2.00 GiB] inherit
5.挂载
[root@test2 jason]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% /
tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm
/dev/sda1 ext4 485M 40M 421M 9% /boot
/dev/sdc1 ext4 20G 421M 19G 3% /home
[root@test2 jason]# mount
/dev/mapper/vg_jason-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/sdc1 on /home type ext4 (rw)
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@test2 jason]# mount /dev/mail_store/mbox /mailbox/
[root@test2 jason]# mount
/dev/mapper/vg_jason-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/sdc1 on /home type ext4 (rw)
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@test2 jason]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% /
tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm
/dev/sda1 ext4 485M 40M 421M 9% /boot
/dev/sdc1 ext4 20G 421M 19G 3% /home
/dev/mapper/mail_store-mbox ext4 35G 176M 33G 1% /mailbox
6.更新磁盘容量
[root@test2 jason]# resize2fs
resize2fs 1.41.12 (17-May-2010)
Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [new_size]
[root@test2 jason]# resize2fs /dev/mail_store/mbox
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mail_store/mbox is mounted on /mailbox; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 8
Performing an on-line resize of /dev/mail_store/mbox to 31457280 (4k) blocks.
The filesystem on /dev/mail_store/mbox is now 31457280 blocks long.
[root@test2 jason]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% /
tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm
/dev/sda1 ext4 485M 40M 421M 9% /boot
/dev/sdc1 ext4 20G 421M 19G 3% /home
/dev/mapper/mail_store-mbox ext4 119G 188M 112G 1% /mailbox
[root@test2 jason]#
本文出自 “11714065” 博客,请务必保留此出处http://11724065.blog.51cto.com/11714065/1790215
原文地址:http://11724065.blog.51cto.com/11714065/1790215