----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
概要
添加硬盘设备 | 添加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]$