CentOS7.4根目录root扩容操作记录

1、首先确认当前各文件系统大小,可以看到根目录对应文件系统大小是13GB,/boot对应文件系统大小是1GB。

[root@mysql1 software]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   13G  7.9G  5.2G  61% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.8M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  125M  890M  13% /boot
tmpfs                    799M   44K  799M   1% /run/user/0
[root@mysql1 software]# 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               <15.00 GiB
  PE Size               4.00 MiB
  Total PE              3839
  Alloc PE / Size       3839 / <15.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               r6eFWb-3pFa-2tA8-lZq0-4ISc-aUh8-YBAesE
   
[root@mysql1 software]# vgdisplay -v centos
  --- 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               <15.00 GiB
  PE Size               4.00 MiB
  Total PE              3839
  Alloc PE / Size       3839 / <15.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               r6eFWb-3pFa-2tA8-lZq0-4ISc-aUh8-YBAesE
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                cgtKDN-voAp-nP4M-gzey-RPez-rMiU-QOriW1
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-11-16 17:52:49 -0500
  LV Status              available
  # open                 1
  LV Size                13.00 GiB
  Current LE             3328
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                nuSDpX-cNCg-rUEi-S5K3-Ar08-tIPx-ZXpiAg
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-11-16 17:52:49 -0500
  LV Status              available
  # open                 2
  LV Size                <2.00 GiB
  Current LE             511
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               PBWjCq-Bqed-iUce-hAR0-nEn1-gJfq-dLLD1Q
  PV Status             allocatable
  Total PE / Free PE    3839 / 0

2、确认当前磁盘容量信息,/dev/sda大小为21.5GB,划分了2个分区,已划分的总容量不到17GB。还有将近4GB可用空间。  
[root@mysql1 software]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0009c454

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

Disk /dev/mapper/centos-root: 14.0 GB, 13958643712 bytes, 27262976 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: 2143 MB, 2143289344 bytes, 4186112 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

3、在未用空间创建新的分区sda3。

[root@mysql1 software]# fdisk /dev/sda
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.


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
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (33554432-41943039, default 33554432):
Using default value 33554432
Last sector, +sectors or +size{K,M,G} (33554432-41943039, default 41943039):
Using default value 41943039
Partition 3 of type Linux and of size 4 GiB is set

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.

4、根据上面步骤的提示,需要重启或者运行命令partprobe重新同步磁盘分区信息,分区重新识别后可以看到新分区sda3。  
[root@mysql1 software]#
[root@mysql1 software]# partprobe
[root@mysql1 software]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0009c454

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM
/dev/sda3        33554432    41943039     4194304   83  Linux

Disk /dev/mapper/centos-root: 14.0 GB, 13958643712 bytes, 27262976 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: 2143 MB, 2143289344 bytes, 4186112 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

5、使用lvm命令pvcreate格式化sda3分区。

[root@mysql1 software]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@mysql1 software]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <15.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3839
  Free PE               0
  Allocated PE          3839
  PV UUID               PBWjCq-Bqed-iUce-hAR0-nEn1-gJfq-dLLD1Q
   
  "/dev/sda3" is a new physical volume of "4.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               4.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               YUu7KQ-fjBr-qkSq-reiP-sjIV-wxUg-tZ4xAP

6、将分区sda3加入root所在的vg(centos)里  。

[root@mysql1 software]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended
[root@mysql1 software]# vgdisplay -v centos
  --- 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               18.99 GiB
  PE Size               4.00 MiB
  Total PE              4862
  Alloc PE / Size       3839 / <15.00 GiB
  Free  PE / Size       1023 / <4.00 GiB
  VG UUID               r6eFWb-3pFa-2tA8-lZq0-4ISc-aUh8-YBAesE
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                cgtKDN-voAp-nP4M-gzey-RPez-rMiU-QOriW1
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-11-16 17:52:49 -0500
  LV Status              available
  # open                 1
  LV Size                13.00 GiB
  Current LE             3328
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                nuSDpX-cNCg-rUEi-S5K3-Ar08-tIPx-ZXpiAg
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-11-16 17:52:49 -0500
  LV Status              available
  # open                 2
  LV Size                <2.00 GiB
  Current LE             511
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               PBWjCq-Bqed-iUce-hAR0-nEn1-gJfq-dLLD1Q
  PV Status             allocatable
  Total PE / Free PE    3839 / 0
   
  PV Name               /dev/sda3     
  PV UUID               YUu7KQ-fjBr-qkSq-reiP-sjIV-wxUg-tZ4xAP
  PV Status             allocatable
  Total PE / Free PE    1023 / 1023
   

7、扩展root根分区所在的逻辑卷大小,vgdisplay可以看到root所在lv大小已经发生变化。

[root@mysql1 software]# lvextend -L +4G /dev/centos/root
  Insufficient free space: 1024 extents needed, but only 1023 available
[root@mysql1 software]# lvextend -L +4092M /dev/centos/root
  Size of logical volume centos/root changed from 13.00 GiB (3328 extents) to <17.00 GiB (4351 extents).
  Logical volume centos/root successfully resized.
[root@mysql1 software]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               18.99 GiB
  PE Size               4.00 MiB
  Total PE              4862
  Alloc PE / Size       4862 / 18.99 GiB
  Free  PE / Size       0 / 0   
  VG UUID               r6eFWb-3pFa-2tA8-lZq0-4ISc-aUh8-YBAesE
   
[root@mysql1 software]# vgdisplay -v
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               18.99 GiB
  PE Size               4.00 MiB
  Total PE              4862
  Alloc PE / Size       4862 / 18.99 GiB
  Free  PE / Size       0 / 0   
  VG UUID               r6eFWb-3pFa-2tA8-lZq0-4ISc-aUh8-YBAesE
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                cgtKDN-voAp-nP4M-gzey-RPez-rMiU-QOriW1
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-11-16 17:52:49 -0500
  LV Status              available
  # open                 1
  LV Size                <17.00 GiB
  Current LE             4351
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                nuSDpX-cNCg-rUEi-S5K3-Ar08-tIPx-ZXpiAg
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-11-16 17:52:49 -0500
  LV Status              available
  # open                 2
  LV Size                <2.00 GiB
  Current LE             511
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Physical volumes ---
  PV Name               /dev/sda2     
  PV UUID               PBWjCq-Bqed-iUce-hAR0-nEn1-gJfq-dLLD1Q
  PV Status             allocatable
  Total PE / Free PE    3839 / 0
   
  PV Name               /dev/sda3     
  PV UUID               YUu7KQ-fjBr-qkSq-reiP-sjIV-wxUg-tZ4xAP
  PV Status             allocatable
  Total PE / Free PE    1023 / 0

8、根目录大小依然没变化,确认root文件系统的类型是xfs后,使用xfs_growfs命令扩展根目录大小。  
[root@mysql1 software]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   13G  7.9G  5.2G  61% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.9M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  125M  890M  13% /boot
tmpfs                    799M   44K  799M   1% /run/user/0
[root@mysql1 software]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=4076808k,nr_inodes=1019202,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=33,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=9919)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=817572k,mode=700)
gvfsd-fuse on /run/user/0/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=0,group_id=0)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)

[root@mysql1 software]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=851968 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3407872, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3407872 to 4455424


[root@mysql1 software]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   17G  7.9G  9.2G  47% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.9M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  125M  890M  13% /boot
tmpfs                    799M   44K  799M   1% /run/user/0
[root@mysql1 software]#

最后使用df命令,确认根目录大小已经从原来的13GB扩展为17GB。

你可能感兴趣的:(Linux)