fdisk工具使用
[root@centos7 ~]# fdisk -l
#我们的硬盘现在有二个主分区
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x0005b92c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 216025087 106962944 8e Linux LVM
[root@centos7 ~]# fdisk /dev/sda
#开始分区
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): n
#n表示新建分区
#已经有2个主分区了,建立一个扩展分区,将剩余的空间全部给它
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): e
Partition number (3,4, default 3): 3
First sector (216025088-251658239, default 216025088):
Using default value 216025088
Last sector, +sectors or +size{K,M,G} (216025088-251658239, default 251658239):
Using default value 251658239
Partition 3 of type Extended and of size 17 GiB is set
Command (m for help): n
#扩展分区之上需要再建立逻辑分区,才能被格式的奥
Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (216027136-251658239, default 216027136):
Using default value 216027136
Last sector, +sectors or +size{K,M,G} (216027136-251658239, default 251658239): +2G
#给它2G
Partition 5 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x0005b92c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 216025087 106962944 8e Linux LVM
/dev/sda3 216025088 251658239 17816576 5 Extended
/dev/sda5 216027136 220221439 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)
[root@centos7 ~]# fdisk -l /dev/sda
Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x0005b92c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 216025087 106962944 8e Linux LVM
/dev/sda3 216025088 251658239 17816576 5 Extended
/dev/sda5 216027136 220221439 2097152 83 Linux
重要要通知内核更新分区表
[root@centos7 ~]# partprobe /dev/sda
#通知内核更新分区表
[root@centos7 ~]# cat /proc/partitions
#查看分区表是否更新
major minor #blocks name
11 0 3898368 sr0
11 1 10768384 sr1
8 0 125829120 sda
8 1 1048576 sda1
8 2 106962944 sda2
8 3 1 sda3
8 5 2097152 sda5
253 0 52428800 dm-0
253 1 2097152 dm-1
253 2 52428800 dm-2
开始创建文件系统
[root@centos7 ~]# mkfs.ext4 -m1 -L 'test' -b 2048 /dev/sda5
#创建一个ext4的文件系统,预留1%的空间,卷标为test 块大小为2048
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=test
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
10485 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=269484032
64 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos7 ~]# blkid /dev/sda5
#查看分区信息
/dev/sda5: LABEL="test" UUID="a4264acc-0e5f-41b2-a810-d5cce924525a" TYPE="ext4"
实现开机自动挂载
[root@centos7 /]# vim /etc/fstab
#设置开启自动挂载,需要修改配置文件/etc/fstab
#设备名称|UUID ,挂载目录,文件系统类型,挂载选项,是否备份,是否fsck检查
/dev/mapper/centos-root / xfs defaults 0 0
UUID=ca08ca12-f105-4b64-903c-8635d7700c83 /boot xfs defaults
0 0
/dev/mapper/centos-data /data xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sda5 /test ext4 defaults,acl 0 0
"/etc/fstab" 15L, 573C written
[root@centos7 /]# reboot
Last login: Tue Mar 10 22:04:46 2020 from 192.168.44.1
[root@centos7 ~]# blkid
#重启查看是否自动挂载
/dev/mapper/centos-root: UUID="3d67f3d7-10ec-4511-98db-5a087fa2d665" TYPE="xfs"
/dev/sda2: UUID="0j57M1-4EWc-2P2e-Atre-eNQr-VEeB-LXpCsk" TYPE="LVM2_member"
/dev/sr0: UUID="2018-06-29-11-20-20-00" LABEL="CentOS_6.10_Final" TYPE="iso9660" PTTYPE="dos"
/dev/sr1: UUID="2019-09-09-19-08-41-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="ca08ca12-f105-4b64-903c-8635d7700c83" TYPE="xfs"
/dev/sda5: LABEL="test" UUID="a4264acc-0e5f-41b2-a810-d5cce924525a" TYPE="ext4"
/dev/mapper/centos-swap: UUID="65d90e49-9d76-4aac-96bc-baf1a8dda18f" TYPE="swap"
/dev/mapper/centos-data: UUID="5689c9bf-320a-4f8b-ae46-440224a6c99c" TYPE="xfs"
测试facl功能
[root@centos7 test]# setfacl -m u:wang:rw a.txt
#没有王用户所以无法设置
setfacl: Option -m: Invalid argument near character 3
[root@centos7 test]# tail -10 /etc/passwd
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
zouyongbing:x:1000:1000:zouyongbing:/home/zouyongbing:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
saslauth:x:998:76:Saslauthd user:/run/saslauthd:/sbin/nologin
[root@centos7 test]# setfacl -m u:zouyongbing:rw a.txt
#可以看到已经成功设置facl
[root@centos7 test]# getfacl a.txt
# file: a.txt
# owner: root
# group: root
user::rw-
user:zouyongbing:rw-
group::r--
mask::rw-
other::r--