LVM(逻辑卷管理)是linux中对磁盘分区的一种管理机制,是建立在硬盘和分区上,文件系统下的一个逻辑层。可以提高磁盘分区管理的灵活性。将多个硬盘和分区做成一个逻辑卷,并把这个逻辑卷作为一个整体来管理。动态对分区进行扩容缩减大小操作。
[root@wrx ~]# fdisk /dev/sdb
#创建新分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
#创建主分区
p
#分区ID
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):
Using default value 2610
#修改分区类型
Command (m for help): t
Selected partition 1
#linux LVM
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
#保存退出
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@wrx ~]#
[root@wrx ~]# fdisk -l
Disk /dev/sda: 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: 0x000caba5
Device Boot Start End Blocks Id System
/dev/sda1 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2358 18631680 83 Linux
/dev/sda3 2358 2611 2031616 82 Linux swap / Solaris
Disk /dev/sdb: 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: 0x864d997a
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 8e Linux LVM
Disk /dev/sdc: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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@wrx ~]#
#物理卷创建
[root@wrx ~]# pvcreate /dev/sdb1
dev_is_mpath: failed to get device for 8:17
Physical volume "/dev/sdb1" successfully created
#查看物理卷
[root@wrx ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 a-- 19.99g 19.99g
#卷组创建
[root@wrx ~]# vgcreate vol_group_1 /dev/sdb1
Volume group "vol_group_1" successfully created
#卷组查看
[root@wrx ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vol_group_1 1 0 0 wz--n- 19.99g 19.99g
#创建一个大小为5G名为vg_wrx_lv_root的逻辑卷(-L指定卷大小,-n指定卷名称)
[root@wrx ~]# lvcreate -L 5G -n vg_wrx_lv_root vol_group_1
Logical volume "vg_wrx_lv_root" created
#格式化逻辑卷
[root@wrx ~]# mkfs.ext4 /dev/vol_group_1/vg_wrx_lv_root
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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
#将逻辑卷挂载到/data目录下
[root@wrx ~]# mount /dev/vol_group_1/vg_wrx_lv_root /data
[root@wrx ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 5.5G 12G 33% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda1 291M 34M 242M 13% /boot
/dev/mapper/vol_group_1-vg_wrx_lv_root 5.0G 138M 4.6G 3% /data
#修改fstab文件,使其开机自动挂载
[root@wrx ~]# vim /etc/fstab