centos7根目录扩容:

网上大部分教程是新建Linux时配置了分区,对于默认分区的系统并不适用,因为没有卷组的概念。

根目录在/dev/mapper/centos-root请参考另一篇博客(https://blog.csdn.net/yang1393214887/article/details/120346704

原理:删除sda3,再重建sda3(注意:删除后不要退出,紧接着重建,注意重建后的起始位置)

虚拟机扩容:

 

1、查看分区状态(可以看出根目录在/dev/sda3

[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.0G   13G  28% /
devtmpfs        896M     0  896M   0% /dev
tmpfs           911M     0  911M   0% /dev/shm
tmpfs           911M   11M  901M   2% /run
tmpfs           911M     0  911M   0% /sys/fs/cgroup
/dev/sda1       297M  148M  150M  50% /boot
tmpfs           183M  4.0K  183M   1% /run/user/42
tmpfs           183M   28K  183M   1% /run/user/0

2、删除sda3然后重建

[root@localhost ~]# 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): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c1f72

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752    41943039    18566144   83  Linux

Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c1f72

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (4810752-209715199, default 4810752): 4810752
Last sector, +sectors or +size{K,M,G} (4810752-209715199, default 209715199): 
Using default value 209715199
Partition 3 of type Linux and of size 97.7 GiB is set

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c1f72

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris
/dev/sda3         4810752   209715199   102452224   83  Linux

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.

3、刷新:xfs_growfs /dev/sda3

(执行cat /etc/fstab查看系统文件格式,centos7默认xfs格式,红帽不是

如果是格式ext格式的,执行resize2fs /dev/sda3)

(或者reboot重启后刷新)

[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  100G  0 disk 
├─sda1   8:1    0  300M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 17.7G  0 part /
sr0     11:0    1 1024M  0 rom  
[root@localhost ~]# xfs_growfs /dev/sda3
meta-data=/dev/sda3              isize=512    agcount=4, agsize=1160384 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4641536, 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
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.1G   13G  29% /
devtmpfs        896M     0  896M   0% /dev
tmpfs           911M     0  911M   0% /dev/shm
tmpfs           911M   11M  901M   2% /run
tmpfs           911M     0  911M   0% /sys/fs/cgroup
/dev/sda1       297M  148M  150M  50% /boot
tmpfs           183M  4.0K  183M   1% /run/user/42
tmpfs           183M   36K  183M   1% /run/user/0
[root@localhost ~]# reboot

Connection closed by foreign host.

Disconnected from remote host(192.168.3.109) at 11:25:02.

Type `help' to learn how to use Xshell prompt.
[c:\~]$ 

Connecting to 192.168.3.109:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Thu Sep 16 20:20:21 2021 from 192.168.3.38
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.1G   13G  29% /
devtmpfs        896M     0  896M   0% /dev
tmpfs           911M     0  911M   0% /dev/shm
tmpfs           911M   11M  901M   2% /run
tmpfs           911M     0  911M   0% /sys/fs/cgroup
/dev/sda1       297M  148M  150M  50% /boot
tmpfs           183M  8.0K  183M   1% /run/user/42
tmpfs           183M     0  183M   0% /run/user/0
[root@localhost ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  100G  0 disk 
├─sda1   8:1    0  300M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 97.7G  0 part /
sr0     11:0    1 1024M  0 rom  
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        18G  5.1G   13G  29% /
devtmpfs        896M     0  896M   0% /dev
tmpfs           911M     0  911M   0% /dev/shm
tmpfs           911M   11M  901M   2% /run
tmpfs           911M     0  911M   0% /sys/fs/cgroup
/dev/sda1       297M  148M  150M  50% /boot
tmpfs           183M  8.0K  183M   1% /run/user/42
tmpfs           183M     0  183M   0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/sda3
meta-data=/dev/sda3              isize=512    agcount=4, agsize=1160384 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4641536, 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 4641536 to 25613056
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        98G  5.1G   93G   6% /
devtmpfs        896M     0  896M   0% /dev
tmpfs           911M     0  911M   0% /dev/shm
tmpfs           911M   11M  901M   2% /run
tmpfs           911M     0  911M   0% /sys/fs/cgroup
/dev/sda1       297M  148M  150M  50% /boot
tmpfs           183M  8.0K  183M   1% /run/user/42
tmpfs           183M     0  183M   0% /run/user/0

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐