虚拟机里的linux主分区扩容

[root@zabbix-test ~]# vgdisplay

  --- Volume group ---

  VG Name               VolGroup

  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               swdQhX-7DhD-qiWW-8oeV-ewSP-Djjy-ozdCpy

[root@zabbix-test ~]# lvdisplay 

  --- Logical volume ---

  LV Path                /dev/VolGroup/lv_root

  LV Name                lv_root

  VG Name                VolGroup

  LV UUID                mduTSv-NAbg-wKVi-HHbB-JSrq-YzVu-pOZ6SD

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-06-01 01:43:46 +0800

  LV Status              available

  # open                 1

  LV Size                45.60 GiB

  Current LE             11674

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0


  --- Logical volume ---

  LV Path                /dev/VolGroup/lv_swap

  LV Name                lv_swap

  VG Name                VolGroup

  LV UUID                Jrud8e-iuls-u8uZ-m8IX-c0lQ-pgAe-VK7pJE

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-06-01 01:43:49 +0800

  LV Status              available

  # open                 1

  LV Size                3.91 GiB

  Current LE             1000

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:1


[root@zabbix-test ~]# df -HP

Filesystem                       Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root      49G   37G  9.2G  80% /

tmpfs                            3.1G     0  3.1G   0% /dev/shm

/dev/sda1                        500M   73M  402M  16% /boot

//10.11.0.6/zabbix_mysql_backup  837G  769G   69G  92% /mysqlbackup

[root@zabbix-test ~]# fdisk -l /dev/sda

Disk /dev/sda: 268.4 GB, 268435456000 bytes

255 heads, 63 sectors/track, 32635 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk identifier: 0x0002c75c

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1*           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda264        6528    51915776   8e  Linux LVM

磁盘分区情况总结如下:

/dev/mapper/VolGroup-lv_root 空间不足

另外VolGroup在centos7里应该是centos ,使用过程中注意观察这个名字

/dev/sda 有2个分区

操作步骤:

1)首先关闭虚拟机,然后再操作之前备份一下所属的硬盘,免得手残

2)编辑所属磁盘,选择扩展磁盘,将大小调整为250GB。

3)开机进入zabbix系统,分区磁盘,转换磁盘类型

[root@zabbix-test ~]# fdisk /dev/sda

The device presents a logical sector size that is smaller than

the physical sector size. Aligning to a physical sector (or optimal

I/O) size boundary is recommended, or performance may be impacted.

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

Disk /dev/sda:268.4 GB, 268435456000 bytes

255 heads, 63 sectors/track, 32635 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk identifier: 0x0002c75c

   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

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 3

First cylinder (6528-32635, default 6528): 

Using default value 6528

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

Using default value 32635

Command (m for help): m

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

Partition number (1-4): 3

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

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

Command (m for help): p

Disk /dev/sda: 268.4 GB, 268435456000 bytes

255 heads, 63 sectors/track, 32635 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk identifier: 0x0002c75c

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

Syncing disks.

[root@zabbix-test ~]# sync

[root@zabbix-test ~]# sync

[root@zabbix-test ~]# init 6

查看挂载分区,分区已经变为250GB,将扩容的磁盘/dev/sda内未分配的空间分区,然后转化为8e LVM格式,然后重启重新识别磁盘

4)格式化分区,重新识别根分区

[root@zabbix-test ~]# mkfs.ext4 /dev/sda3

mke2fs 1.41.12 (17-May-2010)

Discarding device blocks: done                            

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=1 blocks, Stripe width=0 blocks

13107200 inodes, 52427959 blocks

2621397 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

1600 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks: 

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@zabbix-test ~]# pvcreate /dev/sda3

  Physical volume "/dev/sda3" successfully created

[root@zabbix-test ~]# pvdisplay 

  --- Physical volume ---

  PV Name               /dev/sda2

VG Name               VolGroup

  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               257toR-VCpi-ZkbK-6xuM-Vfmh-iywx-CLt1hp


  "/dev/sda3" is a new physical volume of "200.00 GiB"

  --- NEW Physical volume ---

  PV Name               /dev/sda3

  VG Name               

  PV Size               200.00 GiB

  Allocatable           NO

  PE Size               0   

  Total PE              0

  Free PE               0

  Allocated PE          0

  PV UUID               9xcLAh-dIDQ-Q7F5-eSuP-Kzf2-5VGx-i5H7C1


[root@zabbix-test ~]# vgdisplay 

  --- Volume group ---

  VG Name               VolGroup

  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               swdQhX-7DhD-qiWW-8oeV-ewSP-Djjy-ozdCpy


[root@zabbix-test ~]# vgextend VolGroup /dev/sda3

另外VolGroup在centos7里应该是centos ,使用过程中注意观察这个名字

  Volume group "VolGroup" successfully extended

[root@zabbix-test ~]# vgdisplay 

  --- Volume group ---

  VG Name               VolGroup

  System ID             

  Format                lvm2

  Metadata Areas        2

  Metadata Sequence No  4

  VG Access             read/write

  VG Status             resizable

  MAX LV                0

  Cur LV                2

  Open LV               2

  Max PV                0

  Cur PV                2

  Act PV                2

  VG Size               249.50 GiB

  PE Size               4.00 MiB

  Total PE              63872

  Alloc PE / Size       12674 / 49.51 GiB

  Free  PE / Size       51198 / 199.99 GiB

  VG UUID               swdQhX-7DhD-qiWW-8oeV-ewSP-Djjy-ozdCpy


[root@zabbix-test ~]# lvdisplay 

  --- Logical volume ---

  LV Path                /dev/VolGroup/lv_root

  LV Name                lv_root

  VG Name                VolGroup

  LV UUID                mduTSv-NAbg-wKVi-HHbB-JSrq-YzVu-pOZ6SD

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-06-01 01:43:46 +0800

  LV Status              available

  # open                 1

  LV Size                45.60 GiB

  Current LE             11674

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:0


  --- Logical volume ---

  LV Path                /dev/VolGroup/lv_swap

  LV Name                lv_swap

  VG Name                VolGroup

  LV UUID                Jrud8e-iuls-u8uZ-m8IX-c0lQ-pgAe-VK7pJE

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-06-01 01:43:49 +0800

  LV Status              available

  # open                 1

  LV Size                3.91 GiB

  Current LE             1000

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           253:1


[root@zabbix-test ~]# pvdisplay

  --- Physical volume ---

  PV Name               /dev/sda2

  VG Name               VolGroup

  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               257toR-VCpi-ZkbK-6xuM-Vfmh-iywx-CLt1hp


  --- Physical volume ---

 PV Name               /dev/sda3

  VG Name               VolGroup

  PV Size               200.00 GiB / not usable 4.72 MiB

  Allocatable           yes 

  PE Size               4.00 MiB

  Total PE              51198

 Free PE               51198

  Allocated PE          0

  PV UUID               9xcLAh-dIDQ-Q7F5-eSuP-Kzf2-5VGx-i5H7C1


[root@zabbix-test ~]# lvextend -l +51198 /dev/VolGroup/lv_root

另外VolGroup在centos7里应该是centos ,使用过程中注意观察这个名字

  Size of logical volume VolGroup/lv_root changed from 45.60 GiB (11674 extents) to 245.59 GiB (62872 extents).

  Logical volume lv_root successfully resized

#此处的+51198就是添加的分区sda3加入物理卷组之后所剩余的PE,全部加入到逻辑卷组/dev/VolGroup/lv_root

[root@zabbix-test ~]# df -hP

Filesystem                       Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root      45G   34G  8.6G  80% /

tmpfs                            2.9G     0  2.9G   0% /dev/shm

/dev/sda1                        477M   69M  383M  16% /boot

[root@zabbix-test ~]# resize2fs /dev/mapper/VolGroup-lv_root

这里resize2fs在centos7里应该换成xfs_growfs

另外VolGroup在centos7里应该是centos ,使用过程中注意观察这个名字

resize2fs 1.41.12 (17-May-2010)

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

old desc_blocks = 3, new_desc_blocks = 16

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

The filesystem on /dev/mapper/VolGroup-lv_root is now 64380928 blocks long.

[root@zabbix-test ~]# df -hP

Filesystem                       Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root     242G   34G  196G  15% /

tmpfs                            2.9G     0  2.9G   0% /dev/shm

/dev/sda1                        477M   69M  383M  16% /boot

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,636评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,890评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,680评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,766评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,665评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,045评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,515评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,182评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,334评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,274评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,319评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,002评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,599评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,675评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,917评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,309评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,885评论 2 341

推荐阅读更多精彩内容