创建PV
[root@desktop4 ~]# pvcreate /dev/sda5
WARNING: swap signature detected on /dev/sda5. Wipe it? [y/n] y
Wiping swap signature on /dev/sda5.
Writing physical volume data to disk "/dev/sda5"
Physical volume "/dev/sda5" successfully created
[root@desktop4 ~]# pvcreate /dev/sda6
Writing physical volume data to disk "/dev/sda6"
Physical volume "/dev/sda6" successfully created
[root@desktop4 ~]# pvcreate /dev/sda7
Writing physical volume data to disk "/dev/sda7"
Physical volume "/dev/sda7" successfully created
查看PV
[root@desktop4 ~]# pvscan
PV /dev/sda3 VG Vol0 lvm2 [48.82 GB / 0 free]
PV /dev/sda2 VG virt lvm2 [48.82 GB / 1.95 GB free]
PV /dev/sda5 lvm2 [101.94 MB]
PV /dev/sda6 lvm2 [101.94 MB]
PV /dev/sda7 lvm2 [101.94 MB]
Total: 5 [97.95 GB] / in use: 2 [97.65 GB] / in no VG: 3 [305.83 MB]
[root@desktop4 ~]#
创建VG、LV
[root@desktop4 ~]# vgcreate vg1 /dev/sda{5,6,7}
Volume group "vg1" successfully created
[root@desktop4 ~]# lvcreate -L 200M -n lv1 vg1
Logical volume "lv1" created
查看VG
[root@desktop4 ~]# lvscan
ACTIVE '/dev/vg1/lv1' [200.00 MB] inherit
ACTIVE '/dev/Vol0/vol_root' [48.82 GB] inherit
ACTIVE '/dev/virt/station' [19.53 GB] inherit
ACTIVE '/dev/virt/windows' [7.81 GB] inherit
ACTIVE '/dev/virt/server' [19.53 GB] inherit
格式化
[root@desktop4 ~]# mkfs.ext3 /dev/vg1/lv1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
创建目录并挂载
[root@desktop4 ~]# mkdir /dd
[root@desktop4 ~]# mount /dev/vg1/lv1 /dd
[root@desktop4 ~]#
增加磁盘容量
[root@desktop4 ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 60801.
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): p
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 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 6387 51199155 8e Linux LVM
/dev/sda3 6388 12761 51199155 8e Linux LVM
/dev/sda4 12762 60801 385881300 5 Extended
/dev/sda5 12762 12774 104391 8e Linux LVM
/dev/sda6 12775 12787 104391 8e Linux LVM
/dev/sda7 12788 12800 104391 8e Linux LVM
/dev/sda8 12801 12813 104391 83 Linux
Command (m for help): t
Partition number (1-8): 8
Hex code (type L to list codes): 8e
Changed system type of partition 8 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.
Syncing disks.
创建PV,扩容VG、LV
[root@desktop4 ~]# pvcreate /dev/sda8
Writing physical volume data to disk "/dev/sda8"
Physical volume "/dev/sda8" successfully created
[root@desktop4 ~]#
[root@desktop4 ~]# vgextend vg1 /dev/sda8
Volume group "vg1" successfully extended
[root@desktop4 ~]# lvextend -L 400M /dev/vg1/lv1
Extending logical volume lv1 to 400.00 MB
Logical volume lv1 successfully resized
扩容前SIZE
[root@desktop4 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/Vol0-vol_root
48G 3.4G 42G 8% /
/dev/sda1 99M 13M 81M 14% /boot
tmpfs 3.8G 0 3.8G 0% /dev/shm
/dev/mapper/vg1-lv1 194M 5.6M 179M 4% /dd
同步
[root@desktop4 ~]# resize2fs /dev/vg1/lv1
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg1/lv1 is mounted on /dd; on-line resizing required
Performing an on-line resize of /dev/vg1/lv1 to 409600 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 409600 blocks long.
扩容后SIZE
[root@desktop4 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/Vol0-vol_root
48G 3.4G 42G 8% /
/dev/sda1 99M 13M 81M 14% /boot
tmpfs 3.8G 0 3.8G 0% /dev/shm
/dev/mapper/vg1-lv1 388M 6.3M 362M 2% /dd
[root@desktop4 ~]#
卸载并REDUCE内存
[root@desktop4 ~]# umount /dd
[root@desktop4 ~]# resize2fs /dev/vg1/lv1 200M
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/vg1/lv1' first.
[root@desktop4 ~]# e2fsck -f /dev/vg1/lv1
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/vg1/lv1: 11/102400 files (9.1% non-contiguous), 19351/409600 blocks
关键处(大小)
[root@desktop4 ~]# resize2fs /dev/vg1/lv1 200M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
逆向REDUCE 关键处(大小)
root@desktop4 ~]# lvreduce -L 210M /dev/vg1/lv1
Rounding up size to full physical extent 212.00 MB
WARNING: Reducing active logical volume to 212.00 MB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv1? [y/n]: y
Reducing logical volume lv1 to 212.00 MB
Logical volume lv1 successfully resized
[root@desktop4 ~]#
重新挂载LV并查看结果
[root@desktop4 ~]# mount /dev/vg1/lv1 /dd
[root@desktop4 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/Vol0-vol_root
48G 3.4G 42G 8% /
/dev/sda1 99M 13M 81M 14% /boot
tmpfs 3.8G 0 3.8G 0% /dev/shm
/dev/mapper/vg1-lv1 194M 5.6M 179M 4% /dd
[root@desktop4 ~]#
注意:
两个关键处不要出错,否则可能会造成计算机无法启动。
如resize2fs /dev/vg1/lv1 200M处为200M
lvreduce -L 210M /dev/vg1/lv1处的210M改为200M
系统重启后将无法启动。
因为计算机本身的计算以及可能存在的误差。
PV----》VG-----》LV--------》文件系统
从LV处格式化后成为文件系统,200M的文件系统
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
需要的LV必然要大于200M方可支持同样大小的文件系统。