新建逻辑卷:
1) 新加硬盘,并用fdisk进行分区 fdisk /dev/sdb
2) 创建物理卷 pvcreate /dev/sdb
3) 创建物理卷组 vgcreate data /dev/sdb1
4) 创建逻辑卷 lvcreate �Cn data2 -L 90G data
5) 对创建的逻辑卷进行格式化mkfs.ext3 /dev/data/data2
6) 对卷组进行激活vgchange -a y data (据说不激活不能进行挂载,有的说激活只是起到保护数据完整性的作用。redhat4上我创建后没有激活也可用,不晓得原因)
7) 对逻辑卷进行挂载 mount /dev/data/data2 /data2
8) 如果要开机自动挂载,则vi /etc/fstab,将该逻辑卷添加进列表。
更改逻辑卷:
1)增加硬盘到vg里,pvcreate /dev/sdc1,之后再格式化mkfs.ext3 /dev/sdc1,最后vgextend data /dev/sdc1
2)增加逻辑卷容量 lvextend �CL +3.8G /dev/data/data2,之后重新识别一下磁盘容量resize2fs /dev/data/data2
3) 减小逻辑卷容量lvreduce -L -3.8G /dev/data/data2 之后重新识别一下磁盘容量resize2fs /dev/data/data2(切记,这个减小命令最好永远不要用,因为它会导致文件系统出问题。)
删除逻辑卷:
1) 删除逻辑卷,先卸载逻辑卷umount /data2,如果提示:不能卸载,卷组正在使用中时候(umount: /data2: device is busy),可以用fuser -v /data2 来查看输出情况,查到是什么用户,什么进程在访问,然后用kill -9 PID强制终止进程。然后再重新卸载。
2) Lvremove /dev/data/data2即卸载完成。Lvdisplay查看是否还存在data逻辑卷。
使用全部剩余空间创建lvm
[root@ccdb4 ~]# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 514048+ 83 Linux
/dev/sda2 65 586 4192965 82 Linux swap / Solaris
/dev/sda3 587 7832 58203495 83 Linux
Disk /dev/sdb: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb4 1 13054 104856223+ 8e Linux LVM
[root@ccdb4 ~]# lvcreate -n data2 -L 100G oradata
Volume group "oradata" has insufficient free space (25599 extents): 25600 required.
报错。
[root@ccdb4 ~]# vgdisplay
--- Volume group ---
VG Name oradata
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 100.00 GB
PE Size 4.00 MB
Total PE 25599
Alloc PE / Size 0 / 0
Free PE / Size 25599 / 100.00 GB --这里是剩余空间的大小
VG UUID kMFixn-l93t-vMlm-RpOO-eT8s-W30z-wh5Kys
[root@ccdb4 ~]# lvcreate -n data2 -l 25599 oradata
Rounding up size to full physical extent 100.00 GB
Logical volume "oradata" created
不能格式化报错
[root@ccdb4 ~]# mkfs.ext3 /dev/sdb4
mke2fs 1.39 (29-May-2006)
/dev/sdb4 is apparently in use by the system; will not make a filesystem here!
[root@ccdb4 ~]# dmsetup status
oradata-oradata: 0 52428800 linear
[root@ccdb4 ~]# dmsetup remove_all
[root@ccdb4 ~]# mkfs.ext3 /dev/sdb4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
13107200 inodes, 26214055 blocks
1310702 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
这步会清除之前创建的vg,pv……一般不要用这个命令清除。