----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

概要

  添加硬盘设备 添加swap 磁盘容量配额
1 ls /dev/sd* ls /dev/sd*

vim /etc/fstab:

UUID=88dbdde5-3cdd-4037-ac30-cb9e9436b1f6 /boot                   xfs     defaults,uquota        1 2

2 fdisk /dev/sdb  #p主,e扩展,l逻辑 fdisk /dev/sdb mounut | grep boot
3 file /dev/sdb1 file /dev/sdb2 xfs_quota -x -c 'limit isoft=2 ihard=3 bsoft=2m bhard=3m zhxu' /boot
4 partprobe partprobe edquota -u zhxu
5 mkfs.xfs /dev/sdb1 或者 mkfs.ext4 /dev/sdb1 mkswap /dev/sdb2  
6 mount /dev/sdb1 disk2/ swapon /dev/sdb2  
7 dh -f free -m  
8 vim /etc/fstab vim /etc/fstab  

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

详解

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

新硬盘使用:

分区-》格式化-》挂载(永久生效,包括重启)

1,关闭虚拟机,添加新硬盘,开机。

[root@localhost Desktop]# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb
[root@localhost Desktop]#

2,分区:

[root@localhost Desktop]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x662c491a.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition  #删除分区
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition  #新建分区
   o   create a new empty DOS partition table
   p   print the partition table  #列出现有分区
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit  #写入并退出
   x   extra functionality (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x662c491a

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost Desktop]# ls -l /dev/sdb*
brw-rw----. 1 root disk 8, 16 Nov 13 22:27 /dev/sdb
brw-rw----. 1 root disk 8, 17 Nov 13 22:27 /dev/sdb1  #新建分区
[root@localhost Desktop]#

3,格式化:

[root@localhost Desktop]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost Desktop]#

 4,挂载:

4.1,#永久挂载

[root@localhost zhxu]# vim /etc/fstab  #设备文件挂载定义文件
 
1
  2 #
  3 # /etc/fstab
  4 # Created by anaconda on Fri Nov  2 09:20:16 2018
  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 /dev/mapper/rhel-root   /                       xfs     defaults        1 1
 10 UUID=88dbdde5-3cdd-4037-ac30-cb9e9436b1f6 /boot                   xfs     defaults        1 2
 11 /dev/mapper/rhel-swap   swap                    swap    defaults        0 0
 12 # /dev/sdb1             /media/usb              xfs     defaults        0 0
 13 #add by Xu
 14 /dev/sdb1               /home/zhxu/disk2        ext4    defaults        0 0

[root@localhost zhxu]# reboot  #reboot来验证设置是否成功
[root@localhost Desktop]# df -h  #检查是否依然有效
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   18G  3.0G   15G  17% /
devtmpfs               985M     0  985M   0% /dev
tmpfs                  994M  148K  994M   1% /dev/shm
tmpfs                  994M  8.9M  986M   1% /run
tmpfs                  994M     0  994M   0% /sys/fs/cgroup
/dev/sdb1              4.8G   20M  4.6G   1% /home/zhxu/disk2
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/zhxu/RHEL-7.0 Server.x86_64
[root@localhost Desktop]#

4.2,#临时挂载

[root@localhost zhxu]# mount /dev/sdb1 /home/zhxu/disk2/
[root@localhost zhxu]# df -h  #查看挂载情况
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   18G  3.0G   15G  17% /
devtmpfs               985M     0  985M   0% /dev
tmpfs                  994M  148K  994M   1% /dev/shm
tmpfs                  994M  8.9M  986M   1% /run
tmpfs                  994M     0  994M   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/zhxu/RHEL-7.0 Server.x86_64
/dev/sdb1              4.8G   20M  4.6G   1% /home/zhxu/disk2
[root@localhost zhxu]#

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

增加swap

1,交换分区

[root@localhost Desktop]# free -m  #查看现有交换区大小
             total       used       free     shared    buffers     cached
Mem:          1987        965       1022         10          0        301
-/+ buffers/cache:        663       1324
Swap:         2047          0       2047
[root@localhost Desktop]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x662c491a

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e  #新建扩展分区
Partition number (2-4, default 2): 2
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +10G   
Partition 2 of type Extended and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x662c491a

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    31459327    10485760    5  Extended

Command (m for help): n  #再新建swap
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l  #逻辑分区
Adding logical partition 5
First sector (10489856-31459327, default 10489856):
Using default value 10489856
Last sector, +sectors or +size{K,M,G} (10489856-31459327, default 31459327): 2G
Value out of range.
Last sector, +sectors or +size{K,M,G} (10489856-31459327, default 31459327): +2G
Partition 5 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x662c491a

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    31459327    10485760    5  Extended
/dev/sdb5        10489856    14684159     2097152   83  Linux

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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost Desktop]# ls -l /dev/sdb*  #检查是否有逻辑分区/dev/sdb5,结果没有
brw-rw----. 1 root disk 8, 16 Nov 13 23:04 /dev/sdb
brw-rw----. 1 root disk 8, 17 Nov 13 22:43 /dev/sdb1
[root@localhost Desktop]# [root@localhost Desktop]# partprobe  

#同步,partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@localhost Desktop]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@localhost Desktop]#
[root@localhost Desktop]#
[root@localhost Desktop]# ls -l /dev/sdb*  #再次检查,结果:出现。
brw-rw----. 1 root disk 8, 16 Nov 13 23:09 /dev/sdb
brw-rw----. 1 root disk 8, 17 Nov 13 22:43 /dev/sdb1
brw-rw----. 1 root disk 8, 18 Nov 13 23:09 /dev/sdb2
brw-rw----. 1 root disk 8, 21 Nov 13 23:09 /dev/sdb5
[root@localhost Desktop]#
如果还是不能出现,可以reboot来解决。

2,格式化

[root@localhost Desktop]# mkswap /dev/sdb5
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=c720ebdd-2ff1-4f4b-a418-527b5cf0535d
[root@localhost Desktop]#

3,挂载swap

3.1,#临时挂载
[root@localhost Desktop]# swapo
swapoff  swapon   
[root@localhost Desktop]# swapon /dev/sdb5
[root@localhost Desktop]#
[root@localhost Desktop]# free -m
             total       used       free     shared    buffers     cached
Mem:          1987        973       1014         10          2        303
-/+ buffers/cache:        667       1320
Swap:         4095          0       4095  #已经增加
[root@localhost Desktop]#

3.2,#永久挂载

[root@localhost Desktop]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Nov  2 09:20:16 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root   /                       xfs     defaults        1 1
UUID=88dbdde5-3cdd-4037-ac30-cb9e9436b1f6 /boot                   xfs     defaults        1 2
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
# /dev/sdb1             /media/usb              xfs     defaults        0 0
#add by Xu
/dev/sdb1               /home/zhxu/disk2        ext4    defaults        0 0
/dev/sdb5               swap                    swap    defaults        0 0
~

重启去验证是否设置成功。

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

磁盘配额

个数 inode, 大小 block

软限制 isoft bsoft 警告

硬限制 ihard bhard 直接拒绝

1,#编辑fstab文件,添加uquota来使支持磁盘配额功能

[root@localhost Desktop]# vim /etc/fstab  

#
# /etc/fstab
# Created by anaconda on Fri Nov  2 09:20:16 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root   /                       xfs     defaults        1 1
UUID=88dbdde5-3cdd-4037-ac30-cb9e9436b1f6 /boot                   xfs     defaults,uquota        1 2
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
# /dev/sdb1             /media/usb              xfs     defaults        0 0
#add by Xu
/dev/sdb1               /home/zhxu/disk2        ext4    defaults        0 0
/dev/sdb5               swap                    swap    defaults        0 0
~

2,reboot

3,验证是否支持quota

[root@localhost Desktop]# mount | grep boot
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)

4,设置quota

[root@localhost Desktop]# xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 zhxu' /boot
[root@localhost Desktop]#

 5,验证

[root@localhost Desktop]# chmod -Rf 777 /boot/
[root@localhost Desktop]# ls -ld /boot/
drwxrwxrwx. 3 root root 4096 Nov  2 09:43 /boot/
[root@localhost Desktop]# su - zhxu
Last login: Tue Nov 13 23:49:40 CST 2018 on pts/0
[zhxu@localhost ~]$
[zhxu@localhost ~]$ cd /boot/
5.1, 验证个数配额
[zhxu@localhost boot]$ touch a b c d e f  #新建6个文件,达到配额
[zhxu@localhost boot]$ ls
a                             f                                                        symvers-3.10.0-123.el7.x86_64.gz
b                             grub2                                                    System.map-3.10.0-123.el7.x86_64
c                             initramfs-0-rescue-2ccd4241f6e5443e9ddae8584c94d73a.img  vmlinuz-0-rescue-2ccd4241f6e5443e9ddae8584c94d73a
config-3.10.0-123.el7.x86_64  initramfs-3.10.0-123.el7.x86_64.img                      vmlinuz-3.10.0-123.el7.x86_64
d                             initramfs-3.10.0-123.el7.x86_64kdump.img
e                             initrd-plymouth.img
[zhxu@localhost boot]$ touch g
touch: cannot touch ‘g’: Disk quota exceeded  #数目已经达到6个,禁止新建第7个。
[zhxu@localhost boot]$
5.2,验证大小配额

[zhxu@localhost boot]$ rm a b c d e f
[zhxu@localhost boot]$ ls
config-3.10.0-123.el7.x86_64                             initrd-plymouth.img
grub2                                                    symvers-3.10.0-123.el7.x86_64.gz
initramfs-0-rescue-2ccd4241f6e5443e9ddae8584c94d73a.img  System.map-3.10.0-123.el7.x86_64
initramfs-3.10.0-123.el7.x86_64.img                      vmlinuz-0-rescue-2ccd4241f6e5443e9ddae8584c94d73a
initramfs-3.10.0-123.el7.x86_64kdump.img                 vmlinuz-3.10.0-123.el7.x86_64
[zhxu@localhost boot]$ dd if=/dev/zero of=g bs=3M count=1
1+0 records in
1+0 records out
3145728 bytes (3.1 MB) copied, 0.00423943 s, 742 MB/s
[zhxu@localhost boot]$ dd if=/dev/zero of=g bs=7M count=1  #大于配额6M时,只能写入最大值文件。
dd: error writing ‘g’: Disk quota exceeded
1+0 records in
0+0 records out
6291456 bytes (6.3 MB) copied, 0.0116008 s, 542 MB/s
[zhxu@localhost boot]$

6,修改

[zhxu@localhost boot]$ edquota -u zhxu

Disk quotas for user zhxu (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sda1                      6144       3072       6144          1        3        6  #修改限制值,不能修改已经使用的6144或者1

---

Disk quotas for user zhxu (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sda1                      6144       3072       10240          1        3        6  #从6M修改为10M
---

[root@localhost boot]# exit
[zhxu@localhost boot]$ dd if=/dev/zero of=g bs=8M count=1  #ok
1+0 records in
1+0 records out
8388608 bytes (8.4 MB) copied, 0.23644 s, 35.5 MB/s
[zhxu@localhost boot]$

转载于:https://www.cnblogs.com/zhxu/p/9954592.html

Linux_8/ fdisk, xfs_quota, edquota相关推荐

  1. Linux磁盘分区(fdisk)及磁盘限额(quota)

    Linux磁盘分区(fdisk)及磁盘限额(quota) 学校组织大家参加程序设计大赛,为此成立了以你为组长的项目组,同时小组内还有其他3名成员.因磁盘空间不够,做为组长的你争取到了10GB的磁盘空间 ...

  2. linux df是否分区,Linux中df命令查询磁盘信息和fdisk命令分区的用法

    df - 报告文件系统磁盘空间的使用情况 总览 df [option]... [file]... posix 选项: [-kp] gnu 选项 (最短方式): [-ahhiklmpv] [-t fst ...

  3. linux分区_Linux系统 fdisk管理MBR分区

    前言 fdisk是一条以交互的方式进行操作的命令,在菜单中选择相应的功能键即可. 目录 一.添加新硬盘 二.新建分区 三.总结 四.思维导图 一.添加新硬盘 1.为了不影响正在运行的业务,需要在不关闭 ...

  4. linux fdisk 分区、格式化、挂载

    关于硬盘分区:主分区(包含扩展分区).逻辑分区,主分区最多有4个(包含扩展分区). 因此我们在对硬盘分区时最好划分主分区连续,比如说:主分区一.主分区二.扩展分区. 此文章以fdisk工具为例,对一个 ...

  5. df命令、du命令、磁盘分区(fdisk命令)

    df命令 用于查看已挂载磁盘的总容量.使用容量.属于容量:不加参数以kb为单位显示: 实验1: [root@shu-test ~]# df 文件系统 1K-块 已用 可用 已用% 挂载点 /dev/s ...

  6. 实例解说Linux中fdisk分区使用方法

    一.fdisk 的介绍 fdisk - Partition table manipulator for Linux ,译成中文的意思是磁盘分区表操作工具:本人译的不太好,也没有看中文文档:其实就是分区 ...

  7. 采用fdisk在linux进行分区操作

    采用fdisk在linux进行分区操作 在virtualBox中创建一个新的磁盘,登入到系统,执行fdisk -l(需要root权限)来查看磁盘信息. root@mhchen-VirtualBox:~ ...

  8. CentOS下挂载硬盘(fdisk,mkfs.ext4,mount)

    centos挂载硬盘挂载硬盘步骤:1. 先分区 fdisk /dev/sdb-p 查看分区-n 创建分区-p 创建主分区-1 这是分区序号-回车,回车(这里选择扇区起始位置和分区大小,类似:+1G 这 ...

  9. linux 系统基础知识 - fdisk命令

    在 console 上输入 fdisk -l /dev/sda ,观察硬盘之实体使用情形. 在 console 上输入 fdisk /dev/sda,可进入分割硬盘模式. 1. 输入 m 显示所有命令 ...

最新文章

  1. Cocos本地存储LocalStorage
  2. python怎么判断一个文件是否存在-利用Python如何判断一个文件是否存在
  3. AS插件-Android Drawable Importer
  4. 还没毕业就被阿里30万年薪预定,他凭什么?
  5. Ubuntu下动态库与静态库混合连接
  6. 吴恩达|机器学习作业8.1.推荐系统(协同过滤算法)
  7. Vmware安装CentOS7后访问不了外网
  8. Centos7重置Mysql 8.0.1 root 密码
  9. java复制文件拒绝访问权限_关于IO流在复制文件时出现java.io.FileNotFoundException: D:\xxx (拒绝访问。) 拒绝访问的问题...
  10. KunlunBase 产品使用和评测指南
  11. 9个方法,教你用Google Drive做好云端档案管理
  12. 基于天地图热力图及区域划分
  13. 透彻理解神经网络剪枝算法
  14. 74cms骑士人才招聘系统源码SE版 v3.16.0
  15. MAF 项目创建流程
  16. drm debug log with drm.debug=6 debug
  17. 机器学习笔记——数据挖掘与机器学习区别以及课程内容
  18. .CN 根域名被攻击至瘫痪,谁之过?
  19. ansible问题记录--Timeout (12s) waiting for privilege escalation prompt
  20. 如何用中国知网导出参考文献

热门文章

  1. 股票量化交易策略源码 tushare
  2. Optimus Ride选用Velodyne Lidar的开创性传感器为其自动驾驶汽车提供支持
  3. Golang 单引号、双引号和反引号
  4. 怎样在计算机里添加新的打印机地址,网络一体打印机怎么样添加扫描地址
  5. 30岁,程序员,3月无情被毕业
  6. 【正点原子MP157连载】第二十二章 新字符设备驱动实验-摘自【正点原子】STM32MP1嵌入式Linux驱动开发指南V1.7
  7. 俄乌局势再起波澜,3月季节性一览,甲醇认购大涨,CCS05收官LPP季节性下跌2022.2.28
  8. 软件架构:总体设计师
  9. 8月1日云栖精选夜读:独家:阿里巴巴DevOps落地实践玩法及思路解析
  10. 【windows】win11 简体中文版系统下载csv文件打开乱码