之前创建了一个linux虚拟机(Centos6 ),后来发现默认8G 的 大小不够了,又不想add virtual disk,因此关机后直接调大默认盘的空间,然后调整逻辑卷。其实和增加盘的操作基本相同。
1.格式化物理卷
2.扩大卷组
3.扩大逻辑卷
4.resize2fs
相关命令如下:
[root@localhost ~]# fdisk -l
Disk /dev/xvda: 23.6 GB, 23622320128 bytes
255 heads, 63 sectors/track, 2871 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 13 104391 83 Linux
/dev/xvda2 14 1044 8281507+ 8e Linux LVM
可以看到,增加了磁盘空间后,还有一半的空间没有用到(看柱面的个数)。
[root@localhost ~]# fdisk /dev/xvda
The number of cylinders for this disk is set to 2871.
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 (1045-2871, default 1045):
Using default value 1045
Last cylinder or +size or +sizeM or +sizeK (1045-2871, default 2871):
Using default value 2871
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): q
如上所示,新增分区,保存后退出。
然后格式化物理分区
[root@localhost ~]# pvcreate /dev/xvda3
Device /dev/xvda3 not found (or ignored by filtering).
此处报错,主要是因为fdisk增、删操作顺序有误,导致实际上发生的和系统中的配置不一致,可通过下面的命令解决
[root@localhost ~]# partprobe
[root@localhost ~]# pvcreate /dev/xvda3
Writing physical volume data to disk "/dev/xvda3"
Physical volume "/dev/xvda3" successfully created
[root@localhost ~]#
扩展卷组
[root@localhost ~]# vgextend VolGroup00 /dev/xvda3
Volume group "VolGroup00" successfully extended
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 21.84 GB
PE Size 32.00 MB
Total PE 699
Alloc PE / Size 252 / 7.88 GB
Free PE / Size 447 / 13.97 GB //可见有13.97G可用
VG UUID hSG4Tj-k6SR-qTsw-KFB5-v9qz-tkZT-yc5oTd
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3.9G 2.8G 951M 75% /
/dev/xvda1 99M 14M 81M 15% /boot
tmpfs 257M 0 257M 0% /dev/shm
[root@localhost ~]# lvextend /dev/mapper/VolGroup00-LogVol00 /dev/xvda3
Extending logical volume LogVol00 to 17.94 GB
Logical volume LogVol00 successfully resized
[root@localhost ~]# resize2fs /dev/mapper/VolGroup00-LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-LogVol00 to 4702208 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-LogVol00 is now 4702208 blocks long.
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
18G 2.8G 14G 17% /
/dev/xvda1 99M 14M 81M 15% /boot
tmpfs 257M 0 257M 0% /dev/shm
可见以扩展
遇到问题:
由于自测试,增删分区,导致卷组错乱,在扩大卷组时报错如下:
[root@localhost ~]# vgextend VolGroup00 /dev/xvda3
Couldn't find device with uuid ksrbSP-Vm6g-C1Zq-sWu1-5xnS-ZQ2y-UqIcTO.
Cannot change VG VolGroup00 while PVs are missing.
Consider vgreduce --removemissing.
可通过执行命令
[root@localhost ~]# vgreduce VolGroup00 --removemissing
Volume group "VolGroup00" is already consistent
未解决问题:
在格式分区时(pvcreate /dev/xvda),新增分区只能选择主分区,如果选择扩展分区,之后流程报错。哪位仁兄知道原因,请指点。
阅读(4451) | 评论(1) | 转发(0) |