centos扩展lv(centos7扩展磁盘空间)
红帽linux,centos7 添加磁盘到/(根目录下),扩展VG卷和lv
为了在红帽Linux的CentOS7系统中扩展根目录(/)下的磁盘,添加新磁盘并扩展VG(Volume Group)和LV(Logical Volume),请遵循以下步骤。
首先,使用fdisk命令创建新的分区。在终端输入:
fdisk/dev/sdb
在新打开的窗口中,按照提示操作添加新的分区。选择“n”新建分区,“p”设置为主分区,输入分区编号“1”,并选择默认大小,最后输入“w”保存并退出。
接着,将新分区加入VG中,以此扩充VG的大小。使用vgextend命令执行如下操作:
[tr][/tr][/table] [root@localhost~]# vgextend centos/dev/sdb1
这条命令将VG名称“centos”与磁盘的位置“/dev/sdb1”进行连接,成功扩展VG。
查看VG状态,确认扩展操作成功:
[root@localhost~]# vgs
通过lvs命令进一步检查LV的状态,虽然VG已扩展,但LV仍需调整大小:
[root@localhost~]# lvs
使用lvextend命令扩展LV的大小,具体命令如下:
[root@localhost~]# lvextend-L+20G/dev/mapper/centos-root
这将LV的大小从17.47GB增加至37.47GB。执行完命令后,使用df-h查看文件系统容量变化,若未见更新,需执行xfs_growfs命令重新读取大小:
[root@localhost~]# xfs_growfs/dev/mapper/centos-root
执行后使用df-h再次检查,确认文件系统大小已调整。
至此,根目录下的磁盘容量已成功扩展。
注意:在自定义创建VG组及在新VG中生成LV时,使用vgcreate命令创建VG,使用lvcreate命令在新VG中创建LV(需指定VG名称)。执行vgreduce将PV从VG中移除,若VG中只有一个PV,则直接使用vgremove。
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文件系统的扩容操作。