8月9日 迁移home到独立分区和实现文件系统配额

1、迁移home到独立分区

[root@centos6 app]#fdisk /dev/sdb  ---创建分区
[root@centos6 app]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1  5.8G  0 rom  /media/CDROM
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0 1000M  0 part /boot
├─sda2   8:2    0 48.8G  0 part /
├─sda3   8:3    0 39.1G  0 part /app
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sdb      8:16   0  100G  0 disk 
└─sdb1   8:17   0   10G  0 part    ---创建了一个10G的分区 
sdd      8:48   0   80G  0 disk 
├─sdd1   8:49   0    5G  0 part 
└─sdd2   8:50   0    2G  0 part 
sdc      8:32   0  150G  0 disk 
├─sdc1   8:33   0   20G  0 part 
└─sdc2   8:34   0   20G  0 part 
[root@centos6 app]#mkfs.ext4  - L /home /dev/sdb1  ---创建文件系统
[root@centos6 app]#blkid
/dev/sdb1: UUID="d027885d-e32b-42e7-94aa-329130282748" TYPE="ext4" LABEL="/home" 
[root@centos6 app]#mkdir /mnt/sdb1
[root@centos6 app]#mount /dev/sdb1 /mnt/sdb1  ---挂载
[root@centos6 app]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4750888  42953884  10% /
tmpfs             502056      76    501980   1% /dev/shm
/dev/sda3       40185208 1097612  37039596   3% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         6049912 6049912         0 100% /media/CDROM
/dev/sdb1       10194676   23064   9647092   1% /mnt/sdb1
[root@centos6 app]#cd /mnt/sdb1/
[root@centos6 sdb1]#ls
lost+found
[root@centos6 sdb1]#ls -a /home  ---查看home目录下有没有隐藏的目录,如果有隐藏的目录,cp-a复制不过去
.  ..  alice  bash  dufu  gentoo  harry  libai  natasha  nologin  sh  testbash  tom  zhang  zhaoritian
[root@centos6 sdb1]#cp -a /home/* .  ---
[root@centos6 sdb1]#ls
alice  bash  dufu  gentoo  harry  libai  lost+found  natasha  nologin  sh  testbash  tom  zhang  zhaoritian
[root@centos6 sdb1]#init 1  ---切换到单用户模式,避免别人正在使用/home这个目录,切换之前先发个通知告诉大家,此时只能在机器跟前操作,远程已经连接不了
 vim /etc/fstab  ---修改配置文件
UUID=xxx   /home    ext4 defaults 0 0
 备份home
rm -rf /home/*  ---删除家目录里的文件,删除之前要备份
 mount -a   ---自动挂载,此时就可以进入/home,此时目录用的空间是来自/dev/sdb1
umount /mnt/sdb1  ---取消之前的挂载目录
init 3 

2、实现文件系统配额功能

[root@centos6 ~]#vim /etc/fstab 
  1 
  2 #
  3 # /etc/fstab
  4 # Created by anaconda on Fri Jul 14 10:37:59 2017
  5 #
  6 # Accessible filesystems, by reference, are maintained under '/dev/disk'
  7 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
  8 #
  9 UUID=07e3094b-c50d-4568-aee5-b2f76d91c962 /                       ext4    defaults        1 1
 10 UUID=4a2031c3-8595-489e-bc6d-1e2c31860c7b /app                    ext4    defaults        1 2
 11 UUID=a056e3b8-7cc2-4aea-9308-9b0744741394 /boot                   ext4    defaults        1 2
 12 UUID=953b7594-f906-4d3e-8a3a-a6bb79b1c900 swap                    swap    defaults        0 0
 13 UUID=d027885d-e32b-42e7-94aa-329130282748 /home                   ext4    usrquota,grpquota        0 0   ---将default修改
 14 tmpfs                   /dev/shm                tmpfs   defaults        0 0
 15 devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
 16 sysfs                   /sys                    sysfs   defaults        0 0
 17 proc                    /proc                   proc    defaults        0 0
~              
[root@centos6 ~]#mount -o remount /home---重新挂载一下,让文件生效
[root@centos6 ~]#mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda3 on /app type ext4 (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /media/CDROM type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)
/dev/sdb1 on /home type ext4 (rw,usrquota,grpquota)  ---挂载成功,已经有usrquota,grpquota两个选项
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
 [root@centos6 ~]#setenforce 0  ---禁用selinux
[root@centos6 ~]#getenforce
Permissive
[root@centos6 ~]#quotacheck -cug /home  ---创建磁盘配合数据库
[root@centos6 home]#ls ---会生成aquota.group  aquota.user 这两个文件
aquota.group  aquota.user  laoma  lost+found  tom  zhang
[root@centos6 ~]#quotaon /home   ---开启磁盘配合数据库
[root@centos6 ~]#quotaon -p /home ---查看是否开启
group quota on /home (/dev/sdb1) is on
user quota on /home (/dev/sdb1) is on
[root@centos6 ~]#edquota zhang  ---编辑这个文件,修改文件系统配合
QQ截图20170809230741.png
[root@centos6 ~]#su - zhang  ---切换张用户
[zhang@centos6 ~]$pwd
/home/zhang
[zhang@centos6 ~]$dd if=/dev/zero of=f1 bs=1M count=80
sdb1: warning, user block quota exceeded. ---警报磁盘配合将超过
80+0 records in
80+0 records out
83886080 bytes (84 MB) copied, 0.119029 s, 705 MB/s
[zhang@centos6 ~]$dd if=/dev/zero of=f1 bs=1M count=105
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.  ---写失败,磁盘限制已经达到
dd: writing `f1': Disk quota exceeded
98+0 records in
97+0 records out
102359040 bytes (102 MB) copied, 0.544066 s, 188 MB/s
[root@centos6 home]#setquota zhang 100000 150000 15  20 /home    ---非交互式的方式创建磁盘配额
[root@centos6 home]#quota zhang  ---查看张用的磁盘配额
Disk quotas for user zhang (uid 500): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdd1      40  100000  150000              13      15      20    
[root@centos6 home]#edquota -p zhang tom  ---复制张的磁盘配额给tom  
[root@centos6 home]#quota tom  ---查看一下,是一样的
Disk quotas for user tom (uid 504): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdd1      32  100000  150000               8      15      20     
对组创建磁盘配额
[root@centos6 home]#edquota -g admins
      1 Disk quotas for group admins (gid 515):
      2   Filesystem                   blocks       soft       hard     inodes     soft     hard
      3   /dev/sdd1                         0         100000  150000          0        0        0
quota -g admins  ---查看组的磁盘配额
repquota /home  ----查看整个目录的磁盘配额

你可能感兴趣的:(8月9日 迁移home到独立分区和实现文件系统配额)