Centos根分区扩容

342次阅读
没有评论

共计 4198 个字符,预计需要花费 11 分钟才能阅读完成。

Centos根分区扩容

最近服务器系统根分区快满了,得加块硬盘顶一顶,本打算加块硬盘后,将数据拷贝到数据盘,和系统盘数据分开,想想还得停服拷贝啥的,不如直接扩容根分区得了。。。

查看当前系统磁盘使用情况

[root@xadocker-ops ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   37G   35G  2.3G  95% /
devtmpfs                 980M     0  980M   0% /dev
tmpfs                    992M     0  992M   0% /dev/shm
tmpfs                    992M  9.6M  982M   1% /run
tmpfs                    992M     0  992M   0% /sys/fs/cgroup
/dev/sda1               1014M  130M  885M  13% /boot
tmpfs                    199M     0  199M   0% /run/user/0

加上硬盘后,查看磁盘设备

[root@xadocker-ops ~]# lsblk -l
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   40G  0 disk
sda1          8:1    0    1G  0 part /boot
sda2          8:2    0   39G  0 part
centos-root 253:0    0   37G  0 lvm  /
centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb           8:16   0   40G  0 disk
sr0          11:0    1 1024M  0 rom

将磁盘分区type设置为Linux LVM

[root@xadocker-ops ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x0bedadc8.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1

First sector (2048-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Using default value 83886079
Partition 1 of type Linux and of size 40 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[root@xadocker-ops ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009c128

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    83886079    40893440   8e  Linux LVM

Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0bedadc8

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    83886079    41942016   8e  Linux LVM

Disk /dev/mapper/centos-root: 39.7 GB, 39720058880 bytes, 77578240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

创建物理卷PV

# 创建物理卷PV
[root@xadocker-ops ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

# 查看当前卷组
[root@xadocker-ops ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  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               <39.00 GiB
  PE Size               4.00 MiB
  Total PE              9983
  Alloc PE / Size       9982 / 38.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               edcQDg-ZRaK-SeHF-ZGD9-nndn-GZf6-E2n00W

扩容卷组

[root@xadocker-ops ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
[root@xadocker-ops ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  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               78.99 GiB
  PE Size               4.00 MiB
  Total PE              20222
  Alloc PE / Size       9982 / 38.99 GiB
  Free  PE / Size       10240 / 40.00 GiB
  VG UUID               edcQDg-ZRaK-SeHF-ZGD9-nndn-GZf6-E2n00W

逻辑卷扩容根分区目录

[root@xadocker-ops ~]# lvextend -L +40G /dev/mapper/centos-root
  Size of logical volume centos/root changed from 36.99 GiB (9470 extents) to 76.99 GiB (19710 extents).
  Logical volume centos/root successfully resized.

根分区文件系统扩容那个

# 博主这里是xfs文件系统,所以使用xfs_growfs,如果你的ext文件系统,则使用此命令resize2fs /dev/mapper/centos-root
[root@xadocker-ops ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=2424320 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9697280, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4735, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9697280 to 20183040

# 查看最终效果
[root@xadocker-ops ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        77G   35G   62G  46% /
devtmpfs                devtmpfs  2.0G     0  2.0G   0% /dev
tmpfs                   tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs                   tmpfs     2.0G   12M  2.0G   1% /run
tmpfs                   tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  130M  885M  13% /boot
tmpfs                   tmpfs     394M     0  394M   0% /run/user/0

正文完
 
xadocker
版权声明:本站原创文章,由 xadocker 2020-04-26发表,共计4198字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)