resize2fs - ext2 file system resizer
resize2fs 是 ext2 檔案系統大小調整工具
可以擴大 可以縮小原ext2分區(當然 ext3隻是多了 Journal的ext2 也可以)
需要注意的是 增大的話
起始柱面不能變
步驟就是:
先fdisk 調整分區
所謂調整 也就是删了相關的分區 再重建分區
最後在分區上再用 resize2fs 調整檔案系統大小
是以一個概念 或者說對照就是
檔案系統(file system)是在分區(Partition)基礎上的
# rpm -qf /sbin/resize2fs
e2fsprogs-1.32-15.1
# rpm -qil e2fsprogs
Name : e2fsprogs Relocations: (not relocatable)
Version : 1.32 Vendor: Red Hat, Inc.
Release : 15.1 Build Date: Mon 04 Oct 2004 10:23:16 PM CST
Install Date: Mon 17 Jan 2005 03:36:34 PM CST Build Host: tweety.build.redhat.com
Group : System Environment/Base Source RPM: e2fsprogs-1.32-15.1.src.rpm
Size : 1069923 License: GPL
Signature : DSA/SHA1, Thu 18 Nov 2004 05:35:43 AM CST, Key ID 219180cddb42a60e
Packager : Red Hat, Inc.
URL : http://e2fsprogs.sourceforge.net/
Summary : Utilities for managing the second extended (ext2) filesystem.
Description :
The e2fsprogs package contains a number of utilities for creating,
checking, modifying, and correcting any inconsistencies in second
extended (ext2) filesystems. E2fsprogs contains e2fsck (used to
repair filesystem inconsistencies after an unclean shutdown), mke2fs
(used to initialize a partition to contain an empty ext2 filesystem),
debugfs (used to examine the internal structure of a filesystem, to
manually repair a corrupted filesystem, or to create test cases for
e2fsck), tune2fs (used to modify filesystem parameters), and most of
the other core ext2fs filesystem utilities.
You should install the e2fsprogs package if you need to manage the
performance of an ext2 filesystem.
/lib/evms/libe2fsim.1.2.1.so
/lib/libcom_err.so.2
/lib/libcom_err.so.2.0
/lib/libe2p.so.2
/lib/libe2p.so.2.3
/lib/libext2fs.so.2
/lib/libext2fs.so.2.4
/lib/libss.so.2
/lib/libss.so.2.0
/lib/libuuid.so.1
/lib/libuuid.so.1.2
/sbin/badblocks
/sbin/debugfs
/sbin/dumpe2fs
/sbin/e2fsck
/sbin/e2image
/sbin/e2label
/sbin/findfs
/sbin/fsck
/sbin/fsck.ext2
/sbin/fsck.ext3
/sbin/mke2fs
/sbin/mkfs.ext2
/sbin/mkfs.ext3
/sbin/resize2fs
/sbin/tune2fs
/usr/bin/chattr
/usr/bin/lsattr
/usr/bin/uuidgen
/usr/sbin/mklost+found
/usr/share/doc/e2fsprogs-1.32
/usr/share/doc/e2fsprogs-1.32/README
/usr/share/doc/e2fsprogs-1.32/RELEASE-NOTES
/usr/share/man/man1/chattr.1.gz
/usr/share/man/man1/lsattr.1.gz
/usr/share/man/man1/uuidgen.1.gz
/usr/share/man/man3/libuuid.3.gz
/usr/share/man/man3/uuid_clear.3.gz
/usr/share/man/man3/uuid_compare.3.gz
/usr/share/man/man3/uuid_copy.3.gz
/usr/share/man/man3/uuid_generate.3.gz
/usr/share/man/man3/uuid_generate_random.3.gz
/usr/share/man/man3/uuid_generate_time.3.gz
/usr/share/man/man3/uuid_is_null.3.gz
/usr/share/man/man3/uuid_parse.3.gz
/usr/share/man/man3/uuid_time.3.gz
/usr/share/man/man3/uuid_unparse.3.gz
/usr/share/man/man8/badblocks.8.gz
/usr/share/man/man8/debugfs.8.gz
/usr/share/man/man8/dumpe2fs.8.gz
/usr/share/man/man8/e2fsck.8.gz
/usr/share/man/man8/e2image.8.gz
/usr/share/man/man8/e2label.8.gz
/usr/share/man/man8/findfs.8.gz
/usr/share/man/man8/fsck.8.gz
/usr/share/man/man8/fsck.ext2.8.gz
/usr/share/man/man8/fsck.ext3.8.gz
/usr/share/man/man8/mke2fs.8.gz
/usr/share/man/man8/mkfs.ext2.8.gz
/usr/share/man/man8/mkfs.ext3.8.gz
/usr/share/man/man8/mklost+found.8.gz
/usr/share/man/man8/resize2fs.8.gz
/usr/share/man/man8/tune2fs.8.gz
# fdisk /dev/sdb
The number of cylinders for this disk is set to 8924.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p {顯示分區資訊}
Disk /dev/sdb: 73.4 GB, 73407868928 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 522 4192933+ 82 Linux swap
/dev/sdb2 523 783 2096482+ 83 Linux
/dev/sdb3 784 1436 5245222+ 83 Linux
/dev/sdb4 1437 8924 60147360 f Win95 Ext'd (LBA)
/dev/sdb5 1437 8924 60147328+ 83 Linux
Command (m for help): d {删除分區}
Partition number (1-5): 3 {選擇分區編号}
{請留意sdb3的分區start =785, End = 1436 }
Command (m for help): p
{上面的顯示出已經删除了 /dev/sdb3.....}
Command (m for help): d {删除分區}
Partition number (1-5): 2 {選擇分區編号}
Command (m for help): n {建立new的分區}
Command action
l logical (5 or over) {分區類型 邏輯分區}
p primary partition (1-4) {分區類型 主分區 }
p
Partition number (1-4): 2
First cylinder (523-8924, default 523):
Using default value 523
Last cylinder or +size or +sizeM or +sizeK (523-1436, default 1436):
Using default value 1436
/dev/sdb2 523 1436 7341705 83 Linux
Command (m for help): w {最終寫入資料,進行确認儲存}
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
{要umount所在的檔案系統}
#partprobe {新增加這個指令!!必須運作這條指令才能生産新的裝置檔案 /dev/sda2,——ken }
# resize2fs -p /dev/sdb2 7341705
resize2fs 1.32 (09-Nov-2002)
The containing partition (or device) is only 1835426 blocks.
You requested a new size of 7341705 blocks.
{增加了上條指令partprobe後,運作resize2fs -p /dev/sdb2 7341705 可能!!(有些時候是有出現的)不會出現
resize2fs 1.32 (09-Nov-2002)
You requested a new size of 7341705 blocks. Syncing disks.
變成 會提示 你要 運作 e2fsck -f /dev/sdb2}
{e2fsck -f /dev/sdb2 運作後提示要修複 ....Fix <y>,那麼 就加上參數 -y ;e2fsck -y -f /dev/sdb2}
# e2fsck -f /dev/sdb2
e2fsck 1.32 (09-Nov-2002)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/var: 599/262144 files (4.5% non-contiguous), 74698/524120 blocks
# resize2fs -p /dev/sdb2
Begin pass 1 (max = 40)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/sdb2 is now 1835008 blocks long.
然後 mount 上 ls 一下 就發現 原來 sdb2 的區大了 還有 sdb3 的東西也在
{上述說 sdb3的東西還在 ,我沒有試驗出來, sdb2 的東西就還在!(也就是說更改後分區的(cylinders )柱面start 值不變的,那麼資料還是可以存在)!
本文轉自 freeterman 51CTO部落格,原文連結:http://blog.51cto.com/myunix/1114365,如需轉載請自行聯系原作者