设为首页 收藏本站
查看: 693|回复: 0

[经验分享] Radhat linux 6.3根分区在线扩容

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-7-5 08:59:14 | 显示全部楼层 |阅读模式
需求: 虚拟机需要扩容硬盘容量,通过vCenter编辑资源设置,将原来50G扩容至100G.但是并不是马上可以使用.以下操作:
wKioL1d6mWuCIUL8AAA4Dt_3u9w879.jpg
修改后100G,登陆虚拟机查看如下:
[iyunv@loveyao_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
[iyunv@loveyao_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。
具体操作实例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[iyunv@loveyao_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)分区
[iyunv@loveyao_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.
[iyunv@loveyao_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.

分区完成:
[iyunv@loveyao_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.
[iyunv@loveyao_test etc]# pvcreate /dev/sda5
  Device /dev/sda5 not found (or ignored by filtering).
[iyunv@loveyao_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
[iyunv@loveyao_test etc]# pvcreate /dev/sda5
  Writing physical volume data to disk "/dev/sda5"
  Physical volume "/dev/sda5" successfully created
查看vg
[iyunv@loveyao_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中。
[iyunv@loveyao_test etc]# vgextend rootvg /dev/sda5
  Volume group "rootvg" successfully extended
4)在线扩容磁盘空间,扩容/dev/mapper/rootvg-lv_root卷空间.
[iyunv@loveyao_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
[iyunv@loveyao_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
   没有重设大小,
[iyunv@loveyao_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)重设卷大小
[iyunv@loveyao_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.
再次查看,已经扩容成功
[iyunv@loveyao_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

[iyunv@loveyao_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

[iyunv@loveyao_test ~]#



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-239534-1-1.html 上篇帖子: 自定义Linux 终端/ssh登录前后的欢迎信息 下篇帖子: Linux中变量$#,$@,$0,$1,$2,$*,$$,$?的含义 linux 在线
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表