文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>resizing lvm volumes in linux...

resizing lvm volumes in linux...

时间:2010-08-19  来源:finewings

Resizing LVM Volumes in Linux: 

By David Maphis 4/29/2008 

In this example I will changed the size of my root partition without 

affecting any data. Since this is a VM, I can extend my vmdk with the 

“vmkfstools” command. To do this I will have to shutdown the VM to release 

the lock on the file then resize it. Power up when complete. 

Once this is done, make a partition that uses the available space you wish to 

add to the LVM volume using “parted”. It has an interactive shell, so just 

enter “parted” in a shell: 

parted 

(parted) print 

Model: VMware Virtual disk (scsi) 

Disk /dev/sda: 10.7GB 

Sector size (logical/physical): 512B/512B 

Partition Table: msdos 

 

Number  Start   End     Size    Type     File system  Flags 

 1      32.3kB  206MB   206MB   primary  ext3         boot 

 2      206MB   8587MB  8382MB  primary               lvm 

So I have from 8588MB to 10.7GB available for a new partition. For this 

example I’m only using up to 9588MB. Your numbers will obviously vary. 

So now let’s make a partition from the new space: 

(parted) mkpart primary 8588 9588 

 

(parted) print 

Model: VMware Virtual disk (scsi) 

Disk /dev/sda: 10.7GB 

Sector size (logical/physical): 512B/512B 

Partition Table: msdos 

 

Number  Start   End     Size    Type     File system  Flags 

 1      32.3kB  206MB   206MB   primary  ext3         boot 

 2      206MB   8587MB  8382MB  primary               lvm 

 3      8587MB  9588MB  1001MB  primary 

You can now see that we have allocated a total of 1001MB of space to 

partition 3 or /dev/sda3. 

Next we need to create a Physical Volume (PV) with “pvcreate”. LVM also has 

an interactive shell, so type “lvm” in a shell prompt: 

lvm 

lvm> pvcreate /dev/sda3 

  Physical volume "/dev/sda3" successfully created 

 

lvm> pvs 

  PV         VG         Fmt  Attr PSize   PFree 

  /dev/sda2  VolGroup00 lvm2 a-     7.78G  32.00M 

  /dev/sda3             lvm2 --   954.44M 954.44M  

Now there is a partition that is about 1GB of space available on PV 

/dev/sda3. 

Now we need to extend the Volume Group (VG) to include the new PV with the 

“vgextend” command: 

lvm> vgextend VolGroup00 /dev/sda3 

  Volume group "VolGroup00" successfully extended 

lvm> pvs 

  PV         VG         Fmt  Attr PSize   PFree 

  /dev/sda2  VolGroup00 lvm2 a-     7.78G  32.00M 

  /dev/sda3  VolGroup00 lvm2 a-   928.00M 928.00M 

By virtue of the fact that we used the same name as the existing VG, we have 

now included this PV in the VG. 

Extend the Logical Volume (LV) to include the new space with “lvextend”. To 

determine that size of the extents we want to add, we first need to view the 

VG: 

lvm> vgdisplay VolGroup00 

  --- Volume group --- 

  VG Name               VolGroup00 

  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               8.69 GB 

  PE Size               32.00 MB 

  Total PE              278 

  Alloc PE / Size       248 / 7.75 GB 

  Free  PE / Size       30 / 960.00 MB 

  VG UUID               Ll4Bg4-jIFV-lfut-z4Ae-JTfH-0Hzp-Zf9RjM 

Looking at this we can see that the total “Free  PE” is 30. We will use this 

in the following command: 

lvm> lvextend -l+30 /dev/VolGroup00/LogVol00 

  Extending logical volume LogVol00 to 8.19 GB 

  Logical volume LogVol00 successfully resized 

 

lvm> lvs 

  LV       VG         Attr   LSize   Origin Snap%  Move Log Copy% 

  LogVol00 VolGroup00 -wi-ao   8.19G 

  LogVol01 VolGroup00 -wi-ao 512.00M 

 So there you are, you have now extended your LV. Now we have to clue the OS 

in what is happening. 

We need to expand the file system to make the new space visible to the OS 

with resize2fs (Fedora, CentOS) or ext2online (RedHat) 

[root@labserver02 dev]# df -h / 

Filesystem            Size  Used Avail Use% Mounted on 

/dev/mapper/VolGroup00-LogVol00 

                      7.1G  1.3G  5.4G  20% / 

 

[root@labserver02 dev]# resize2fs 

resize2fs 1.40.2 (12-Jul-2007) 

Usage: resize2fs [-d debug_flags] [-f] [-F] [-p] device [new_size] 

 

[root@labserver02 dev]# resize2fs /dev/VolGroup00/LogVol00 

resize2fs 1.40.2 (12-Jul-2007) 

Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing 

required 

old desc_blocks = 1, new_desc_blocks = 1 

Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2146304 (4k) 

blocks. 

The filesystem on /dev/VolGroup00/LogVol00 is now 2146304 blocks long. 

 

[root@labserver02 dev]# df -h / 

Filesystem            Size  Used Avail Use% Mounted on 

/dev/mapper/VolGroup00-LogVol00 

                      8.0G  1.3G  6.3G  17% / 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载