Disk管理
LVM(Logical Volume Manager)逻辑卷管理
建立在硬盘和分区之上,文件系统之下的逻辑层,能在保持原有数据不变的状况下动态调整磁盘容量
/boot分区不能创建在逻辑卷上(跟启动引导相关)必须独立出来
LVM概念 创建时在硬盘头部预留一个块,用于保存LVM属性
PV物理卷--->VG卷组--->LV逻辑卷--->格式化--->挂载使用文件系统
2、LVM管理命令
功能 物理卷 卷组 逻辑卷
scan(扫描) pvscan vgscan lvscan
create(创建) pvcreate vgcreate lvcreate
display(显示) pvdisplay vgdisplay lvdisplay
remove(移除) pvremove vgremove lvremove
extend(扩充) vgextend lvextend
reduce(减小) vgreduce lvreduce
3、LVM用法
pvcreate 设备名 创建PV
vgcreate 卷组名 物理卷名1 物理卷名2 创建VG
lvcreate -L 大小 -n 逻辑卷名 卷组名 创建LVM
4、增大LVM
lvextend -L +大小 /dev/卷组名/逻辑卷名 扩大LVM
resize2fs /dev/卷组名/逻辑卷名 更新文件系统
5、减小LVM
umount /dev/vg01/lv01 卸载分区
e2fsck -f /dev/vg01/lv01 检查分区
resize2fs /dev/vg01/lv01 450M 先减小文件系统
lvreduce -L 450M /dev/vg01/lv01 再减小分区
[[email protected] ~]# fdisk -l
Disk /dev/hdb doesn‘t contain a valid partition table
[[email protected] ~]# fdisk /dev/hdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-44384, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-44384, default 44384): +2G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (4136-44384, default 4136):
Using default value 4136
Last cylinder or +size or +sizeM or +sizeK (4136-44384, default 44384): +2G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (8271-44384, default 8271):
Using default value 8271
Last cylinder or +size or +sizeM or +sizeK (8271-44384, default 44384): +2G
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/hdb1 1 4135 1953756 83 Linux
/dev/hdb2 4136 8270 1953787+ 83 Linux
/dev/hdb3 8271 12405 1953787+ 83 Linux
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): p
[[email protected] ~]# pvcreate /dev/hdb[123]
[[email protected] ~]# pvdisplay /dev/hdb[123]
[[email protected] ~]# vgscan
[[email protected] ~]# vgcreate vg01 /dev/hdb[123]
[[email protected] ~]# vgdisplay vg01
[[email protected] ~]# lvscan
[[email protected] ~]# lvcreate -L 3G -n lvm01 vg01
[[email protected] ~]# mkfs.ext3 /dev/vg01/lvm01
[[email protected] ~]# mkdir /lvm01
[[email protected] ~]# mount /dev/vg01/lvm01 /lvm01
[[email protected] ~]# cd /lvm01
[[email protected] lvm01]# touch 1
[[email protected] ~]# df -Th
[[email protected] ~]# lvdisplay /dev/vg01/lvm01
[[email protected] ~]# lvextend -L +512M /dev/vg01/lvm01
[[email protected] ~]# lvdisplay /dev/vg01/lvm01
[[email protected] ~]# resize2fs /dev/vg01/lvm01
[[email protected] ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/vg01-lvm01 ext3 3.5G 72M 3.3G 3% /lvm01
[[email protected] ~]# umount /dev/vg01/lvm01
[[email protected] ~]# e2fsck -f /dev/vg01/lvm01
[[email protected] ~]# resize2fs /dev/vg01/lvm01 2G
[[email protected] ~]# lvreduce -L 2G /dev/vg01/lvm01
[[email protected] ~]# mount /dev/vg01/lvm01 /lvm01/
[[email protected] ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/vg01-lvm01 ext3 2.0G 70M 1.9G 4% /lvm01
磁盘配额
方法一:
[[email protected] ~]# mount -o remount,usrquota,grpquota /dev/vg01/lvm01 /lvm01/
[[email protected] ~]# mount
/dev/mapper/vg01-lvm01 on /lvm01 type ext3 (rw,usrquota,grpquota)
[[email protected] ~]# chmod 777 /lvm01/
方法二:
[[email protected] ~]# vi /etc/fstab
/dev/vg01/lvm01 /lvm01 ext3 defaults,usrquota,grpquota 0 0
在你要做配额的分区后面添加usrquota,grpquota
[[email protected] ~]# umount /lvm01/ && mount -a
[[email protected] ~]# mount -o remount /dev/vg01/lvm01
[[email protected] ~]# mount 查看所配额分区后面有没(rw,usrquota,grpquota)
/dev/mapper/vg01-lvm01 on /lvm01 type ext3 (rw,usrquota,grpquota)
[[email protected] ~]# quotacheck -cmug /dev/vg01/lvm01 创建配额文件
[[email protected] ~]# quotacheck -augcv
[[email protected] ~]# ll /lvm01/aquota.*
-rw------- 1 root root 6144 09-06 23:59 /lvm01/aquota.group
-rw------- 1 root root 6144 09-06 23:59 /lvm01/aquota.user
[[email protected] ~]# useradd jack
[[email protected] ~]# passwd jack
[[email protected] ~]# edquota -u jack
Disk quotas for user jack (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/vg01-lvm01 0 80000 100000 0 40 50
Filesystem 表示本行配置记录对应的文件系统,配额作用范围
blocks 表示用户当前已用的硬盘容量
inodes 表示用户当前拥有的文件数量
soft 第三列的soft表示硬盘容量的软限制、第六列的soft表示文件数量的软限制
hard 第四列的hard表示硬盘容量的硬限制、第七列的hard表示文件数量的硬限制
edquota -u 用户
-g 组
-t 时间
-p 复制模板
[[email protected] ~]# edquota -t
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/mapper/vg01-lvm01 3days 3days
[[email protected] ~]# quotaon -ugv /lvm01/ 开启配额
/dev/mapper/vg01-lvm01 [/lvm01]: group quotas turned on
/dev/mapper/vg01-lvm01 [/lvm01]: user quotas turned on
[[email protected] ~]# su - jack 切换用户
[[email protected] ~]$ dd if=/dev/zero of=/lvm01/test bs=1M count=70
70+0 records in
70+0 records out
73400320 bytes (73 MB) copied, 0.10486 seconds, 700 MB/s
[[email protected] ~]$ dd if=/dev/zero of=/lvm01/test bs=1M count=79
dm-0: warning, user block quota exceeded.
79+0 records in
79+0 records out
82837504 bytes (83 MB) copied, 0.167987 seconds, 493 MB/s
[[email protected] ~]$ dd if=/dev/zero of=/lvm01/test bs=1M count=110
dm-0: warning, user block quota exceeded.
dm-0: write failed, user block limit reached.
dd: 写入 “/lvm01/test”: 超出磁盘限额
98+0 records in
97+0 records out
102293504 bytes (102 MB) copied, 0.152686 seconds, 670 MB/s
dd if=哪里来 of=到哪里去 bs=大小 count=次数
quota -u 用户 查看用户配额情况
-g 组 查看组配额情况
edquota -p 已设置配额账户 -u 未设置配额账户
quotaoff -a 关闭配额
repquota -a