将LINUX系统下的一个分区/dev/sda6划给linux的LVM使用,具体操作如下:

1.用 fdisk /dev/sda分区

2.pvcreate /dev/sda6

3.vgextend VolGroup00 /dev/sda6

4.lvextend -L +10G /dev/VolGroup/LogGroup02

5.e2fsck -f /dev/VolGroup/LogGroup02

6.resize2fs /dev/VolGroup/LogGroup02

这就好了,第6步是让扩展的空间生效,要不你会发现df后磁盘的空间并没有扩大。

Expanding a LVM logical volume

This tip explains how to expand an existing logical volume by adding a new new physical volume to a volume group through LVM. The e2fsprogs and lvm2 packages are required to follow these steps, but these packages are mandatory on systems that use ext2/ext3 on a LVM2 logical volume.

Situation

Volume group: MindbenderGroup

Logical volume: MindbenderHome

Physical storage device to add: /dev/sda5 of type "Linux LVM"

Adding a physical device for use by LVM

Add /dev/sda5 as a physical volume that can be used for LVM:

# lvm pvcreate /dev/sda5

Adding the physical volume to the volume group

Add this physical volume to the volume group "MindbenderGroup":

# lvm vgextend "MindbenderGroup" /dev/sda5
  Volume group "MindbenderGroup" successfully extended

Determine the size of the extended volume

Get the site of the expanded volume group first:

# lvm vgdisplay
  --- Volume group ---
  VG Name               MindbenderGroup
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               72.59 GB
  PE Size               32.00 MB
  Total PE              2323
  Alloc PE / Size       1129 / 35.28 GB
  Free  PE / Size       1194 / 37.31 GB
  VG UUID               6OXHId-sean-ZBR2-wuOy-yjVR-cQeB-PJIvrD

We can see here that 1129 of 2323 physical extends (PE) are in use. But there are two logical volumes, so we have to look up the size of the volume that we would like to extend:

# lvm lvdisplay /dev/MindbenderGroup/MindbenderHome
  --- Logical volume ---
  LV Name                /dev/MindbenderGroup/MindbenderHome
  VG Name                MindbenderGroup
  LV UUID                RQtp4K-Wca2-uivW-3rVn-GfZE-hYea-KKH5pT
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                33.34 GB
  Current LE             1067
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0

The current size is 1067 PEs, and we have 1194 free extends, so the new volume size will be 1067 + 1194 = 2261.

Extending the volume

We can now easily extend the volume, by specifying the new number of PEs:

# lvm lvresize -l 2261 /dev/MindbenderGroup/MindbenderHome
  Extending logical volume MindbenderHome to 70.66 GB
  Logical volume MindbenderHome successfully resized

Resizing the filesystem

The volume is now expanded, but the filesystem still has its old size. You have 2 solutions to expand the filesytem :

  • You can either umount the volume , use resize2fs and then mount it back :
# umount /dev/MindbenderGroup/MindbenderHome
# resize2fs /dev/MindbenderGroup/MindbenderHome
# mount /dev/MindbenderGroup/MindbenderHome
  • Or you can resize the filesystem without umounting the device (applications can still write/read datas on disk), a.k.a online resizing :

CentOS 4

# ext2online /dev/MindbenderGroup/MindbenderHome

CentOS 5

# resize2fs /dev/MindbenderGroup/MindbenderHome

(In CentOS 5 the ext2online command has been removed and the online resizing code has been merged into resize2fs)

How to expand an LVM partition on a Linux/Centos VMware ESXi server

So you have this sweet vmware server with like 5 linux servers running on it but one of the vm’s ran out of space. You have 200Gb of space left on your drive so its time to expand. Well we run into this a lot with vm’s, it seems easy and it can be if you know how to expand lvm partition. If you don’t know then you have come to the right place.  Alright well lets start expanding an LVM Partition!

1. Go into VMware infrastructure Client, edit the hard drive settings to the size you want. Now reboot your vm, not the entire server just the machine you changed the hard drive size on.

2.After powering the VM back on, I now have to create a partition that will incorporate the new space:

[root@server ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 5874.
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): 3
First cylinder (5222-5874, default 5222):
Using default value 5222
Last cylinder or +size or +sizeM or +sizeK (5222-5874, default 5874):
Using default value 5874

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 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.
Syncing disks.

Command (m for help): p

Disk /dev/sda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 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 5221 41833260 8e Linux LVM
/dev/sda3 5222 5874 5245222+ 8e Linux LVM

Command (m for help): q

I now have 3 partitions, including my most recent, partition 3 that has been formatted to use LVM. Now I must reboot my VM so that it will include this partition in the table at reboot.

3) Now I must create a physical volume so that I can access my partition with LVM.

[root@server ~]# pvcreate /dev/sda3
Physical volume “/dev/sda3″ successfully created

4) Following that, I need to extend my VolGroup into my new physical Volume:

[root@server ~]# vgextend VolGroup00 /dev/sda3
Volume group “VolGroup00″ successfully extended

5) With that complete, I need to extend the logical volume into the newly created space. I know that I planned to give myself 5 gigs, but I want to see how the system is really going to give me, so I’m going to run:

[root@server ~]# vgdisplay | grep ‘Free’
Free PE / Size 165 / 5.16 GB

So now I can be sure that I have 5 GB to work with. I can run lvextend to grow my logical volume across the new partition:

[root@server ~]# lvextend -L+5G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 7.47 GB
Logical volume LogVol00 successfully resized

With that completed, I now have the Logical Volume sitting at 7.47 Gigs. I now need to expand the file system to take advantage of the space that was created. This step is normally taken care of with the resize2fs command, but since I’m running RHEL 4, I can take advantage of ext2online command and don’t have to take the filesystem down. I like this idea much better:

[root@server ~]# ext2online /dev/VolGroup00/LogVol00
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b

NOTE: incase you get the error I got on my last expanding, where it saws:

-bash: ext2online: command not found

Just run resize2fs instead of ext2online, so it would look like this:

[root@server ~]# resize2fs /dev/VolGroup00/LogVol00

That’s it! Now when I run my df -h, I have all the space I was needing. Keep watching our blog for more linux help! Thanks!

Extending a logical volume

To extend a logical volume you simply tell the lvextend command how much you want to increase the size. You can specify how much to grow the volume, or how large you want it to grow to:

# lvextend -L12G /dev/myvg/homevollvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
will extend /dev/myvg/homevol to 12 Gigabytes.

# lvextend -L+1G /dev/myvg/homevollvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
will add another gigabyte to /dev/myvg/homevol.

After you have extended the logical volume it is necessary to increase the file system size to match. how you do this depends on the file system you are using.

By default, most file system resizing tools will increase the size of the file system to be the size of the underlying logical volume so you don't need to worry about specifying the same size for each of the two commands.

  1. ext2/ext3

    Unless you have patched your kernel with the ext2online patch it is necessary to unmount the file system before resizing it. (It seems that the online resizing patch is rather dangerous, so use at your own risk)

    # umount /dev/myvg/homevol/dev/myvg/homevol
       # resize2fs /dev/myvg/homevol
       # mount /dev/myvg/homevol /home

    If you don't have e2fsprogs 1.19 or later, you can download the ext2resize command from ext2resize.sourceforge.net and use that:

    # umount /dev/myvg/homevol/dev/myvg/homevol
       # ext2resize /dev/myvg/homevol
       # mount /dev/myvg/homevol /home

    For ext2 there is an easier way. LVM 1 ships with a utility called e2fsadm which does the lvextend and resize2fs for you (it can also do file system shrinking, see the next section).

    WarningLVM 2 Caveat
     

    There is currently no e2fsadm equivalent for LVM 2 and the e2fsadm that ships with LVM 1 does not work with LVM 2.

    so the single command
    # e2fsadm -L+1G /dev/myvg/homevol
    is equivalent to the two commands:
    # lvextend -L+1G /dev/myvg/homevol
       # resize2fs /dev/myvg/homevol
    NoteNote
     

    You will still need to unmount the file system before running e2fsadm.

  2. reiserfs

    Reiserfs file systems can be resized when mounted or unmounted as you prefer:

    • Online:

      # resize_reiserfs -f /dev/myvg/homevol

    • Offline:

      # umount /dev/myvg/homevol
         # resize_reiserfs /dev/myvg/homevol
         # mount -treiserfs /dev/myvg/homevol /home

  3. xfs

    XFS file systems must be mounted to be resized and the mount-point is specified rather than the device name.

    # xfs_growfs /home

  4. jfs

    Just like XFS the JFS file system must be mounted to be resized and the mount-point is specified rather than the device name. You need at least Version 1.0.21 of the jfs-utils to do this.

    # mount -o remount,resize /home

    WarningKnown Kernel Bug
     

    Some kernel versions have problems with this syntax (2.6.0 is known to have this problem). In this case you have to explicitly specify the new size of the filesystem in blocks. This is extremely error prone as you must know the blocksize of your filesystem and calculate the new size based on those units.

    Example: If you were to resize a JFS file system to 4 gigabytes that has 4k blocks, you would write:

    # mount -o remount,resize=1048576 /home

更多资源:

LVM HOWTO

此文章由 flyinweb 于 2010-08-13 10:20:04 编辑

本日志由 flyinweb 于 2010-08-13 09:46:35 发表,目前已经被浏览 4457 次,评论 0 次;

作者添加了以下标签: LVM

引用通告:http://www.517sou.net/Article/507/Trackback.ashx

评论订阅:http://www.517sou.net/Article/507/Feeds.ashx

相关文章

评论列表

    暂时没有评论
(必填)
(必填,不会被公开)