CentOS使用LVM扩充空间实验

软件环境:VirtualBox4.1.10 r76836安装CentOS6.2 64bit

分区情况:
系统原有一块磁盘/dev/sda 21.5GB
/root 单独挂载一个485MB的分区sda1
LVM系统创建在sda2,卷组名为vg_centos6264
分为两个逻辑卷lv_root,lv_swap,用于挂载”/”和”swap”
均使用ext3文件系统

实验目的:

新增一块磁盘,将其加入LVM系统中,为逻辑卷lv_root扩容。

# fdisk -l #查看磁盘信息,以下信息可以看到系统认出了一块新加未分区磁盘sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn’t contain a valid partition table

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005e9cd

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/mapper/vg_centos6264-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_centos6264-lv_root doesn’t contain a valid partition table

Disk /dev/mapper/vg_centos6264-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_centos6264-lv_swap doesn’t contain a valid partition table

# fdisk /dev/sdb #为新加磁盘sdb分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd800b07d.
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)

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).

Command (m for help): n #创建新的分区
Command action
e   extended
p   primary partition (1-4)
p #输入p创建主分区
Partition number (1-4): 1 #输入主分区编号1
First cylinder (1-2610, default 1):  #直接回车,分区从第一个柱面开始
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): #直接回车,分区截至最后一个柱面,即整块硬盘
Using default value 2610

Command (m for help): t #格式化分区,因为该硬盘只有一个分区,所以无需选择分区
Selected partition 1
Hex code (type L to list codes): 8e #将整个分区作为LVM系统类型
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p #显示该硬盘当前分区表

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd800b07d

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  8e  Linux LVM

Command (m for help): w #将当前的分区设置保存,并退出fdisk
The partition table has been altered!

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

# pvcreate /dev/sdb1 #建立物理卷
Writing physical volume data to disk “/dev/sdb1”
Physical volume “/dev/sdb1” successfully created

# vgscan #查看系统中的卷组,得到系统中存在的卷组名
Reading all physical volumes.  This may take a while…
Found volume group “vg_centos6264” using metadata type lvm2

# vgextend vg_centos6264 /dev/sdb1 #将新建的物理卷扩展到已存在的卷组中
Volume group “vg_centos6264” successfully extended

# vgdisplay #查看卷组状态,确定卷组已扩容
— Volume group —
VG Name               vg_centos6264
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               39.50 GiB
PE Size               4.00 MiB
Total PE              10112
Alloc PE / Size       4994 / 19.51 GiB
Free  PE / Size       5118 / 19.99 GiB
VG UUID               2TEysv-wPyV-Exv5-17Y1-5aZc-5g3M-13L418

# lvdisplay /dev/vg_centos6264/lv_root #查看逻辑卷状态
— Logical volume —
LV Name                /dev/vg_centos6264/lv_root
VG Name                vg_centos6264
LV UUID                qwyrwt-60Kh-H02d-Twc5-2B7c-RcEi-tzoHoi
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                17.54 GiB
Current LE             4490
Segments               1
Allocation             inherit
Read ahead sectors     auto
– currently set to     256
Block device           253:0

# lvextend -L +19.99G /dev/vg_centos6264/lv_root #将卷组中的Free Size:19.99 GiB全部加入逻辑卷
Rounding up size to full physical extent 19.99 GiB
Extending logical volume lv_root to 37.53 GiB
Logical volume lv_root successfully resized

# lvdisplay /dev/vg_centos6264/lv_root #重新查看逻辑卷状态,发现空间增加
— Logical volume —
LV Name                /dev/vg_centos6264/lv_root
VG Name                vg_centos6264
LV UUID                qwyrwt-60Kh-H02d-Twc5-2B7c-RcEi-tzoHoi
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                37.53 GiB
Current LE             9608
Segments               2
Allocation             inherit
Read ahead sectors     auto
– currently set to     256
Block device           253:0

# mount /dev/vg_centos6264/lv_root #重新挂载逻辑卷
mount: /dev/mapper/vg_centos6264-lv_root already mounted or / busy
mount: according to mtab, /dev/mapper/vg_centos6264-lv_root is already mounted on /

# df -h #查看挂载系统状态,如果”/”空间并未增加,如果使用ext3文件系统,则可用resize2fs命令来扩容。
文件系统          容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_centos6264-lv_root
18G  3.9G   13G  24% /
tmpfs                 751M  260K  751M   1% /dev/shm
/dev/sda1             485M   53M  407M  12% /boot
vboxshare              98G   71G   27G  73% /media/sf_vboxshare
vboxshare              98G   71G   27G  73% /mnt/vboxshare

# resize2fs /dev/vg_centos6264/lv_root #使用resize2fs在线增加ext3文件系统
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_centos6264/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/vg_centos6264/lv_root to 9838592 (4k) blocks.
The filesystem on /dev/vg_centos6264/lv_root is now 9838592 blocks long.

注:如果是其他文件系统则需要使用不同的扩容命令,比如XFS使用xfs_growfs,ReiserFS使用resize_reiserfs -f等等。

# df -h #查看挂载系统状态,发现”/”已经扩容。
文件系统          容量  已用  可用 已用%% 挂载点
/dev/mapper/vg_centos6264-lv_root
37G  3.9G   32G  12% /
tmpfs                 751M  260K  751M   1% /dev/shm
/dev/sda1             485M   53M  407M  12% /boot
vboxshare              98G   71G   27G  73% /media/sf_vboxshare
vboxshare              98G   71G   27G  73% /mnt/vboxshare

2012年3月30日 | 归档于 CentOS
标签: ,
本文目前尚无任何评论.

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>