當硬盤分區不使用LVM的時候,將不能使用lvresize等指令調整
在調整分區之前,先來了解一下當前的磁盤分區信息
1:使用Fdisk指令查看后發現sda1的分區有195309568個Sectors(扇區)
每個扇區有512字節,所以總共有99998498816字節
================================================================
root@X9DRLiF:~# fdisk -l /dev/sda
Disk /dev/sda: 223.6 GiB, 240057409536 bytes, 468862128 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: 0x7eefe6fa
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 195311615 195309568 93.1G 83 Linux
/dev/sda2 * 453236736 468860927 15624192 7.5G 83 Linux
================================================================
2:使用resize2fs發現sda1的文件系統有24413696個blocks(塊),
所以總共有99998498816字節
================================================================
root@X9DRLiF:~# resize2fs /dev/sda1
resize2fs 1.42.13 (17-May-2015)
The filesystem is already 24413696 (4k) blocks long. Nothing to do!
================================================================
用resize2fs調整如果超過了分區的界限就會有錯誤,可以用這個方法還原回去
resize2fs -f /dev/sda1 24413696
這里的24413696可以通過Sectors*512/4096所得
3:開始減小ext4分區,調整到200G-1M=204799M*(256)=52428544blocks
root@X9DRLiF:~# resize2fs -f /dev/sda1 52428544
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/sda1 is mounted on /mnt/data; on-line resizing required
resize2fs: On-line shrinking not supported
這里應該先umount,如果umount不了就用fuser -k /mnt/data
===========================================================
root@X9DRLiF:~# resize2fs -f /dev/sda1 52428544
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/sda1 to 52428544 (4k) blocks.
The filesystem on /dev/sda1 is now 52428544 (4k) blocks long.
4:然后用fdisk調整(就是d刪除,n新建分區)
===================下面是調整后的樣子==================
root@X9DRLiF:~# fdisk -l /dev/sda
Disk /dev/sda: 223.6 GiB, 240057409536 bytes, 468862128 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: 0x7eefe6fa
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 419430399 419428352 200G 83 Linux
/dev/sda2 * 453236736 468860927 15624192 7.5G 83 Linux
====================================================================
這里的/dev/sda1的Sectors為419428352,除以8,剛好是block的值