磁盘分区与挂载是Linux使用过程之中比较基础的部分
创建分区
[root@7-64-test ~]# 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: 0x000c145a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 41943039 20663296 8e Linux LVM
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 /dev/mapper/centos-root: 17.9 GB, 17930649600 bytes, 35020800 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 /dev/mapper/centos-swap: 3221 MB, 3221225472 bytes, 6291456 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
[root@7-64-test ~]# fdisk -l /dev/sdb //查看新增的磁盘
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
[root@7-64-test ~]# 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 0x1bdd0658.
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x1bdd0658
Device Boot Start End Blocks Id System
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): g //创建gpt磁盘
Building a new GPT disklabel (GUID: 26965E7C-1CD5-4EB3-B1F4-DE7E5B896224)
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: gpt
Disk identifier: 26965E7C-1CD5-4EB3-B1F4-DE7E5B896224
# Start End Size Type Name
Command (m for help): n //新建分区
Partition number (1-128, default 1):
First sector (2048-2097118, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-2097118, default 2097118): +100M
Created partition 1
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: gpt
Disk identifier: 26965E7C-1CD5-4EB3-B1F4-DE7E5B896224
# Start End Size Type Name
1 2048 206847 100M Linux filesyste
Command (m for help): w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
格式化新增的分区
[root@7-64-test ~]# mkfs.xfs /dev/sdb1 //格式化新建的分区
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@7-64-test ~]# partprobe //无需重启加载分区信息
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. //这个警告无关紧要
挂载新建的分区
[root@7-64-test ~]# mount /dev/sdb1 /root/test_mnt/ //挂载新建的分区
写入测试数据并查看挂载情况
[root@7-64-test ~]# dd if=/dev/zero of=/root/test_mnt/test.txt bs=1M count=40 //写入测试的数据
40+0 records in
40+0 records out
41943040 bytes (42 MB) copied, 0.0232881 s, 1.8 GB/s
[root@7-64-test ~]# df -Th //查看挂载情况
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.7M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 2.6G 15G 16% /
/dev/sda1 xfs 297M 120M 178M 41% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 xfs 97M 46M 52M 47% /root/test_mnt
[root@7-64-test ~]# du -sh /root/test_mnt/ //查询挂载点使用情况
40M /root/test_mnt/
转载请标明出处。