虚机磁盘分区之后就xfs格式化了,给根目录扩容10G
[root@y_zilong ~]# lsblk #查看磁盘空间
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 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 /
[root@y_zilong ~]# df -Th |grep sda3 #查看文件系统的信息
/dev/sda3 xfs 18G 3.7G 15G 21% /
[root@y_zilong ~]# #因为内容不重要,直接扩容,不在备份
下面开始扩容步骤
一、卸载分区
[root@y_zilong ~]# umount /dev/sda3
umount: /: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@y_zilong ~]# 根分区卸载不掉那就不卸载了
二、使用fdisk修改分区容量
[root@y_zilong ~]# 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: 32.2 GB, 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
Disk label type: dos
Disk identifier: 0x000b70b3
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 8e Linux LVM
/dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
/dev/sda3 4810752 61433855 28311552 83 Linux
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted
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-62914559, default 4810752):
Using default value 4810752
Last sector, +sectors or +size{K,M,G} (4810752-62914559, default 62914559):
Using default value 62914559
Partition 3 of type Linux and of size 27.7 GiB is set
Command (m for help): p
Disk /dev/sda: 32.2 GB, 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
Disk label type: dos
Disk identifier: 0x000b70b3
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 8e Linux LVM
/dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
/dev/sda3 4810752 62914559 29051904 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.
[root@y_zilong ~]# partprobe #不管用,必须reboot重启
Error: Partition(s) 3 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@y_zilong ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 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 4.5G 0 rom
#重启之后
[root@y_zilong ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 300M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 27.7G 0 part / #磁盘分区空间变为了27.7,增加了10G
sr0 11:0 1 4.5G 0 rom
[root@y_zilong ~]#
三、扩容文件系统
分区已经扩容到27.7G了,文件系统还是原来的大小,现在扩容文件系统
[root@y_zilong ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 18G 3.6G 15G 21% /
devtmpfs devtmpfs 1.7G 0 1.7G 0% /dev
tmpfs tmpfs 1.8G 84K 1.8G 1% /dev/shm
tmpfs tmpfs 1.8G 9.0M 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/sda1 xfs 297M 152M 146M 51% /boot
tmpfs tmpfs 351M 16K 351M 1% /run/user/42
tmpfs tmpfs 351M 0 351M 0% /run/user/0
[root@y_zilong ~]# xfs_growfs / #扩展XFS文件系统!!!
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 7262976
#!!!要是提示只读
[root@y_zilong ~]# mount -o remount rw / #改为读写
然后在 [root@y_zilong ~]# xfs_growfs /
!!!
[root@y_zilong ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 28G 3.6G 25G 13% / #文件系统变为了28G
devtmpfs devtmpfs 1.7G 0 1.7G 0% /dev
tmpfs tmpfs 1.8G 84K 1.8G 1% /dev/shm
tmpfs tmpfs 1.8G 9.0M 1.8G 1% /run
tmpfs tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/sda1 xfs 297M 152M 146M 51% /boot
tmpfs tmpfs 351M 16K 351M 1% /run/user/42
tmpfs tmpfs 351M 0 351M 0% /run/user/0
[root@y_zilong ~]#