今天,不得不面对lvm了,毕竞是公司用的.
================================================================= 创建LVM 1、首先,我们要先创建新磁盘分区 #fdisk /dev/hda 2、激活刚创建好的分区 #partprobe
1、创建1个500MB分区(hda12),然后在fdisk命令下输入t,选择刚创建好的分区,输入8e,将刚创建好的分区转换为8e格式。输入w保存退出 #fdisk /dev/had 总结LVM几个高级命令:lvchange、vgexport/vgimport、vgcfgbackup/vgcfgrestore =============================================================== |
----
So you have an LVM based file system that needs extended? Now a days this can be done pretty quickly with a few commands. The following will walk you through a basic online resize of an ext3 and reiserfs based filesystem. Keep in mind, if you’re dealing with critical production data of any type, you probably should resize those offline, and during a scheduled maintenance window as a safety measure.
#df -k /mnt/test
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/testvg-test
2097084 1760768 336316 84% /mnt/test
When resizing volumes, you have to keep in mind that the file system also has to be made aware of the new volume size. A common misconception is that you can resize the LVM device and the file system will automatically grow with it, not the case in ext3 and reiserfs that I’m aware of.
The test volume we’re messing with is nearly full, so we will add another 1GB to this. We’ll start off first by extending the logical volume using the ‘lvextend’ command.
#lvextend
Please specify either size or extents (not both)
lvextend: Add space to a logical volumelvextend
[-A|--autobackup y|n]
[--alloc AllocationPolicy]
[-d|--debug]
[-h|--help]
[-i|--stripes Stripes [-I|--stripesize StripeSize]]
{-l|–extents [+]LogicalExtentsNumber[%{VG|FREE}] |
-L|–size [+]LogicalVolumeSize[kKmMgGtTpPeE]}
[-m|--mirrors Mirrors]
[-n|--nofsck]
[-r|--resizefs]
[-t|--test]
[--type VolumeType]
[-v|--verbose]
[--version]
LogicalVolume[Path] [ PhysicalVolumePath... ]#lvextend -L+1G /dev/testvg/test
Extending logical volume test to 3.00 GB
Logical volume test successfully resized
#lvs /dev/testvg/test
LV VG Attr LSize Origin Snap% Move Log Copy%
test testvg -wi-ao 3.00G
#
#df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
2.0G 1.7G 329M 84% /mnt/test
#
Note the file system size remains at 2GB. Once the logical volume is extended, we will have to figure out what type of file system this is. You can run the following to determine this:
#mount | grep /mnt/test
/dev/mapper/testvg-test on /mnt/test type reiserfs (rw)
So we’re dealing with reiserfs.
It may also be smart to run an fsck at this point, depending on whether or not you can take the volume offline. Since this is test data, I’ll ignore the fsck and go ahead and resize the file system while it’s online. For reiserfs, this is done using the ‘resize_reiserfs’ command. You can either specify the size of let the command figure it out, and grow to the full extent of the volume. I’ll let it figure it out.
#resize_reiserfs /dev/testvg/test
resize_reiserfs 3.6.19 (2003 www.namesys.com)resize_reiserfs: On-line resizing finished successfully.
#df -h /mnt/test/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
3.0G 1.7G 1.4G 56% /mnt/test
#
That’s it… Pretty tough huh?
Now for ext3, we’ll use the same volume.
#df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
2.0G 68M 1.9G 4% /mnt/test
#mount | grep /mnt/test
/dev/mapper/testvg-test on /mnt/test type ext3 (rw)
#
#lvextend -L+1G /dev/testvg/test
Extending logical volume test to 3.00 GB
Logical volume test successfully resized
#!df
df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
2.0G 68M 1.9G 4% /mnt/test
#
You’ll resize ext3 using the ‘resize2fs’ command as shown. Pretty similar to reiserfs.
#resize2fs
resize2fs 1.40.2 (12-Jul-2007)
Usage: resize2fs [-d debug_flags] [-f] [-F] [-p] device [new_size]#resize2fs /dev/testvg/test
resize2fs 1.40.2 (12-Jul-2007)
Filesystem at /dev/testvg/test is mounted on /mnt/test; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/testvg/test to 786432 (4k) blocks.
The filesystem on /dev/testvg/test is now 786432 blocks long.#!df
df -h /mnt/test
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-test
3.0G 68M 2.8G 3% /mnt/test
#