Linux操作系统之centos7根目录扩容(根目录在sda3 vgdisplay为空)

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

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

0、虚拟机扩容:
在这里插入图片描述
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、刷新:ext格式执行resize2fs /dev/sda3

(执行cat /etc/fstab查看系统文件格式,xfs格式执行xfs_growfs /dev/sda3)

[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
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值