空白的一坪

从DBA到SRE

导航

操作系统root目录磁盘分区扩容实践(无物理,逻辑卷)

环境说明:

虚拟机:vmware 16 play

操作系统:centos 8


1.虚拟机设置>目标磁盘>扩容磁盘容量(按需扩容磁盘大小)
2.查看磁盘空间大小

fdisk -l

[root@tertiary ~]# fdisk -l|more 
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors                              #当前磁盘大小30G
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x68538fa9

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   616447   614400  300M 83 Linux
/dev/sda2        616448  4810751  4194304    2G 82 Linux swap / Solaris
/dev/sda3       4810752 41943039 37132288 17.7G 83 Linux                                 #目标磁盘分区大小
3.查看文件系统大小

df -h

[root@tertiary ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  9.6M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda3        18G   17G  1.2G  94% /                                           #目标文件大小
/dev/sda1       295M  173M  122M  59% /boot
tmpfs           371M  1.2M  370M   1% /run/user/42
tmpfs           371M     0  371M   0% /run/user/0
4.重新分配原有根目录目标磁盘分区(生产环境备份数据后执行操作)

fdisk /dev/sda

[root@tertiary ~]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p                                                #显示分区信息
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0x68538fa9

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   616447   614400  300M 83 Linux
/dev/sda2        616448  4810751  4194304    2G 82 Linux swap / Solaris
/dev/sda3       4810752 41943039 37132288 17.7G 83 Linux

Command (m for help): d  											#删除分区
Partition number (1-3, default 3): 3                                #删除3号分区

Partition 3 has been deleted.

Command (m for help): n                                             #创建分区
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p):                                                 #创建主分区(默认)

Using default response p.
Partition number (3,4, default 3):                                  #创建3号分区(必须与删除分区号相同)
First sector (4810752-62914559, default 4810752):                   #分区起始扇区
Last sector, +sectors or +size{K,M,G,T,P} (4810752-62914559, default 62914559):    #分区结束扇区

Created a new partition 3 of type 'Linux' and of size 27.7 GiB.
Partition #3 contains a xfs signature.                                      

Do you want to remove the signature? [Y]es/[N]o: y                     #移除标签

The signature will be removed by a write command.

Command (m for help): w                                              #保存修改
The partition table has been altered.
Syncing disks.
5.检查磁盘分区大小变化

fdisk -l|more lsblk

[root@tertiary ~]# fdisk -l|more 
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0x68538fa9

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   616447   614400  300M 83 Linux
/dev/sda2        616448  4810751  4194304    2G 82 Linux swap / Solaris
/dev/sda3       4810752 62914559 58103808 27.7G 83 Linux                               #目标磁盘分区已扩容10G
6.查看文件系统类型

df -hT

[root@tertiary ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  1.8G     0  1.8G   0% /dev
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs          tmpfs     1.9G  9.6M  1.9G   1% /run
tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda3      xfs        18G   17G  1.2G  94% /                                            #目标文件类型xfs
/dev/sda1      xfs       295M  173M  122M  59% /boot
tmpfs          tmpfs     371M  1.2M  370M   1% /run/user/42
tmpfs          tmpfs     371M     0  371M   0% /run/user/0
7.通过resize2fs或者xfs_growfs命令对文件系统进行扩容

上文检查文件类型为xfs,则用xfs_growfs命令执行操作

xfs_growfs /dev/sda3

[root@tertiary ~]# xfs_growfs /dev/sda3
meta-data=/dev/sda3              isize=512    agcount=4, agsize=1160384 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=4641536, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           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 4641536 to 7262976
8.确认文件系统大小

df -h

[root@tertiary ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  9.6M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda3        28G   17G   12G  60% /                                           #目标文件系统已扩容10G
/dev/sda1       295M  173M  122M  59% /boot
tmpfs           371M  1.2M  370M   1% /run/user/42
tmpfs           371M     0  371M   0% /run/user/0

posted on 2021-04-19 14:28  行列式  阅读(331)  评论(0编辑  收藏  举报

后会无期

2011-2-14... ...后来喜欢很浅,喝过酒就忘记,吵完架就放弃