1. 在系统上添加一个新硬盘
[root@centos7 ~]# reboot
2.确认硬盘被系统识别
[root@centos7 ~]# fdisk -l
Disk /dev/sda: 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: 0x000b4721
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
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
3.对新硬盘(/dev/sdb)进行分区
[root@centos7 ~]# 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 0x0519c64f.
Command (m for help):
Command后面输入m可以列出fdisk的子命令,输入n可进行分区;输入的p表示创建主分区;1表示分区号为1的主分区;First sector为分区的起始位置,一般保持默认;Last sector为分区的结束位置,一般保持默认;+8G表示主分区大小为8G
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): +8G
Partition 1 of type Linux and of size 8 GiB is set
Command (m for help):
下面输入的p是将磁盘分区情况打印出来
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: 0x0519c64f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
然后创建第二个分区,然后输入w保存分区:
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (16779264-41943039, default 16779264):
Using default value 16779264
Last sector, +sectors or +size{K,M,G} (16779264-41943039, default 41943039):
Using default value 41943039
Partition 2 of type Linux and of size 12 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: 0x0519c64f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
/dev/sdb2 16779264 41943039 12581888 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos7 ~]# fdisk -l
Disk /dev/sda: 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: 0x000b4721
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
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: 0x0519c64f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
/dev/sdb2 16779264 41943039 12581888 83 Linux
4.创建文件系统
分区完成后,要先在分区上创建文件系统,分区才能用,下面将两个分区格式化为xfs类型的文件系统,如果不指定文件系统类型将默认为ext2文件系统类型
[root@centos7 ~]# mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=524288 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2097152, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@centos7 ~]# mkfs -t xfs /dev/sdb2
meta-data=/dev/sdb2 isize=512 agcount=4, agsize=786368 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=3145472, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
5.挂载分区使用
[root@centos7 ~]# cd
[root@centos7 ~]# cd /mnt/
[root@centos7 mnt]# mkdir sdb1
[root@centos7 mnt]# mkdir sdb2
[root@centos7 mnt]# cd
[root@centos7 ~]# mount /dev/sdb1 /mnt/sdb1
[root@centos7 ~]# mount /dev/sdb2 /mnt/sdb2
[root@centos7 ~]# mount|tail -2
/dev/sdb1 on /mnt/sdb1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdb2 on /mnt/sdb2 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
若需系统重启后自动挂载,需要在/etc/fstab文件中添加:
[root@centos7 ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Aug 13 23:27:51 2019
#
# 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/centos-root / xfs defaults 0 0
UUID=18170546-e5ce-4fd1-9f7a-45df40e45621 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /mnt/sdb1 xfs defaults 0 0
/dev/sdb2 /mnt/sdb2 xfs defaults 0 0
[root@centos7 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 17811456 4092052 13719404 23% /
devtmpfs 996948 0 996948 0% /dev
tmpfs 1014056 0 1014056 0% /dev/shm
tmpfs 1014056 10704 1003352 2% /run
tmpfs 1014056 0 1014056 0% /sys/fs/cgroup
/dev/sda1 1038336 169540 868796 17% /boot
tmpfs 202812 4 202808 1% /run/user/42
tmpfs 202812 24 202788 1% /run/user/0
/dev/sr0 4480476 4480476 0 100% /run/media/root/CentOS 7 x86_64
/dev/sdb1 8378368 32992 8345376 1% /mnt/sdb1
/dev/sdb2 12571648 32992 12538656 1% /mnt/sdb2
这样在/mnt/sdb1和/mnt/sdb2上的操作就是在所添加的硬盘上的操作
6.用户配额限制
根据用户来限制可以使用分区大小,下面我们使用/dev/sdb2对用户test进行设置
[root@centos7 ~]# vi /etc/fstab
[root@centos7 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Aug 13 23:27:51 2019
#
# 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/centos-root / xfs defaults 0 0
UUID=18170546-e5ce-4fd1-9f7a-45df40e45621 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /mnt/sdb1 xfs defaults 0 0
/dev/sdb2 /mnt/sdb2 xfs defaults,usrquota,grpquota 0 0
[root@centos7 ~]# reboot
[root@centos7 ~]# edquota -u test
Disk quotas for user test (uid 1003):
Filesystem blocks soft hard inodes soft hard
/dev/sdb2 0 10000 20000 0 0 0
上面soft设为10000表示test这个用户写入的文件大小超过10M时系统会有提示(xfs文件系统无提示),但还是可以再写入数据的
hard设为20000表示test这个用户写入的文件大小超过20M时将无法写入文件
[root@centos7 ~]# edquota -u test
Disk quotas for user test (uid 1003):
Filesystem blocks soft hard inodes soft hard
/dev/sdb2 0 0 0 0 3 5
上面soft设为3表示test这个用户写入的文件超过3个时系统会有提示(xfs文件系统无提示),但还是可以再写入文件的
hard设为5表示test这个用户写入的文件超过5个将无法写入文件