虚拟机 centos 6.5 扩展根目录分区大小

本文详细介绍了如何在虚拟机环境下,通过增加物理空间并转换为LVM格式,最终实现CentOS根目录的扩容。从创建新分区、转换为LVM到扩展卷组及文件系统,每一步都配有具体命令。

要想扩充虚拟机centos 空间,必须先扩充虚拟机本身物理空间.本文只描述如何增加centos系统的根目录空间。以下内容,需要输入命令以红色标出,关键输出内容以蓝色标出。

1 查看磁盘情况

首先登陆root用户,然后使用#fdisk -l 查看系统磁盘会出现以下信息:

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux

/dev/sda2 64 2611 20458496 8e Linux LVM

 

Disk /dev/mapper/vg_zxw-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_zxw-lv_root doesn't contain a valid partition table

 

Disk /dev/mapper/vg_zxw-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

2 创建新的主分区

执行命令 #fdisk /dev/sda之后会出现一系列信息

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):m //“ 列出fdisk的帮助”

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 //输入p,选择创建主分区.我们之前已经有了sda1,sda2,因此此处需要创建的是

Partition number (1-4):3

First cylinder (2611-3916, default 2611): //此时,fdisk又会让你选择该分区的开始值这个就是分区的Start 值(start cylinder);这里最好直接按回车

Using default value 2611

Last cylinder, +cylinders or +size{K,M,G} (2611-3916, default 3916): //此时,fdisk又会让你选择该分区的开始值这个就是分区的End 值这里最好直接按回车

Using default value 3916

 

Command (m for help): w //w "保存所有并退出,分区划分完毕".q不保存退出

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 or after you run partprobe(8) or kpartx(8)

Syncing disks.

3 修改分区为LVM

#fdisk /dev/sda

 

Command (m for help): m

Command (m for help): t //改变分区系统id

 

Partition number (1-4): 3 //指定分区号

Hex code (type L to list codes): 8e //指定要改成的id号,8e代表LVM。

Command (m for help): w

4 重启系统后登录(否则无法扩展分区)

5 格式化改新添加的分区

#fdisk -l

 

 

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux

/dev/sda2 64 2611 20458496 8e Linux LVM

/dev/sda3 2611 3916 10483750 8e Linux LVM

 

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

6 扩展新分区

#lvs

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

#vgextend  vg_ylitech  /dev/sda3 (其中是当前需要扩充的lvm组名,可以通过df -h查看,例如本次教学用的系统为: /dev/mapper/vg_ylitech-lv_root) //vgextend指令用于动态的扩展卷组,它通过向卷组中添加物理卷来增加卷组的容量。

#vgdisplay //用于显示LNM卷组的元数据信息。(可跳过)

--- Volume group ---

VG Name vg_ylitech

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 3

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 2

Open LV 2

Max PV 0

Cur PV 1

Act PV 1

VG Size 19.51 GiB

PE Size 4.00 MiB

Total PE 4994

Alloc PE / Size 4994 / 19.51 GiB

Free PE / Size 4994 / 10.01GB

VG UUID sqBgTs-iA8x-tCXZ-KYxK-SyWS-TfXQ-uBsLaR

(主要查看Free PE / Size 4994 / 10.01GB,说明我们最多可以有10.01GB的扩充空间。我一般选择小于10.01GB)

然后执行以下命令(注意空格)

# lvextend -L+5G /dev/vg_ylitech/lv_root /dev/sda3

// 添加硬盘

# sudo resize2fs /dev/mapper/vg_ylitech-lv_root

//在主分区自动扩展添加的新磁盘

 

完成之后,可以使用df -h 命令,查看磁盘情况,这是已经扩展完成了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tian Fengshou

写的很好,请给我钱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值