美文网首页
虚拟机里的linux主分区扩容

虚拟机里的linux主分区扩容

作者: 嘿嘿逗 | 来源:发表于2018-12-11 15:59 被阅读0次

[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

相关文章

  • 虚拟机里的linux主分区扩容

    [root@zabbix-test ~]# vgdisplay --- Volume group --- VG...

  • Linux 主分区扩容

    参考资料:https://www.2cto.com/net/201608/541676.html #查看挂载点: ...

  • linux磁盘主分区扩容

    建议看完全文 以前我自己用过的方法:fdisk后边跟着的是每次提示要输入的命令 今天看到这个,只想说一句:wc,这...

  • 磁盘扩容

    Centos7 普通扩容 Centos7虚拟机,主分区在/dev/sda3上的情况, vgdisplay为空 参考...

  • linux分区扩容

    图片中可以看到挂载点“/”的利用率移到100%,空间不够,所以要对其进行分区。 先进入虚拟机设置里增大磁盘空间 注...

  • 《Linux实践技能》学习笔记 day11

    Linux 虚拟机 virtualbox 磁盘扩容 首先在虚拟机中模拟磁盘挂载,先关机,扩容磁盘大小image.p...

  • Linux虚拟机根分区磁盘扩容

    前提知识 查看磁盘文件系统、空间、挂载点:df -Th, mount查看磁盘扇区:fdisk -l查看磁盘是固态磁...

  • vmware主分区扩容

    参考:https://blog.csdn.net/birencs/article/details/12438921...

  • vmware虚拟机扩容磁盘空间

    主要步骤: vmware宿主机编辑虚拟机配置扩容服务器磁盘并启动虚拟机 fdisk新建分区 pvcreate新建物...

  • Linux根分区扩容

    现状: 需求/目录增加500M 操作步骤1.VirtualBox新加一个磁盘 新建分区 3.把新分区改成LVM 卷...

网友评论

      本文标题:虚拟机里的linux主分区扩容

      本文链接:https://www.haomeiwen.com/subject/staofqtx.html