linux不用LVM进行文件系统扩展
近期调整linux服务器磁盘,发现出了点笑话。以前总以为UNIX/LINUX使用了lvm才能扩展或缩小卷和文件系统,今天才发现我错了:即使没有lvm,linux也能扩展卷和及其相应的文件系统而不会丢失原有数据。
以下是测试步骤,记录备查。
1、系统是redhat linux 6
[root@localhost ku]# uname -r
2.6.32-131.0.15.el6.x86_64
[root@localhost ku]# more /etc/redhat-release
Red Hat Enterprise Linux Server release 6.1 (Santiago)
[root@localhost ku]#
2、创建/dev/sdb1及其文件系统,创建文本文件
[root@localhost ku]# echo welcome to redhat world > ricky
[root@localhost ku]# more ricky
welcome to redhat world
3、目前/dev/sdb1对应的文件系统/ku为1.2G
[root@localhost ku]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
16G 3.7G 11G 25% /
tmpfs 613M 88K 613M 1% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/sdb1 1.2G 34M 1.1G 3% /ku
4、卸载/ku
[root@localhost ku]# cd /
[root@localhost /]# umount /ku
[root@localhost /]#
5、用fdisk命令删除/dev/sdb1分区,然后重新创建/dev/sdb1分区,并指定大小为4G
[root@localhost /]# 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): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x54f7c6df
Device Boot Start End Blocks Id System
/dev/sdb1 1 393 3156741 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +4G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost /]#
6、fdisk -l /dev/sdb输出可以看出,cylinder已经由393扩为523
[root@localhost /]# fdisk -l /dev/sdb
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x54f7c6df
Device Boot Start End Blocks Id System
/dev/sdb1 1 523 4200966 83 Linux
7、先check文件系统
[root@localhost /]# e2fsck -f /dev/sdb1
e2fsck 1.41.12 (17-May-2010)
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
/dev/sdb1: 12/73760 files (0.0% non-contiguous), 13234/307200 blocks
8、将文件系统resize为2G
[root@localhost /]# resize2fs /dev/sdb1 2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/sdb1 to 524288 (4k) blocks.
The filesystem on /dev/sdb1 is now 524288 blocks long.
[root@localhost /]# mount /dev/sdb1 /ku
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
16G 3.7G 11G 25% /
tmpfs 613M 88K 613M 1% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/sdb1 2.0G 34M 1.9G 2% /ku
[root@localhost /]#
9、检查扩容前的文件是否正确无损
[root@localhost /]# cd /ku
[root@localhost ku]# more ricky
welcome to redhat world
[root@localhost ku]#
10、当然也可以在线扩展文件系统
[root@localhost ku]# resize2fs /dev/sdb1 2500M
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/sdb1 is mounted on /ku; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/sdb1 to 640000 (4k) blocks.
The filesystem on /dev/sdb1 is now 640000 blocks long.
[root@localhost ku]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
16G 3.7G 11G 25% /
tmpfs 613M 88K 613M 1% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/sdb1 2.5G 34M 2.3G 2% /ku
[root@localhost ku]#
11、但是不可以在线缩小;要缩小文件系统必须先卸载文件系统
[root@localhost ku]# resize2fs /dev/sdb1 1G
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/sdb1 is mounted on /ku; on-line resizing required
On-line shrinking from 640000 to 262144 not supported.
[root@localhost ku]# cd /
[root@localhost /]# umount /ku
[root@localhost /]# resize2fs /dev/sdb1 1G
resize2fs 1.41.12 (17-May-2010)
Please run ‘e2fsck -f /dev/sdb1’ first.
[root@localhost /]# e2fsck -f /dev/sdb1
e2fsck 1.41.12 (17-May-2010)
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
/dev/sdb1: 12/147520 files (0.0% non-contiguous), 17864/640000 blocks
[root@localhost /]# resize2fs /dev/sdb1 1G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/sdb1 to 262144 (4k) blocks.
The filesystem on /dev/sdb1 is now 262144 blocks long.
[root@localhost /]# mount /dev/sdb1 /ku
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
16G 3.7G 11G 25% /
tmpfs 613M 88K 613M 1% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/sdb1 1010M 34M 939M 4% /ku
12、当然,你不能将文件系统扩展为比它的逻辑卷大
[root@localhost /]# resize2fs /dev/sdb1 5G
resize2fs 1.41.12 (17-May-2010)
The containing partition (or device) is only 1050241 (4k) blocks.
You requested a new size of 1310720 blocks.
时间周期会比较久,可以通过进程状态判断
分享到: | |
没有评论