RHEL6 LVM管理

2011-07-10 19:23:25

技术资料 Linux

建立LVM分区-------------
[root@localhost ~]# fdisk /dev/sda

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): n
First cylinder (781-1305, default 781):
Using default value 781
Last cylinder, +cylinders or +size{K,M,G} (781-1305, default 1305): +1G

Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)

Command (m for help): n
First cylinder (913-1305, default 913):
Using default value 913
Last cylinder, +cylinders or +size{K,M,G} (913-1305, default 1305): +1G

Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
BLKPG: Device or resource busy
error adding partition 6

建立PV-------------
[root@localhost ~]# pvcreate /dev/sda5
  Physical volume "/dev/sda5" successfully created
[root@localhost ~]# pvcreate /dev/sda6
  Physical volume "/dev/sda6" successfully created

建立VG-------------
[root@localhost ~]# vgcreate myvg /dev/sda5
  Volume group "myvg" successfully created

扩展VG-------------
[root@localhost ~]# vgextend myvg /dev/sda6
  Volume group "myvg" successfully extended

缩减VG-------------
[root@localhost ~]# vgreduce myvg /dev/sda6
  Removed "/dev/sda6" from volume group "myvg"

建立LV-------------
[root@localhost ~]# lvcreate -n mylv -L 800M myvg
  Logical volume "mylv" created

建立文件系统-------------
[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks:
 32768, 98304, 163840

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

建立挂载点-------------
[root@localhost ~]# mkdir /new

编辑fstab-------------
[root@localhost ~]# vi /etc/fstab

挂载分区-------------
[root@localhost ~]# mount -a

扩展LV-------------
[root@localhost ~]# lvresize -L +800M /dev/myvg/mylv
  Extending logical volume mylv to 1.27 GiB
  Logical volume mylv successfully resized

调整文件系统大小-------------
[root@localhost ~]# resize2fs /dev/myvg/mylv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/mylv is mounted on /new; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 6
Performing an on-line resize of /dev/myvg/mylv to 1331200 (1k) blocks.
The filesystem on /dev/myvg/mylv is now 1331200 blocks long.

卸载分区-------------
[root@localhost ~]# umount /dev/myvg/mylv

检查分区-------------
[root@localhost ~]# fsck -f /dev/myvg/mylv
fsck from util-linux-ng 2.17.2
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/mapper/myvg-mylv: 11/331216 files (0.0% non-contiguous), 52784/1331200 blocks

调整文件系统大小-------------
[root@localhost ~]# resize2fs /dev/myvg/mylv 600M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/mylv to 614400 (1k) blocks.
The filesystem on /dev/myvg/mylv is now 614400 blocks long.

调整LV大小-------------
[root@localhost ~]# lvreduce -L 600M /dev/myvg/mylv
  WARNING: Reducing active logical volume to 600.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
  Reducing logical volume mylv to 600.00 MiB
  Logical volume mylv successfully resized

挂载分区-------------
[root@localhost ~]# mount -a

移动PV-------------
[root@localhost ~]# pvmove /dev/sda5
  /dev/sda5: Moved: 2.0%
  /dev/sda5: Moved: 91.3%
  /dev/sda5: Moved: 100.0%

缩减VG-------------
[root@localhost ~]# vgreduce myvg /dev/sda5
  Removed "/dev/sda5" from volume group "myvg"
  
删除PV-------------
[root@localhost ~]# pvremove /dev/sda5
  Labels on physical volume "/dev/sda5" successfully wiped

卸载分区-------------
[root@localhost /]# umount /dev/myvg/mylv

修改LV活动状态
[root@localhost /]# lvchange -an /dev/myvg/mylv

移除LV-------------
[root@localhost /]# lvremove /dev/myvg/mylv
  Logical volume "mylv" successfully removed

移除VG-------------
[root@localhost /]# vgremove myvg
  Volume group "myvg" successfully removed

移除PV-------------
[root@localhost /]# pvremove /dev/sda6
  Labels on physical volume "/dev/sda6" successfully wiped