一、建立LVM
1、创建pv
[root@localhost ~]# fdisk -l
1、创建pv
[root@localhost ~]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 650 5116702+ 83 Linux
/dev/sda3 651 781 1052257+ 82 Linux swap / Solaris
[root@localhost ~]# fdisk /dev/sda
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 650 5116702+ 83 Linux
/dev/sda3 651 781 1052257+ 82 Linux swap / Solaris
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1044.
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)
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): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (782-1044, default 782):
Using default value 782
Last cylinder or +size or +sizeM or +sizeK (782-1044, default 1044):
Using default value 1044
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (782-1044, default 782):
Using default value 782
Last cylinder or +size or +sizeM or +sizeK (782-1044, default 1044):
Using default value 1044
Command (m for help): n
First cylinder (782-1044, default 782):
Using default value 782
Last cylinder or +size or +sizeM or +sizeK (782-1044, default 1044): +50M
First cylinder (782-1044, default 782):
Using default value 782
Last cylinder or +size or +sizeM or +sizeK (782-1044, default 1044): +50M
Command (m for help): n
First cylinder (789-1044, default 789):
Using default value 789
Last cylinder or +size or +sizeM or +sizeK (789-1044, default 1044): +50M
First cylinder (789-1044, default 789):
Using default value 789
Last cylinder or +size or +sizeM or +sizeK (789-1044, default 1044): +50M
Command (m for help): t
Partition number (1-6): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Partition number (1-6): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
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)
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): p
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 650 5116702+ 83 Linux
/dev/sda3 651 781 1052257+ 82 Linux swap / Solaris
/dev/sda4 782 1044 2112547+ 5 Extended
/dev/sda5 782 788 56196 8e Linux LVM
/dev/sda6 789 795 56196 8e Linux LVM
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 650 5116702+ 83 Linux
/dev/sda3 651 781 1052257+ 82 Linux swap / Solaris
/dev/sda4 782 1044 2112547+ 5 Extended
/dev/sda5 782 788 56196 8e Linux LVM
/dev/sda6 789 795 56196 8e Linux LVM
Command (m for help): w
The partition table has been altered!
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.
Syncing disks.
[root@localhost ~]# partprobe
Warning: Unable to open /dev/hdc read-write (Read-only file system). /dev/hdc has been opened read-only.
[root@localhost ~]# pvcreate /dev/sda5
Physical volume "/dev/sda5" successfully created
2、建立vg
[root@localhost ~]# vgcreate mainVG /dev/sda5
Volume group "mainVG" successfully created
3、建立lv
[root@localhost ~]# lvcreate -L 20M -n lstLV mainVG
Logical volume "lstLV" created
二、调整LVM
1、调整vg
[root@localhost ~]# pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created
[root@localhost ~]# vgextend mainVG /dev/sda6
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "mainVG" successfully extended
[root@localhost ~]# vgdisplay mainVG | grep 'VG Size'
VG Size 104.00 MB
[root@localhost ~]# vgreduce mainVG /dev/sda6
Removed "/dev/sda6" from volume group "mainVG"
[root@localhost ~]# vgdisplay mainVG | grep 'VG Size'
VG Size 52.00 MB
2、调整lv
[root@localhost ~]# mkfs.ext3 /dev/mainVG/lstLV
[root@localhost ~]# lvextend -L +20M /dev/mainVG/lstLV
Extending logical volume lstLV to 40.00 MB
Logical volume lstLV successfully resized
[root@localhost ~]# tune2fs -l /dev/mainVG/lstLV | grep Block
Block count: 20480
Block size: 1024
Blocks per group: 8192
[root@localhost ~]# resize2fs /dev/mainVG/lstLV
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mainVG/lstLV to 40960 (1k) blocks.
The filesystem on /dev/mainVG/lstLV is now 40960 blocks long.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost ~]# partprobe
Warning: Unable to open /dev/hdc read-write (Read-only file system). /dev/hdc has been opened read-only.
[root@localhost ~]# pvcreate /dev/sda5
Physical volume "/dev/sda5" successfully created
2、建立vg
[root@localhost ~]# vgcreate mainVG /dev/sda5
Volume group "mainVG" successfully created
3、建立lv
[root@localhost ~]# lvcreate -L 20M -n lstLV mainVG
Logical volume "lstLV" created
二、调整LVM
1、调整vg
[root@localhost ~]# pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created
[root@localhost ~]# vgextend mainVG /dev/sda6
/dev/cdrom: open failed: Read-only file system
Attempt to close device '/dev/cdrom' which is not open.
Volume group "mainVG" successfully extended
[root@localhost ~]# vgdisplay mainVG | grep 'VG Size'
VG Size 104.00 MB
[root@localhost ~]# vgreduce mainVG /dev/sda6
Removed "/dev/sda6" from volume group "mainVG"
[root@localhost ~]# vgdisplay mainVG | grep 'VG Size'
VG Size 52.00 MB
2、调整lv
[root@localhost ~]# mkfs.ext3 /dev/mainVG/lstLV
[root@localhost ~]# lvextend -L +20M /dev/mainVG/lstLV
Extending logical volume lstLV to 40.00 MB
Logical volume lstLV successfully resized
[root@localhost ~]# tune2fs -l /dev/mainVG/lstLV | grep Block
Block count: 20480
Block size: 1024
Blocks per group: 8192
[root@localhost ~]# resize2fs /dev/mainVG/lstLV
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mainVG/lstLV to 40960 (1k) blocks.
The filesystem on /dev/mainVG/lstLV is now 40960 blocks long.
[root@localhost ~]# tune2fs -l /dev/mainVG/lstLV | grep Block
Block count: 40960
Block size: 1024
Blocks per group: 8192
[root@localhost ~]# e2fsck -f /dev/mainVG/lstLV
e2fsck 1.39 (29-May-2006)
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/mainVG/lstLV: 11/8560 files (9.1% non-contiguous), 2368/40960 blocks
[root@localhost ~]# resize2fs /dev/mainVG/lstLV 20M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mainVG/lstLV to 20480 (1k) blocks.
The filesystem on /dev/mainVG/lstLV is now 20480 blocks long.
Block count: 40960
Block size: 1024
Blocks per group: 8192
[root@localhost ~]# e2fsck -f /dev/mainVG/lstLV
e2fsck 1.39 (29-May-2006)
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/mainVG/lstLV: 11/8560 files (9.1% non-contiguous), 2368/40960 blocks
[root@localhost ~]# resize2fs /dev/mainVG/lstLV 20M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mainVG/lstLV to 20480 (1k) blocks.
The filesystem on /dev/mainVG/lstLV is now 20480 blocks long.
[root@localhost ~]# lvreduce -L 20M /dev/mainVG/lstLV
WARNING: Reducing active logical volume to 20.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lstLV? [y/n]: y
Reducing logical volume lstLV to 20.00 MB
Logical volume lstLV successfully resized
WARNING: Reducing active logical volume to 20.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lstLV? [y/n]: y
Reducing logical volume lstLV to 20.00 MB
Logical volume lstLV successfully resized