现在的位置: 首页 > 综合 > 正文

LVM扩展磁盘空间

2017年11月10日 ⁄ 综合 ⁄ 共 5620字 ⁄ 字号 评论关闭

1、添加新的硬盘

[root@test001 ~]# fdisk -l

Disk /dev/sda: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2088    16667437+  8e  Linux LVM

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         609     4891761   83  Linux
/dev/sdb2             610        1218     4891792+  83  Linux
/dev/sdb3            1219        1827     4891792+  83  Linux
/dev/sdb4            1828        3916    16779892+   5  Extended
/dev/sdb5            1828        2436     4891761   83  Linux
/dev/sdb6            2437        3045     4891761   83  Linux
/dev/sdb7            3046        3916     6996276   83  Linux

Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1305    10482381   8e  Linux LVM

Disk /dev/sdd: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

看到新添加的硬盘/dev/sdd

2、格式化硬盘

[root@test001 ~]# fdisk /dev/sdd

The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044): 
Using default value 1044

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): w
The partition table has been altered!

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

3、查看磁盘信息

[root@test001 ~]# fdisk -l /dev/sdd

Disk /dev/sdd: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        1044     8385898+  8e  Linux LVM


4、创建PV(物理卷)

[root@test001 ~]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created

查看系统中的物理卷

[root@test001 ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               15.90 GB / not usable 20.79 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              508
  Free PE               0
  Allocated PE          508
  PV UUID               071V5o-QN2P-u6nQ-1A9A-dn9n-OF2q-Da60ga
   
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               VolGroup00
  PV Size               10.00 GB / not usable 28.70 MB
  Allocatable           yes 
  PE Size (KByte)       32768
  Total PE              319
  Free PE               5
  Allocated PE          314
  PV UUID               S9gULJ-Hz9M-rGNE-x0ar-HX7J-32sf-OpK0fb
   
  "/dev/sdd1" is a new physical volume of "8.00 GB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd1
  VG Name               
  PV Size               8.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               KQJ5kK-5cNG-OgSz-ogqe-7pjc-tIZj-bYw2Ag

5、将PV添加到VG(卷组),VolGroup00

查看先卷组

[root@test001 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               25.84 GB
  PE Size               32.00 MB
  Total PE              827
  Alloc PE / Size       822 / 25.69 GB
  Free  PE / Size       5 / 160.00 MB
  VG UUID               3BzCKt-XD29-6bDz-KCmg-ajTu-N3Jh-odScSf

添加到卷组

[root@test001 ~]# vgextend VolGroup00 /dev/sdd1
  Volume group "VolGroup00" successfully extended

再次查看卷组,卷组已经增大

[root@test001 ~]# vgdisplay 
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               33.81 GB
  PE Size               32.00 MB
  Total PE              1082
  Alloc PE / Size       822 / 25.69 GB
  Free  PE / Size       260 / 8.12 GB
  VG UUID               3BzCKt-XD29-6bDz-KCmg-ajTu-N3Jh-odScSf

6、扩展LV(逻辑卷)

[root@test001 ~]# lvextend -L+8G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 29.78 GB
  Logical volume LogVol00 successfully resized

查看下LV

[root@test001 ~]# lvdisplay 
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                A6HxdN-nREM-72xd-B2JD-joFZ-BkTU-WYawMg
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                29.78 GB
  Current LE             953
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                bSQ4uu-5vWv-4jUb-4ELw-BWuI-Ha83-l1CUwa
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                3.91 GB
  Current LE             125
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

7、

[root@test001 ~]# df -hT
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
              ext3     22G   15G  5.1G  75% /
/dev/sda1     ext3     99M   16M   79M  17% /boot
tmpfs        tmpfs   1006M  653M  354M  65% /dev/shm

上面看到逻辑卷已经增加,系统未增加

使用resize2fs命令将文件系统扩展到增加的空间上:

[root@test001 ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 7806976 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 7806976 blocks long.

[root@test001 ~]# df -hT
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
              ext3     29G   15G   13G  55% /
/dev/sda1     ext3     99M   16M   79M  17% /boot
tmpfs        tmpfs   1006M  653M  354M  65% /dev/shm


抱歉!评论已关闭.