Linux利用LVM扩展根分区

1.LVM的基本概念

physical volume (PV)

通常是一快硬盘。相当于一个物理设备,磁盘空间物理卷PV。

volume group (VG)

相当于LVM的卷组,属于一个抽象下的组概念,一个VG可以包括多个PV。我的实操是我的VG下面,包含了PV(/dev/sda5)和PV(/dev/sdb1)如下:
root@linuxidc.com:~# pvdisplay
  --- Physical volume ---
  PV Name              /dev/sda5
  VG Name              linuxidc.com-vg
  PV Size              49.76 GiB / not usable 2.00 MiB
  Allocatable          yes (but full)
  PE Size              4.00 MiB
  Total PE              12738
  Free PE              0
  Allocated PE          12738
  PV UUID              ADh3K6-fjVA-5lLY-9vzu-eIxe-utiL-pOYtZa
 
  --- Physical volume ---
  PV Name              /dev/sdb1
  VG Name              linuxidc.com-vg
  PV Size              16.00 GiB / not usable 3.00 MiB
  Allocatable          yes (but full)
  PE Size              4.00 MiB
  Total PE              4095
  Free PE              0
  Allocated PE          4095
  PV UUID              2RwFCw-lLul-8CIf-gHvb-0rC1-U0aG-SfHZGd
 
root@linuxidc.com:~# pvs     
  PV        VG          Fmt  Attr PSize  PFree
  /dev/sda5  linuxidc.com-vg lvm2 a--  49.76g    0
  /dev/sdb1  linuxidc.com-vg lvm2 a--  16.00g    0

logical volume (LV)

LV简单的理解是可以挂载到分区下的磁盘空间了。如下 :根分区/下的空间,代表着root这个lv。
root@linuxidc.com:~# lvs
  LV    VG          Attr      LSize  Pool Origin Data%  Move Log Copy%  Convert
  root  linuxidc.com-vg -wi-ao--- 53.76g                                         
  swap_1 linuxidc.com-vg -wi-ao--- 12.00g                                         

2.lvm扩展根目录分区的实战

2.1 设置硬盘/dev/sdb为linux lvm

先决条件:在vmware虚拟化平台下,我先添加了一块/dev/sdb的硬盘,并把硬盘设置为linux lvm,操作如下:
root@linuxidc.com:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x502d7728.
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)

Command (m for help): p

Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x502d7728

Device Boot      Start        End      Blocks  Id  System

Command (m for help): n
Partition type:
  p  primary (0 primary, 0 extended, 4 free)
  e  extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-33554431, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431):
Using default value 33554431

Command (m for help): p

Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x502d7728

Device Boot      Start        End      Blocks  Id  System
/dev/sdb1            2048    33554431    16776192  83  Linux

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/11613.html