Centos7 挂载磁盘

小豆苗 1年前 ⋅ 2047 阅读

1. 查看已使用的磁盘情况:df -HT
2. 查看所有磁盘:fdisk -l
3. 查看指定磁盘的分区情况:fdisk -l /dev/vdb
4. 对显示的该磁盘进行格式化分区
对磁盘进行分区:fdisk /dev/vdb(此处只分成1个区)
依次输入 m -> n -> p -> 1 -> 回车 -> 回车 -> w
---------------------------------------------------------------
[root@VM_0_14_centos ~]# fdisk /dev/vdb
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 0x90e414aa.

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-314572799, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-314572799, default 314572799):
Using default value 314572799
Partition 1 of type Linux and of size 150 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


5. 查看刚刚分配的磁盘号:fdisk -l
6. 格式化磁盘:mkfs -t ext4 /dev/xvdb1
-t 表示指定格式化磁盘的文件系统类型为ext4,默认不指定为ext2(比较老的linux文件系统类型)centos7默认系统格式是xfs格式,格式化磁盘的时候也可以指定类型为xfs格式;
7. 挂载磁盘,将/dev/xvdb磁盘挂载(mount)到文件系统的/data目录上
创建磁盘挂载目标文件夹:mkdir -p /data/fdisks
挂载磁盘:mount /dev/xvdb1 /data/fdisks

8. 此时即可看到新挂载上的磁盘以及文件系统类型ext4
设置开机启动自动挂载磁盘分区
编辑/etc/fstab文件(防止系统重启后挂载丢失)
/etc/fstab是在开机引导的时候自动挂载到linux的文件系统。
编辑该文件,添加如下内容

#new fdisk mounts
/dev/vdb1 /data/szdev ext4 defaults 0 0

9. 重启系统:reboot


全部评论: 0

    我有话说: