linux分区扩容

简介:

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
 
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/sdb4           1437      8924 60147360    f Win95 Ext'd (LBA)
/dev/sdb5           1437      8924 60147328+ 83 Linux
{上面的显示出已经删除了 /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
 
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      1436    7341705    83 Linux
/dev/sdb4           1437      8924 60147360    f Win95 Ext'd (LBA)
/dev/sdb5           1437      8924 60147328+ 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.
 
Syncing disks.
 
{增加了上条命令partprobe后,运行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. 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
resize2fs 1.32 (09-Nov-2002)
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,如需转载请自行联系原作者
相关文章
|
1月前
|
Linux Shell C语言
【Shell 命令集合 磁盘维护 】Linux 分区管理的工具 sfdisk命令使用教程
【Shell 命令集合 磁盘维护 】Linux 分区管理的工具 sfdisk命令使用教程
30 1
|
1月前
|
存储 Shell Linux
【Shell 命令集合 磁盘维护 】Linux 管理硬盘分区 mpartition命令使用教程
【Shell 命令集合 磁盘维护 】Linux 管理硬盘分区 mpartition命令使用教程
36 1
|
1月前
|
监控 Linux Shell
【Shell 命令集合 磁盘维护 】Linux 交换分区的特殊文件或设备 swapon命令使用指南
【Shell 命令集合 磁盘维护 】Linux 交换分区的特殊文件或设备 swapon命令使用指南
38 1
|
4月前
|
IDE Linux 开发工具
Linux添加硬盘并进行分区、格式化、挂载及卸载
Linux添加硬盘并进行分区、格式化、挂载及卸载
127 0
|
4月前
|
Linux Windows
linux(三十)硬盘分区命令fdisk
linux(三十)硬盘分区命令fdisk
67 1
|
1月前
|
存储 安全 Linux
【Shell 命令集合 磁盘维护 】Linux 在特定的分区上建立 linux 文件系统 mkfs命令使用教程
【Shell 命令集合 磁盘维护 】Linux 在特定的分区上建立 linux 文件系统 mkfs命令使用教程
27 0
|
6月前
|
Linux
生产环境Linux服务器磁盘分区、无损扩容根分区以及挂载磁盘到目录实战
生产环境Linux服务器磁盘分区、无损扩容根分区以及挂载磁盘到目录实战
214 0
|
14天前
|
Linux
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
Linux操作系统调优相关工具(三)查看IO运行状态相关工具 查看哪个磁盘或分区最繁忙?
21 0
|
3月前
|
弹性计算 Linux Shell
阿里云ecs linux系统如何进行系统盘的扩容
【1月更文挑战第25天】【1月更文挑战第122篇】阿里云ecs linux系统如何进行系统盘的扩容
206 1
|
1天前
|
Linux
Linux(1)arm64根目录扩容
Linux(1)arm64根目录扩容
6 0