LINUX在线扩文件系统(/目录)
我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢!
由于博客中有大量代码,通过页面浏览效果更佳。
LINUX在线扩文件系统(/目录)
今天在做gc 12cr2版本的实验的时候,发现/目录的空间不够了,于是手动增加了一块盘,在线扩文件系统,不过前提是/文件系统是放到VG里面的,而不是单独的分区,如果是单个分区,是不能扩的。测试环境:OS:RHEL 5.4
1,查看硬盘
如果硬盘没有发现,我们可以通过/etc/init.d/kudzu来在线发现,一直觉得LINUX在线配置硬件设置这块,就没有AIX这一块做得好。
[root@gc12r2 ~]# fdisk -lDisk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 5221 41833260 8e Linux LVMDisk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDisk /dev/sdb doesn't contain a valid partition table
2,格式化磁盘
[root@gc12r2 ~]# pvcreate /dev/sdbPhysical volume "/dev/sdb" successfully created
3,把PV增加到VG中
[root@gc12r2 ~]# vgsVG #PV #LV #SN Attr VSize VFreerootvg 1 2 0 wz--n- 39.88G 2.50G[root@gc12r2 ~]# vgextend rootvg /dev/sdb/dev/hdc: open failed: Read-only file system/dev/cdrom: open failed: Read-only file systemAttempt to close device '/dev/cdrom' which is not open.Volume group "rootvg" successfully extended[root@gc12r2 ~]# vgdisplay -vFinding all volume groupsFinding volume group "rootvg"--- Volume group ---VG Name rootvgSystem ID Format lvm2Metadata Areas 2Metadata Sequence No 4VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 2Act PV 2VG Size 79.84 GBPE Size 32.00 MBTotal PE 2555Alloc PE / Size 1196 / 37.38 GBFree PE / Size 1359 / 42.47 GBVG UUID 1zJ3d3-b5WO-qNXD-F6a6-j4mA-rKMj-k7Ar8r--- Logical volume ---LV Name /dev/rootvg/rootlvVG Name rootvgLV UUID apcaZv-CeDg-gNmg-f7pL-duSG-4UPj-REGcApLV Write Access read/writeLV Status available# open 1LV Size 29.28 GBCurrent LE 937Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:0--- Logical volume ---LV Name /dev/rootvg/swapVG Name rootvgLV UUID LsMRXz-C0oh-rnvP-10iT-Di8q-77YR-e4XlY7LV Write Access read/writeLV Status available# open 1LV Size 8.09 GBCurrent LE 259Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:1--- Physical volumes ---PV Name /dev/sda2 PV UUID sqToLA-R3Tg-jfCN-NR1f-bLie-e7cD-wMzZLPPV Status allocatableTotal PE / Free PE 1276 / 80PV Name /dev/sdb PV UUID 2q1urp-b0VM-h7Pm-G0ZT-FpdQ-TrS5-bEzc9dPV Status allocatableTotal PE / Free PE 1279 / 1279
4,在线扩LV
[root@gc12r2 ~]# lvextend -L50G /dev/rootvg/rootlv Extending logical volume rootlv to 50.00 GBLogical volume rootlv successfully resized
5,在线扩文件系统
如果是rhel 4版本的系统需要使用ext2online命令来实现。
[root@gc12r2 ~]# resize2fs -p /dev/rootvg/rootlv
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/rootvg/rootlv is mounted on /; on-line resizing required
Performing an on-line resize of /dev/rootvg/rootlv to 13107200 (4k) blocks.
The filesystem on /dev/rootvg/rootlv is now 13107200 blocks long.[root@gc12r2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv49G 22G 25G 48% /
/dev/sda1 99M 13M 82M 14% /boot
tmpfs 3.9G 0 3.9G 0% /dev/shm
//192.168.111.1/install932G 729G 204G 79% /sof
已经扩展成功。
下面是resize2fs命令的帮助手册
[root@gc12r2 ~]# man resize2fs
RESIZE2FS(8) RESIZE2FS(8)NAMEresize2fs - ext2/ext3 file system resizerSYNOPSISresize2fs [ -d debug-flags ] [ -S RAID-stride ] [ -f ] [ -F ] [ -p ] device [ size ]DESCRIPTIONThe resize2fs program will resize ext2 or ext3 file systems. It can be used to enlarge or shrink an unmounted file system located on device. If the filesystem ismounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, the Linux 2.6 kernel supportson-line resize for filesystems mounted using ext3 only.).The size parameter specifies the requested new size of the filesystem. If no units are specified, the units of the size parameter shall be the filesystem blocksize ofthe filesystem. Optionally, the size parameter may be suffixed by one of the following the units designators: ’s’, ’K’, ’M’, or ’G’, for 512 byte sectors, kilobytes,megabytes, or gigabytes, respectively. The size of the filesystem may never be larger than the size of the partition. If size parameter is not specified, it willdefault to the size of the partition.The resize2fs program does not manipulate the size of partitions. If you wish to enlarge a filesystem, you must first make sure you can expand the size of the underly-ing partition first. This can be done using fdisk(8) by deleting the partition and recreating it with a larger size or using lvextend(8), if you’re using the logicalvolume manager lvm(8). When recreating the partition, make sure you create it with the same starting disk cylinder as before! Otherwise, the resize operation will cer-tainly not work, and you may lose your entire filesystem. After running fdisk(8), run resize2fs to resize the ext2 filesystem to use all of the space in the newlyenlarged partition.If you wish to shrink an ext2 partition, first use resize2fs to shrink the size of filesystem. Then you may use fdisk(8) to shrink the size of the partition. Whenshrinking the size of the partition, make sure you do not make it smaller than the new size of the ext2 filesystem!OPTIONS-d debug-flagsTurns on various resize2fs debugging features, if they have been compiled into the binary. debug-flags should be computed by adding the numbers of the desiredfeatures from the following list:1 - Print out all disk I/O2 - Debug block relocations8 - Debug inode relocations16 - Debug moving the inode table-S RAID-strideThe resize2fs program will heuristically determine the RAID stride that was specified when the filesystem was created. This option allows the user to explicitlyspecify a RAID stride setting to be used by resize2fs instead.-p Prints out a percentage completion bars for each resize2fs operation, so that the user can keep track of what the program is doing.-f Forces resize2fs to proceed with the filesystem resize operation, overriding some safety checks which resize2fs normally enforces.-F Flush the filesystem device’s buffer caches before beginning. Only really useful for doing resize2fs time trials.AUTHORresize2fs was written by Theodore Ts’o <tytso@mit.edu>.COPYRIGHTResize2fs is Copyright 1998 by Theodore Ts’o and PowerQuest, Inc. All rights reserved. As of April, 2000 Resize2fs may be redistributed under the terms of the GPL.SEE ALSOfdisk(8), e2fsck(8), mke2fs(8), lvm(8), lvextend(8)E2fsprogs version 1.39 May 2006 RESIZE2FS(8)
------------------作者介绍-----------------------
姓名:黄廷忠
个人博客: (http://www.htz.pw)
CSDN地址: (https://blog.csdn.net/wwwhtzpw)
博客园地址: (https://www.cnblogs.com/www-htz-pw)