Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174102
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 305
  • 用 户 组: 普通用户
  • 注册时间: 2016-02-01 12:35
个人简介

不断超越自己,将更强大!

文章分类

全部博文(35)

文章存档

2022年(1)

2017年(5)

2016年(29)

我的朋友

分类: LINUX

2016-02-27 23:00:46

           我们在使用虚拟机的过程中进程会遇到磁盘空间不足的情况,下面就介绍一下怎么给虚拟机的根目录扩展空间。

扩展前的磁盘空间情况:

[ ~]# df -h 

Filesystem Size Used Avail Use% Mounted on 
/dev/mapper/VolGroup00-LogVol00 
16G 11G 4.2G 72% / 
/dev/sda1 99M 16M 78M 17% /boot 
tmpfs 1005M 0 1005M 0% /dev/shm


1、关闭虚拟机在cmd窗口下使用vmware-vdiskmanager.exe命令扩展文件大小,这一步也可以在虚拟机的界面上增加

"C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe" -x 40GB "Y:\VM\RAC 11G\RAC1102\RAC1101.vmdk"

把磁盘空间扩展到40G,包含原来的20G,即增加20G

2、启动虚拟机,使用Linux的fdisk分区工具给磁盘分区

[ ~]# fdisk -l 


Disk /dev/sda: 42.9 GB, 42949672960 bytes 
255 heads, 63 sectors/track, 5221 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 2610 20860402+ 8e Linux LVM 

根据提示信息可以判断出此系统的磁盘接口为SCSI,对应“sda”,如果上面的红色字体是“hda”,那么此系统的磁盘接口为IDE对应“hda”。下面开始分区

[ ~]# fdisk /dev/sda 

The number of cylinders for this disk is set to 5221. 
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): m //查看帮助

Command action 
a toggle a bootable flag 
b edit bsd disklabel 
c toggle the dos compatibility flag 
d delete a partition 
l list known partition types 
m print this menu 
n add a new partition 
o create a new empty DOS partition table 
p print the partition table 
q quit without saving changes 
s create a new empty Sun disklabel 
t change a partition's system id 
u change display/entry units 
v verify the partition table 
w write table to disk and exit 
x extra functionality (experts only)

Command (m for help): n // n 是增加分区

Command action 
e extended 
p primary partition (1-4) 
p   //" 选择创建主分区"此时

Partition number (1-4): 3   //已经就1,2两个分区了,这里分为第三个区

First cylinder (2611-5221, default 2611):   //此时,fdisk又会让你选择该分区的开始值这个就是分区的Start 值(start cylinder);这里最好直接按回车
Using default value 2611 
Last cylinder or +size or +sizeM or +sizeK (2611-5221, default 5221):   //此时,fdisk又会让你选择该分区的开始值这个就是分区的End 值这里最好直接按回车
Using default value 5221 

Command (m for help):  w  //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. 
[ ~]# fdisk -l 

Disk /dev/sda: 42.9 GB, 42949672960 bytes 
255 heads, 63 sectors/track, 5221 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 2610 20860402+ 8e Linux LVM 
/dev/sda3 2611 5221 20972857+ 83 Linux 



3、使用fdisk将其改成LVM的
[ ~]# fdisk /dev/sda 

The number of cylinders for this disk is set to 5221. 
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): m 
Command action 
a toggle a bootable flag 
b edit bsd disklabel 
c toggle the dos compatibility flag 
d delete a partition 
l list known partition types 
m print this menu 
n add a new partition 
o create a new empty DOS partition table 
p print the partition table 
q quit without saving changes 
s create a new empty Sun disklabel 
t change a partition's system id 
u change display/entry units 
v verify the partition table 
w write table to disk and exit 
x extra functionality (experts only) 

Command (m for help): t //改变分区系统id
Partition number (1-4): 3 //指定分区号,选择分区3

Hex code (type L to list codes): 8e //指定要改成的id号,8e代表LVM
Changed system type of partition 3 to 8e (Linux LVM) 

Command (m for help): w    //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. 

备注:以上的操作,可以图形界面的方式实现!!

4、重启系统,格式化该新添加的分区

[ ~]# fdisk -l 

Disk /dev/sda: 42.9 GB, 42949672960 bytes 
255 heads, 63 sectors/track, 5221 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 2610 20860402+ 8e Linux LVM 
/dev/sda3 2611 5221 20972857+ 8e Linux LVM

已经增加了一个分区,格式也改为LVM

#mkfs  -t   ext3  /dev/sda3           //在硬盘分区“/dev/sda3”上创建“ext3”文件系统。

[ ~]# mkfs -t ext3 /dev/sda3 
mke2fs 1.39 (29-May-2006) 
warning: 334 blocks unused. 

Filesystem label= 
OS type: Linux 
Block size=4096 (log=2) 
Fragment size=4096 (log=2) 
2626560 inodes, 5242880 blocks 
262160 blocks (5.00%) reserved for the super user 
First data block=0 
Maximum filesystem blocks=4294967296 
160 block groups 
32768 blocks per group, 32768 fragments per group 
16416 inodes per group 
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
4096000 

Writing inode tables: done 
Creating journal (32768 blocks): done 
Writing superblocks and filesystem accounting information: done 

This filesystem will be automatically checked every 36 mounts or 
180 days, whichever comes first. Use tune2fs -c or -i to override.


以下才为重点:

5、扩展文件系统

创建PV

[ ~]# pvcreate /dev/sda3 
Physical volume "/dev/sda3" successfully created

//pvcreate指令用于将物理硬盘分区初始化为物理卷,以便被LVM使用。要创建物理卷必须首先对硬盘进行分区,并且将硬盘分区的类型设置为“8e”后,才能使用pvcreat指令将分区初始化为物理卷。

扩展VG

[ ~]# vgextend VolGroup00 /dev/sda3 
/dev/hdc: open failed: Read-only file system 
/dev/cdrom: open failed: Read-only file system 
Attempt to close device '/dev/cdrom' which is not open. 
Volume group "VolGroup00" successfully extended

(其中VolGroup00是当前需要扩充的lvm组名,可以通过df -h查看,例如我的是: /dev/mapper/VolGroup00-LogVol00)   //vgextend指令用于动态的扩展卷组,它通过向卷组中添加物理卷来增加卷组的容量。

#vgdisplay           //用于显示LNM卷组的元数据信息。

[ ~]# vgdisplay 
--- 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 39.88 GB 
PE Size 32.00 MB 
Total PE 1276 
Alloc PE / Size 636 / 19.88 GB 
Free PE / Size 640 / 20.00 GB 
VG UUID GEwLeI-DRdi-NKXI-cB89-JQ81-2eMf-C2quKf

(主要查看Free PE / Size 640 / 20.00 GB,说明我们最多可以有20GB的扩充空间。)

扩展LV,这里的扩展空间要小于VG的Free PE

[ ~]# lvextend -L+19.8G /dev/VolGroup00/LogVol00 /dev/sda3 
/dev/hdc: open failed: Read-only file system 
Rounding up size to full physical extent 19.81 GB 
Extending logical volume LogVol00 to 35.78 GB 
Logical volume LogVol00 successfully resized

再查看VG的信息

[ ~]# vgdisplay 
--- Volume group --- 
VG Name VolGroup00 
System ID 
Format lvm2 
Metadata Areas 2 
Metadata Sequence No 5 
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.88 GB 
PE Size 32.00 MB 
Total PE 1276 
Alloc PE / Size 1270 / 39.69 GB 
Free PE / Size 6 / 192.00 MB 
VG UUID GEwLeI-DRdi-NKXI-cB89-JQ81-2eMf-C2quKf


[ ~]# resize2fs /dev/VolGroup00/LogVol00 
resize2fs 1.39 (29-May-2006) 
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required 
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 9404416 (4k) blocks. 
The filesystem on /dev/VolGroup00/LogVol00 is now 9404416 blocks long.

//resize2fs指令被用来增大或者收缩未加载的“ext2/ext3”文件系统的大小。


[ ~]# df -h 
Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00
                       35G   11G   23G  32% /
/dev/sda1              99M   16M   78M  17% /boot
tmpfs                1005M     0 1005M   0% /dev/shm

      这是查看文件系统空间已经扩展成功,如果resize2fs 之后文件系统空间没增加可以尝试重启虚拟机。


阅读(2134) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~