1.查看块设备信息
[root@centos7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 4G 0 part [SWAP]
├─sda6 8:6 0 1G 0 part
└─sda7 8:7 0 2G 0 part
sdb 8:16 0 200G 0 disk
sdc 8:32 0 20G 0 disk
sdd 8:48 0 10G 0 disk
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom
以下将在sdb磁盘作为操作目标
- 在sdb磁盘上创建大小为2G的分区
[root@centos7 ~]#fdisk /dev/sdd
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 0x87a3f767.
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):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
- 在sdd2分区上创建文件系统
[root@centos7 ~]#mkfs.ext4 -b 2048 -m 1 -L TEST /dev/sdd1
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/sda1: UUID="793af41e-2bb7-4c31-9f0f-571251920f22" TYPE="xfs"
/dev/sda2: UUID="5e9ce9bf-255f-4fc9-8ec1-2ca462b11486" TYPE="xfs"
/dev/sda3: UUID="4366d641-77fb-4f52-8115-250792bbdf64" TYPE="xfs"
/dev/sda5: UUID="17b04a6b-f52d-4407-91d8-ca6052b65974" TYPE="swap"
/dev/sda6: LABEL="/mnt/sda6" UUID="137e7f1f-126b-430d-8379-1303dc8b4482" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda7: UUID="cbd2ed35-eeaa-40d4-8244-bce465365808" TYPE="ext4"
/dev/sdd1: LABEL="TEST" UUID="8895b7eb-ed2f-41c6-9ff2-2878b1355d1b" TYPE="ext4"
- 将分区挂载到指定文件夹
在/etc/fstab文件中添加以下内容
UUID=8895b7eb-ed2f-41c6-9ff2-2878b1355d1b /test ext4 acl 0 0
- 创建目标文件夹,使配置文件生效
[root@centos7 ~]#mkdir /test
[root@centos7 ~]#mount -a
- 最终,查看结果如下:
[root@centos7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 4G 0 part [SWAP]
├─sda6 8:6 0 1G 0 part
└─sda7 8:7 0 2G 0 part
sdb 8:16 0 200G 0 disk
sdc 8:32 0 20G 0 disk
sdd 8:48 0 10G 0 disk
└─sdd1 8:49 0 2G 0 part /test
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom