網上大多數博客講的xfs分區擴容都是基於LVM邏輯管理的,但是我這里有一塊磁盤/dev/sdb
,大小只有50G,格式化的xfs文件系統,但是現在想擴容到100G大小,所以可以這樣做:
首先看一下當前/dev/sdb
磁盤
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.2G 0 1.2G 0% /dev
tmpfs tmpfs 1.2G 0 1.2G 0% /dev/shm
tmpfs tmpfs 1.2G 9.3M 1.2G 1% /run
tmpfs tmpfs 1.2G 0 1.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 22G 1.5G 21G 7% /
/dev/sda1 xfs 1014M 186M 829M 19% /boot
tmpfs tmpfs 234M 0 234M 0% /run/user/0
/dev/sdb1 xfs 50G 33M 50G 1% /data
[root@localhost ~]# cat /data/haha/a.txt
abcdefg
hijklmn
opqrstu
vwxyz
其中/dev/sdb1
分區有大小50G的空間,已經全部被格式化為xfs文件系統並掛載到/data目錄下了。並且該目錄下面有存儲的文件a.txt。現在要擴容到100G的空間。
1、首先是vmware磁盤擴容
把虛擬機關機,然后點擊擴容
整好之后開機后進行一波操作
2、查看當前系統的磁盤
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 25G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 24G 0 part
├─centos-root 253:0 0 21.5G 0 lvm /
└─centos-swap 253:1 0 2.5G 0 lvm [SWAP]
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 50G 0 part
sr0 11:0 1 4.2G 0 rom
發現磁盤並沒有擴大,繼續往下
3、卸載之前的數據盤
注意:一定要提前備份好數據
umount /data
4、fdisk命令擴容
[root@localhost ~]# fdisk /dev/sdb
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/sdb: 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: 0xf9cd0df5
Device Boot Start End Blocks Id System
/dev/sdb1 2048 104857599 52427776 83 Linux
Command (m for help): d #刪除分區,但是接下來千萬不要保存
Selected partition 1
Partition 1 is deleted
Command (m for help): n #開始創建新分區/dev/sdb1
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): #一路回車即可
Using default response p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set #現在已經是100G空間了
Command (m for help): w #保存分區並退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
5、修復分區
[root@localhost ~]# xfs_repair /dev/sdb1
Phase 1 - find and verify superblock...
Phase 2 - using internal log
- zero log...
- scan filesystem freespace and inode maps...
- found root inode chunk
Phase 3 - for each AG...
- scan and clear agi unlinked lists...
- process known inodes and perform inode discovery...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
- process newly discovered inodes...
Phase 4 - check for duplicate blocks...
- setting up duplicate extent list...
- check for inodes claiming duplicate blocks...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
Phase 5 - rebuild AG headers and trees...
- reset superblock...
Phase 6 - check inode connectivity...
- resetting contents of realtime bitmap and summary inodes
- traversing filesystem ...
- traversal finished ...
- moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done
6、重新掛載磁盤
mount /dev/sdb1 /data
7、擴容磁盤
[root@localhost ~]# xfs_growfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=3276736 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13106944, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6399, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13106944 to 26214144
看到最后一行data blocks changed from 13106944 to 26214144
就表示擴容了
7、再次查看分區大小
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sda 8:0 0 25G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 24G 0 part
├─centos-root 253:0 0 21.5G 0 lvm /
└─centos-swap 253:1 0 2.5G 0 lvm [SWAP]
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 100G 0 part /data
sr0 11:0 1 4.2G 0 rom
成功了
建議:雖然測試過程中原有的磁盤的數據沒有被毀壞,但是仍然強烈建議提前備份好原有數據