resize2fs


resize2fs 功能說明:調整ext2/ext3/ext4文件系統大小
resize2fs命令用於擴容或收縮未掛載的ext2/ext3/ext4文件系統。
在Linux2.6或更高版本的內核中,該命令還支持在線擴容已經掛載的文件系統,該命令常用來針對LVM擴容后的分區使用。

參數選項:
-p    打印完成任務的進度條
-f    強制執行操作


范例:動態修改分區大小的例子
假設是要對/dev/sdb上的分區進行操作,將/mnt/data1擴容。

[root@cs6 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cs6-lv_root
                       26G  834M   24G   4% /
tmpfs                 931M     0  931M   0% /dev/shm
/dev/sda1             477M   28M  424M   7% /boot
/dev/sdb1             194M  1.8M  182M   1% /mnt/data1
/dev/sdb2             194M  1.8M  182M   1% /mnt/data2
[root@cs6 ~]# touch /mnt/data1/{1..5}.html
[root@cs6 ~]# touch /mnt/data2/{1..5}.html
 

提示:/dev/sdb是一塊1GB的磁盤,現在分了兩個主分區sdb1、sdb2,分別是200MB,剩余800MB未分區。現在需要把sdb2分區和sdb1分區合並,以實現對sdb1的擴容,
注意,此種情況不要在生產場景操作,僅作為演示用,生產場景一般是事先規划好不會出現擴容需求,非I/O密集應用可以采用LVM實現規范動態擴容。

以下是擴容實戰步驟。

1)記錄分區的柱面起始信息:

[root@cs6 ~]# fdisk -l /dev/sdb
 
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1bc7d413
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          26      208813+  83  Linux
/dev/sdb2              27          52      208845   83  Linux


2)卸載分區:

[root@cs6 ~]# umount /mnt/data1
[root@cs6 ~]# umount /mnt/data2
 
[root@cs6 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cs6-lv_root
                       26G  834M   24G   4% /
tmpfs                 931M     0  931M   0% /dev/shm
/dev/sda1             477M   28M  424M   7% /boot
 

3)重新分區:
 
[root@cs6 ~]# fdisk /dev/sdb
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
 
Command (m for help): d
Partition number (1-4): 1
 
Command (m for help): d
Selected partition 2
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): 52
 
Command (m for help): p
 
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1bc7d413
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          52      417658+  83  Linux
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
[root@cs6 ~]# partprobe /dev/sdb
[root@cs6 ~]# mount /dev/sdb1 /mnt/data1
[root@cs6 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cs6-lv_root
                       26G  834M   24G   4% /
tmpfs                 931M     0  931M   0% /dev/shm
/dev/sda1             477M   28M  424M   7% /boot
/dev/sdb1             194M  1.8M  182M   1% /mnt/data1
 
 
[root@cs6 ~]# ls /mnt/data1
1.html  2.html  3.html  4.html  5.html  lost+found
[root@cs6 ~]# resize2fs /dev/sdb1    #<==在線調整磁盤大小,
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/sdb1 is mounted on /mnt/data1; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/sdb1 to 417656 (1k) blocks.
The filesystem on /dev/sdb1 is now 417656 blocks long.
 
[root@cs6 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cs6-lv_root
                       26G  834M   24G   4% /
tmpfs                 931M     0  931M   0% /dev/shm
/dev/sda1             477M   28M  424M   7% /boot
/dev/sdb1             392M  2.3M  369M   1% /mnt/data1
[root@cs6 ~]# ls /mnt/data1
1.html  2.html  3.html  4.html  5.html  lost+found



但是數據還是只有sdb1里的了,sdb2的數據丟失了。
此種方法不適合生產場景擴容,比較規范方法是通過LVM邏輯卷管理進行擴容,擴容后也需要resize2fs進行最終實現擴容。


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM