centos 7 lvm扩容?centos分区扩容

centos系统扩容的问题

着是我经验成果,希望对你有帮助.

有一次我调整VPS的时候发现自己的/分区的空间用光了.但是还剩下一个分区hda3没动.于是乎.想调整到根下面去.但是由于本人新手一个.又不太了解linux的分区机制.所以.百度满世界找答案,终于还是找到了.现在将执行代码贴出来.希望对不有帮助.

以下是Centos5给/分区扩容代码.

[root@localhost~]# fdisk/dev/hda3

The number of cylinders for this disk is set to 3916.

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): p

Disk/dev/hda4: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units= cylinders of 16065* 512= 8225280 bytes

Disk identifier: 0x000bc363

Device Boot Start End Blocks Id System

/dev/hda1* 1 25 200781 83 Linux

/dev/hda2 26 1958 15526822+ 8e Linux LVM

/dev/hda3 1959 2610 5237190 8e Linux LVM

Command(m for help): n

Command action

e extended

p primary partition(1-4)

p

Selected partition 4

First cylinder(2611-3916, default 2611):

Using default value 2611

Last cylinder or+size or+sizeM or+sizeK(2611-3916, default 3916):

Using default value 3916

Command(m for help): t

Partition number(1-4): 4

Hex code(type L to list codes): 8e

Changed system type of partition 4 to 8e(Linux LVM)

Command(m for help): p

Disk/dev/hda: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units= cylinders of 16065* 512= 8225280 bytes

Disk identifier: 0x000bc363

Device Boot Start End Blocks Id System

/dev/hda1* 1 25 200781 83 Linux

/dev/hda2 26 1958 15526822+ 8e Linux LVM

/dev/hda3 1959 2610 5237190 8e Linux LVM

/dev/hda4 2611 3916 10490445 8e Linux LVM

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.

(注:建议重启一下CentOS系统)

[root@localhost~]# pvcreate/dev/hda3

Physical volume"/dev/hda4" successfully created

[root@localhost~]# vgextend VolGroup00/dev/hda3

Volume group"VolGroup00" successfully extended

[root@localhost~]# lvextend-l+100%FREE/dev/VolGroup00/LogVol00

Extending logical volume LogVol00 to 28.25 GB

Logical volume LogVol00 successfully resized

[root@localhost~]# lvresize-l+100%FREE/dev/VolGroup00/LogVol00

New size(904 extents) matches existing size(904 extents)

lvresize: Resize a logical volume

lvresize

[-A|--autobackup y|n]

[--alloc AllocationPolicy]

[-d|--debug]

[-h|--help]

[-i|--stripes Stripes [-I|--stripesize StripeSize]]

{-l|--extents [+|-]LogicalExtentsNumber[%{VG|LV|FREE}]|

-L|--size [+|-]LogicalVolumeSize[kKmMgGtTpPeE]}

[-n|--nofsck]

[-r|--resizefs]

[-t|--test]

[--type VolumeType]

[-v|--verbose]

[--version]

LogicalVolume[Path] [ PhysicalVolumePath... ]

[root@localhost~]# resize2fs/dev/VolGroup00/LogVol00

resize2fs 1.40.2(12-Jul-2007)

Filesystem at/dev/VolGroup00/LogVol00 is mounted on/; on-line resizing required

old desc_blocks= 2, new_desc_blocks= 2

Performing an on-line resize of/dev/VolGroup00/LogVol00 to 7405568(4k) blocks.

The filesystem on/dev/VolGroup00/LogVol00 is now 7405568 blocks long.

centos虚拟机LVM扩容方法:

1、在esxi4.0硬件配置界面,将硬盘直接由原来100G增大到256G

2、用安装光盘启动进入紧急救援系统

3、将增加空间进行分区,我是用Linux下的分区魔术师GParted,光驱启动后,在图形界面下增加一个sda3。其实应该可以用fdisk与parted完成,我没有操作。

4、为了使用 LVM先初始化一块 physical volumn:

pvcreate/dev/sda3

5、然后把它加到卷组(volumn group)里去:

vgextend vgextend VolGroup00/dev/sda3

其中卷组名是通过 vgdisplay看到的。这些命令非常有用: fdisk, parted, mkfs.ext3, df, mount,另外还有/etc/fstab文件。

6、上面加入卷组成功后,扩展逻辑卷的容量,这个逻辑卷就是挂载到/上的分区,可以通过 mount来看到:

lvextend-L+4.5G/dev/VolGroup00/LogVol00

7、最后是两条命令:

e2fsck-f/dev/VolGroup00/LogVol00

resize2fs/dev/VolGroup00/LogVol00

centos下原磁盘扩容后给lvm的root根/文件系统扩容

在CentOS系统中,若需要对原磁盘扩容后给LVM的root文件系统扩容,可以按照以下步骤操作:

1.首先,在云主机管理界面为磁盘扩容,例如将100GB扩展为200GB,务必在操作前创建快照作为备份。

2.使用fdisk-l命令检查新扩容的磁盘,确认其已正确增加。

3.执行fdisk/dev/vda,为新磁盘创建一个新的分区。

4.重启服务器后,通过lsblk查看,新分区应已显示在设备列表中。

5.使用pvscan和vgdisplay命令,确认vg(卷组)的状态,然后执行vgextend centos/dev/vda3,将新分区加入到centos卷组,使其大小变为200GB。

6.接下来,检查逻辑卷(lv)的状况,如果需要,执行lvextend-l+100%FREE/dev/centos/root,按百分比方式为root逻辑卷扩容。

7.如果希望以固定大小追加,可使用lvextend-L+20G命令(替换为实际需要的大小)。

8.完成扩容后,使用df-h检查文件系统空间,确保扩容已生效。

9.最后,通过xfs_growfs/dev/centos/root命令执行文件系统的扩展,以使新空间生效。

10.检查df-h的结果,确认root文件系统已成功扩容。

这样,你就完成了在CentOS环境下,对原磁盘扩容后给LVM root文件系统的扩容操作。

Linux-如何通过LVM对储存空间进行动态扩容

在Linux系统中,逻辑卷管理(LVM)是一种高效的空间管理方式,尤其适用于CentOS 7及以上版本。传统的硬盘分区和扩容可能需要重新创建文件系统并挂载到新的位置,而LVM则提供了更为便捷的解决方案。它将多个原始分区(通过gdisk处理)抽象为逻辑卷组(VG),再将VG划分为可使用的逻辑卷(LV),从而实现动态调整储存空间。

首先,进行硬盘分区时,确保将system ID设置为8E00。接着,使用pvcreate命令将/dev/sda{1,2,3}等分区识别为可管理的物理卷(PV)。接着,通过vgcreate命令将这些PV组合成一个卷组,如vg1,PE大小可自定义,如16M。LV的创建是通过lvcreate,如-l 180G-n lv1 vg1,定义LV的容量和名称。

重要的是,CentOS 7中,XFS格式的文件系统只支持动态扩容,不支持缩小。动态扩容分为两种情况:一是如果原始VG有足够的空间,只需通过lvresize增加LV的大小,如lvresize-L+100G/dev/vg1/lv1,然后执行xfs_growfs使其生效,即可看到文件系统的容量扩展。二是当需要扩容且空间不足时,需添加新硬盘(如/dev/sdb5),按照相同步骤创建PV和VG,使用vgextend命令将新硬盘添加到已有VG,然后按照第一种情况处理即可实现动态扩容。

阅读剩余
THE END