Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150760
  • 博文数量: 52
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-05 12:05
文章分类

全部博文(52)

文章存档

2013年(1)

2010年(3)

2009年(6)

2008年(25)

2007年(17)

我的朋友

分类: LINUX

2007-11-08 12:08:31

LVM Diary

Somehow I met a case about creating a new partition on LVM disk management machine.

I have to find resource and study it, below is my note.

 

LVM is a special file system which can extend or reduce its size easily by a command.

One or more physical partition such as /dev/sda1 (/dev/hda1) make up of LVM, you can add on more physical partition to extend the total size of the LVM file system. So it is really flexible for system administrator to manage system partitions.

 

Physical Volume, short for PV is a type of file system same as swap, ext3 or else, I think.

PV bases on physical partition /dev/sdax, and it has a unique ID 82. So if you want to make a partition become PV, you should use fdisk or parted change its ID to 82 first. Only when partitions become PV, LVM can make use of the partition.

 

Volume Group, short for VG which component is PV, one or more PV make up of a big VG. The big VG can be partition for LV

 

Logical Volume, short for LV is one of VG partition.

 

After clear the basic concepts, create a LV is a easy task.

 

1.         fdisk /dev/hda2, make the ID to 82.

[root@allenlinux /]# fdisk -l

 

Disk /dev/hda: 40.0 GB, 40020664320 bytes

240 heads, 63 sectors/track, 5169 cylinders

Units = cylinders of 15120 * 512 = 7741440 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/hda1   *           1          14      105808+  83  Linux

/dev/hda2              15        5169    38971800   8e  Linux LVM

[root@allenlinux /]#

  

[root@allenlinux /]# partprobe

[root@allenlinux /]#

 

Use partprobe rather than system reboot to make partitions available.

 

2.         Create PV

[root@allenlinux /]#pvcreate /dev/hda2

[root@allenlinux /]# pvscan

  PV /dev/hda2   VG vgroot   lvm2 [37.16 GB / 8.00 GB free]

  Total: 1 [37.16 GB] / in use: 1 [37.16 GB] / in no VG: 0 [0   ]

[root@allenlinux /]#

[root@allenlinux /]# pvdisplay

  --- Physical volume ---

  PV Name               /dev/hda2

  VG Name               vgroot

  PV Size               37.16 GB / not usable 0

  Allocatable           yes

  PE Size (KByte)       4096

  Total PE              9514

  Free PE               2047

  Allocated PE          7467

  PV UUID               QN28tK-AOWu-G5KD-d71b-Bx2N-scaZ-Ti1TkH

 

3.         Create VG

[root@allenlinux /]#vgcreate vgroot /dev/hda2

[root@allenlinux /]# vgdisplay

  --- Volume group ---

  VG Name               vgroot

  System ID

  Format                lvm2

  Metadata Areas        1

  Metadata Sequence No  12

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                7

  Open LV               7

  Max PV                0

  Cur PV                1

  Act PV                1

  VG Size               37.16 GB

  PE Size               4.00 MB

  Total PE              9514

  Alloc PE / Size       7467 / 29.17 GB

  Free  PE / Size       2047 / 8.00 GB

  VG UUID               9SKa2O-Q0yw-I3PD-e3P1-2D2x-hF3i-0GlAQW

 

[root@allenlinux /]# vgscan

  Reading all physical volumes.  This may take a while...

  Found volume group "vgroot" using metadata type lvm2

[root@allenlinux /]#

 

Vgextend can be use to extend the VG to another PV.

Command: vgextend vgroot /dev/hda3

Hda3 should be PV already.

 

4.         After all, you can create LV

Command: lvcreate –L size –n LVname VGname

If VGname didn’t specify the default one vgroot will be used here.

lvcreate -L 15.19G -n /dev/vgroot/lvsvn

 

[root@allenlinux /]# lvscan

  ACTIVE            '/dev/vgroot/lvroot' [1.00 GB] inherit

  ACTIVE            '/dev/vgroot/lvopt' [2.00 GB] inherit

  ACTIVE            '/dev/vgroot/lvtmp' [1.00 GB] inherit

  ACTIVE            '/dev/vgroot/lvusr' [5.98 GB] inherit

  ACTIVE            '/dev/vgroot/lvvar' [3.00 GB] inherit

  ACTIVE            '/dev/vgroot/LogVol00' [1.00 GB] inherit

  ACTIVE            '/dev/vgroot/lvsvn' [15.19 GB] inherit

[root@allenlinux /]#

 

Lvextend is use to extend the size of the LV

Command: lvextend -L 20G /dev/vgroot/lvsvn

 

5.         Mkfs mke2fs and mount the lv partition

mkfs –t ext3 /dev/vgroot/lvsvn

mount /dev/vgroot/lvsvn /svn

[root@allenlinux /]# df -h /svn

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/vgroot-lvsvn

                       15G   71M   15G   1% /svn

[root@allenlinux /]#

 

Note: /boot can’t be LV, because grub can’t read it during boot up.

 
Resize a LVM
A. Resize a mirrored LV
1. Unmount the LV,
 umount /mount_point
2. Disable the LV,
 lvchange -an /dev/vgicil/lvhome
3. Resize the LV
 lvresize -L +3G /dev/vgicil/lvhome
4. Extend the FS on LV, it should run fsck first for extending fs correctly.
 e2fsck -f /dev/mapper/vgicil-lvhome
 resize2fs /dev/mapper/vgicil-lvhome
5. Mount the LV
 mount /mount_point
B. Resize a LV (no mirror)
1. Resize the LV online
 lvresize -L +3G /dev/vgicil/lvhome
2. Extend the FS on LV online
 ext2online /dev/vgicil/lvhome
阅读(924) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~