制作lvm:
添加三块2G的虚拟硬盘,并且,添加到系统系统管理。
挂载硬盘到系统里,可以看到刚刚挂载的硬盘"sdb","sdc","sdd".
[root@localhost ~]# echo "scsi add-single-device 0 0 1 0" > /proc/scsi/scsi[root@localhost ~]# echo "scsi add-single-device 0 0 2 0" > /proc/scsi/scsi[root@localhost ~]# echo "scsi add-single-device 0 0 3 0" > /proc/scsi/scsi [root@localhost ~]# ls /dev/sd[tab][tab]sda sda1 sda2 sda3 sdb sdc sdd
首先,把三块硬盘整合成一块物理卷创建物理卷组(physical volume)
root@localhost ~]# pvcreate /dev/sd[b-d] Physical volume "/dev/sdb" successfully created Physical volume "/dev/sdc" successfully created Physical volume "/dev/sdd" successfully created
再创建卷组(volume Group)
[root@localhost ~]# vgcreate vgtest /dev/sd[b-d] Volume group "vgtest" successfully created
最后创建逻辑卷(Logical Volume)
[root@localhost ~]# lvcreate -L 5.9G -n lvtest vgtest /dev/cdrom: open failed: Read-only file system Rounding up size to full physical extent 5.90 GB Logical volume "lvtest" created
格式化逻辑卷
[root@localhost ~]# mkfs -t ext3 /dev/vgtest/lvtest
把逻辑卷挂载到/web目录上,查看/web目录的空间大小
[root@localhost ~]# mkdir /web [root@localhost ~]# mount /dev/vgtest/lvtest /web [root@localhost ~]# df -h /web Filesystem Size Used Avail Use% Mounted on /dev/mapper/vgtest-lvtest 5.9G 140M 5.4G 3% /web
扩展LVM:
添加一块20G的虚拟硬盘,并且,添加到系统系统管理。
[root@localhost ~]# echo "scsi add-single-device 0 0 4 0" > /proc/scsi/scsi
创建物理卷
[root@localhost ~]# pvcreate /dev/sde Physical volume "/dev/sde" successfully created
vgexten 命令扩展卷组的磁盘空间
[root@localhost ~]# vgextend vgtest /dev/sde Volume group "vgtest" successfully extended
lvexten 命令扩展逻辑卷的磁盘空间
[root@localhost ~]# lvextend -L +20G /dev/vgtest/lvtest /dev/cdrom: open failed: Read-only file system Extending logical volume lvtest to 25.90 GB Logical volume lvtest successfully resized
停止lvm的工作,使用“e2fsck”和 “ resize2fs”重新识别文件系统的大小
[root@localhost ~]# umount /dev/vgtest/lvtest [root@localhost ~]# e2fsck -f /dev/vgtest/lvtest [root@localhost ~]# resize2fs /dev/vgtest/lvtest
再把lvm挂载到文件目录上,查看/web空间大小
[root@localhost ~]# mount /dev/vgtest/lvtest /web[root@localhost ~]# df -h /webFilesystem Size Used Avail Use% Mounted on/dev/mapper/vgtest-lvtest 26G 145M 25G 1% /web
磁盘配额:
添加系统用户user1
[root@localhost ~]# useradd user1
增加对用户,组配额功能的支持。
[root@localhost ~]# mount -o remount,usrquota,grpquota /dev/vgtest/lvtest
设置每次开机后自动支持配额功能的方式挂载该分区
[root@localhost ~]# vi /etc/fstab /dev/vgtest/lvtest /web ext3 defaults,usrquota,grpquota 0 0
自动扫描文件系统,并在支持配额的文件系统中建立配额文件。
[root@localhost ~]# quotacheck -augcv [root@localhost ~]# ls -l /web -rw------- 1 root root 6144 Aug 15 01:24 aquota.group -rw------- 1 root root 6144 Aug 15 01:24 aquota.user
编辑用户配额设置,制定用户user1,磁盘容量软限制8M,硬限制10M。
【root@localhost ~]# edquota -u user1 Disk quotas for user user1 (uid 501): Filesystem blocks soft hard inodes soft hard /dev/mapper/vgtest-lvtest 0 8000 10000 0 0 0
启动文件系统的配额功能
[root@localhost ~]# quotaon -ugv /web /dev/mapper/vgtest-lvtest [/web]: group quotas turned on /dev/mapper/vgtest-lvtest [/web]: user quotas turned on
验证磁盘配额。
[root@localhost ~]# chmod -R 777 /web/[root@localhost ~]# su user1[user1@localhost root]$ dd if=/dev/zero of=/web/user1 bs=1M count=8dm-0: warning, user block quota exceeded.8+0 records in8+0 records out8388608 bytes (8.4 MB) copied, 0.0221772 seconds, 378 MB/s [user1@localhost root]$ dd if=/dev/zero of=/web/user1 bs=1M count=10dm-0: warning, user block quota exceeded.dm-0: write failed, user block limit reached.dd: writing `/web/user1': Disk quota exceeded10+0 records in9+0 records out10219520 bytes (10 MB) copied, 0.0111377 seconds, 918 MB/s
fdisk /dev/hda
n
l #选择逻辑分区,如果没有,则首先创建扩展分区,然后再添加逻辑分区(硬盘:最多四个分区P-P-P-P或P-P-P-E)
6 #分区号(从5开始),/dev/hda6
t 8e #分区类型8e表示LVM分区
fdisk使用详情(http://dragon123.blog.51cto.com/9152073/1539556)
w #写入分区表
vgdisplay #查看当前已经存在的VG信息,以存在VG:Vgtest为例
lvdisplay #查看已经存在的LV信息,以存在LV:Lgtest为例
本文允许转载,但务必保留原著地址(http://dragon123.blog.51cto.com/9152073/1540711)