Radhat linux 6.3根分区在线扩容

需求: 虚拟机需要扩容硬盘容量,通过vCenter编辑资源设置,将原来50G扩容至100G.但是并不是马上可以使用.以下操作:

修改后100G,登陆虚拟机查看如下:

[[email protected]_test etc]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/rootvg-lv_root

45G  7.0G   36G  17% /

tmpfs                 3.9G   88K  3.9G   1% /dev/shm

/dev/sda1             485M   37M  423M   8% /boot

[[email protected]_test ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 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: 0x000b6327

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        6528    51915776   8e  Linux LVM

Disk /dev/mapper/rootvg-lv_root: 49.0 GB, 48997859328 bytes

255 heads, 63 sectors/track, 5956 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/rootvg-lv_swap: 4160 MB, 4160749568 bytes

255 heads, 63 sectors/track, 505 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

1、操作步骤如下:

fdisk -l           //查看分区列表

fdisk /dev/sda     //分区,先划分extend分区,再划分逻辑分区.本例划为extand为:/dev/sda3,逻辑分区/dev/sda5

m->n -> e -> w

fdisk /dev/sda

m->n -> l -> w

partx -a /dev/sda     //添加指定的分区或读取磁盘并添加所有分区

pvcreate /dev/sda5    //初始化分区

vgextend rootvg /dev/sda5   //将初始化过的分区加入虚拟卷组rootvg中(通过vgdisplay查看)

lvextend -l +100%FREE /dev/mapper/rootvg-lv_root //在线扩容磁盘空间,扩容/dev/mapper/rootvg-lv_root卷空间.

resize2fs /dev/mapper/rootvg-lv_root  //重设大小,扩容/dev/mapper/rootvg-lv_root。

具体操作实例如下:

[[email protected]_test ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000b6327

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM

Disk /dev/mapper/rootvg-lv_root: 49.0 GB, 48997859328 bytes
255 heads, 63 sectors/track, 5956 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/rootvg-lv_swap: 4160 MB, 4160749568 bytes
255 heads, 63 sectors/track, 505 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

1)分区

[[email protected]_test etc]# 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): n

Command action

e   extended

p   primary partition (1-4)

e

Partition number (1-4): 3

First cylinder (6528-13054, default 6528):

Using default value 6528

Last cylinder, +cylinders or +size{K,M,G} (6528-13054, default 13054):

Using default value 13054

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

Syncing disks.

[[email protected]_test etc]# 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): n

Command action

l   logical (5 or over)

p   primary partition (1-4)

l

First cylinder (6528-13054, default 6528):

Using default value 6528

Last cylinder, +cylinders or +size{K,M,G} (6528-13054, default 13054):

Using default value 13054

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

Syncing disks.

分区完成:

[[email protected]_test etc]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 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: 0x000b6327

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        6528    51915776   8e  Linux LVM

/dev/sda3           6528    13054    52427455    5  Extended

/dev/sda5           6528    13054    52427423+  83  Linux

Disk /dev/mapper/rootvg-lv_root: 49.0 GB, 48997859328 bytes

255 heads, 63 sectors/track, 5956 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/rootvg-lv_swap: 4160 MB, 4160749568 bytes

255 heads, 63 sectors/track, 505 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)初始化/dev/sda5,有如下错误提示,partx -a /dev/sda,再次初始化,OK.

[[email protected]_test etc]# pvcreate /dev/sda5

Device /dev/sda5 not found (or ignored by filtering).

[[email protected]_test etc]# partx -a /dev/sda

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

BLKPG: Device or resource busy

error adding partition 3

[[email protected]_test etc]# pvcreate /dev/sda5

Writing physical volume data to disk "/dev/sda5"

Physical volume "/dev/sda5" successfully created

查看vg

[[email protected]_test etc]# vgdisply

--- Volume group ---

VG Name               rootvg

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               49.51 GiB

PE Size               4.00 MiB

Total PE              12674

Alloc PE / Size       12674 / 49.51 GiB

Free  PE / Size       0 / 0

VG UUID               0N5RVO-5Uob-yYm7-HGnp-pg0x-2rPH-aKJpXF

 3)将/dev/sda5添加到VGgroup卷组:rootvg中。

[[email protected]_test etc]# vgextend rootvg /dev/sda5

Volume group "rootvg" successfully extended

 4)在线扩容磁盘空间,扩容/dev/mapper/rootvg-lv_root卷空间.

[[email protected]_test etc]# lvextend -l +100%FREE /dev/mapper/rootvg-lv_root

Extending logical volume lv_root to 95.63 GiB

Logical volume lv_root successfully resized

[[email protected]ao_test etc]# pvdisplay

--- Physical volume ---

PV Name               /dev/sda2

VG Name               rootvg

PV Size               49.51 GiB / not usable 3.00 MiB

Allocatable           yes (but full)

PE Size               4.00 MiB

Total PE              12674

Free PE               0

Allocated PE          12674

PV UUID               UIP0kz-a3Xo-4X0V-P78o-t1E6-abuc-F0qqr7

--- Physical volume ---

PV Name               /dev/sda5

VG Name               rootvg

PV Size               50.00 GiB / not usable 2.66 MiB

Allocatable           yes (but full)

PE Size               4.00 MiB

Total PE              12799

Free PE               0

Allocated PE          12799

PV UUID               JijY54-GseR-NvPU-FEzv-ZvMi-8CRp-m5AFhP

 没有重设大小,

[[email protected]_test etc]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/rootvg-lv_root

45G  7.0G   36G  17% /

tmpfs                 3.9G   88K  3.9G   1% /dev/shm

/dev/sda1             485M   37M  423M   8% /boot

5)重设卷大小

[[email protected]_test etc]# resize2fs /dev/mapper/rootvg-lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/mapper/rootvg-lv_root is mounted on /; on-line resizing required

old desc_blocks = 3, new_desc_blocks = 6

Performing an on-line resize of /dev/mapper/rootvg-lv_root to 25068544 (4k) blocks.

The filesystem on /dev/mapper/rootvg-lv_root is now 25068544 blocks long.

再次查看,已经扩容成功

[[email protected]_test etc]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/rootvg-lv_root

95G  7.0G   83G   8% /

tmpfs                 3.9G   88K  3.9G   1% /dev/shm

/dev/sda1             485M   37M  423M   8% /boot

[[email protected]_test ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 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: 0x000b6327

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64        6528    51915776   8e  Linux LVM

/dev/sda3            6528       13054    52427455    5  Extended

/dev/sda5            6528       13054    52427423+  83  Linux

Disk /dev/mapper/rootvg-lv_root: 102.7 GB, 102680756224 bytes

255 heads, 63 sectors/track, 12483 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/rootvg-lv_swap: 4160 MB, 4160749568 bytes

255 heads, 63 sectors/track, 505 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

[[email protected]_test ~]#

时间: 2024-10-20 01:33:10

Radhat linux 6.3根分区在线扩容的相关文章

linux 根分区LVM扩容

linux 根分区LVM扩容 ### df -h 看看现在硬盘的情况 #lsblk 查看磁盘目录 # fdisk -l 可以看到新添加的硬盘/dev/sdb #分区: n p enter t 8e W # lvm lvm>vgdisplay 可以先看卷组是否还有剩余空间可以扩展, 有的话直接扩展,没有或不够的话把新的硬盘添加进去 同时查看到 VG组名: Centos # lvm>pvcreate /dev/sdb1 使用新的整个硬盘创建一个lvm物理卷 #将新创建的物理卷加入VG组 #vgdi

Linux下扩展根分区-非LVM

在配置大数据节点的过程中,node03节点由于安装了图形化界面,以及IDEA等工具,导致/根分区只有几百兆了,因此需要对根分区进行扩容,本文是在参考如下博文(https://www.jianshu.com/p/9db2df60fd0a)的基础上完成的,感谢被引用的博主,这里也记录一下. VMware虚拟机中配置 (1)进入虚拟机设置界面,选择扩展磁盘容量. (2) 本次是在原来30G的基础上扩展为50G. (3)成功后发现提示,必须从客户机操作系统内部对磁盘重新进行分区和扩展文件系统,因此需要进

VM下--Linux根分区磁盘扩容

转载请注明源出处:http://www.cnblogs.com/lighten/p/6825938.html 1.缘由 由于需要对虚拟机中的软件进行升级,执行yum update的时候,整个更新包在800MB以上,但是根分区的大小只剩下400MB不到,当时创建的时候也只分配了10G的空间.因此必须对根分区的大小进行扩容,网上找了很多方法,但是由于我的情况比较特殊,折腾来折腾去总算是弄好了,故此记录一下,进行分享. 之前安装虚拟机的时候是分配了20G的空间,但是分为了两个挂载点/和/home,所以

centos7根分区硬盘扩容

运用虚拟机经常会出现硬盘容量不足的情况,在不改变配置的要求下,直接对根目录增加容量. centos7的默认安装已经把磁盘管理成LVM的卷形式,可以比较容易扩展磁盘容量.但是centos7在拓展文件分区的时候,很多文章用resize2fs命令,就会报错,LVM使用了XFS的分区文件格式,就不能用该命令了. 目前还有很多使用的硬盘是MBR模式,主分区只能有4个.安装的时候用了2个,一个是swap一个是root,分别使用了两个分区.这样就只能分2个,如果对未来的使用不确定,那么扩展的时候,就不要分主分

linux扩展根分区详细步骤

Linux虚拟机扩展根分区! 虚拟机根分区空间不够用,在虚拟机管理界面进行单个磁盘扩展(图形化界面操作略),比如原来是30G,扩展至40G,(扩展需要关机之后操作) 其中的10G空间需要重新分区,以下是分区相关操作让扩展的空间生效: 登录系统之后: df -h  发现空间没有发生变化: [[email protected] ~]# df -h Filesystem            Size  Used Avail Use% Mounted on /dev/mapper/VolGroup-l

centos7上对LVM根分区扩容vg无法添加pv故障解决

一次,我们的备份数据库的虚拟机出现了异常,备份程序异常终止.经过检查是根分区满了.如下所示:因为根分区默认是采用LVM,所以我就想着直接添加一块硬盘,然后添加到LVM里面,直接对根分区扩容.根分区扩容方式参考之前的写的博客https://blog.51cto.com/11555417/2336797但是在执行到vgextend命令时,一直提示错误,无法对vg进行扩充 Couldn't create temporary archive name.后来查询到问题所在原来是根分区满了,无法创建归档名称

linux根分区扩容

今天网站上传图片出问题了,一开始还以为是程序问题,后来发现原来是服务器存储空间不够,明明有200G的磁盘空间,没理由这么快就用完,查了一下分区情况,原来有两块磁盘,根分区只挂载在大少只有10g那块磁盘上面,而且已使用了100%了!接着就要为根分区扩容了:(环境:redhat 5.2 x64) 1:查看分区情况 shell>fdisk -l Disk /dev/sda doesn't contain a valid partition table, 这句说明了190g的磁盘没分区 2:磁盘分区 s

centos7下在线扩容根分区

知识概要:在kvm那章,我们知道centos7默认是启用lvm的,vg组名为centos,根分区所在文件系统名为/dev/mapper/centos-root,默认根分区是分50G的 接下来进入正题 随着使用的深入,根分区总是不够用的,此时需要扩容,在线扩容无疑是最好的 一.先添加一块磁盘,你不重启,用fdisk -l是看不到的,此时需要执行下面脚本 #不关机使添加硬盘生效 numbers=`ls -l /sys/class/scsi_host/host* | wc -l` for ((i=0;

linux扩容根分区脚本,适合用于centos 6、centos 7版本

#!/bin/bash#auther chentongsan,time 2019-05-30#Description: 适用于系统根分区扩容,第一次.第二次.第三次--..适合用于centos 6.centos 7版本#扫描总线,识别新增添加的磁盘.echo "- - -" > /sys/class/scsi_host/host0/scanecho "- - -" > /sys/class/scsi_host/host1/scanecho "-