linux系统分区格式化和挂载数据盘的示例分析

发布时间:2021-09-14 18:13 来源:亿速云 阅读:0 作者:柒染 栏目: 服务器 欢迎投稿:712375056

这篇文章给大家介绍linux系统分区格式化和挂载数据盘的示例分析,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

使用【管理终端】,或远程连接工具,输入用户名 root 和密码登录到linux系统。

1、运行fdisk -l命令查看数据盘。在没有分区和格式化数据盘之前,使用 “df –h”命令,是无法看到数据盘的,可以使用“fdisk -l”命令查看。

执行命令后,如果不存在 /dev/vdb,表示没有数据盘。确认数据盘是否已挂载。

2、依次执行以下命令以创建一个单分区数据盘:

(1)运行fdisk -u /dev/vdb:分区数据盘。

(2)输入p:查看数据盘的分区情况。本示例中,数据盘没有分区。

(3)输入n:创建一个新分区。

(4)输入p:选择分区类型为主分区。

说明 本示例中创建一个单分区数据盘,所以只需要创建主分区。如果要创建四个以上分区,您应该创建至少一个扩展分区,即选择 e(extended)。

(5)输入分区编号并按回车键。本示例中,仅创建一个分区,输入1。

(6)输入第一个可用的扇区编号:按回车键采用默认值2048。

(7)输入最后一个扇区编号:本示例仅创建一个分区,按回车键采用默认值。

(8)输入p:查看该数据盘的规划分区情况。

(9)输入w:开始分区,并在分区后退出。

[root@ecshost~ ]# fdisk -u /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 0x3e60020e.
 
Command (m for help): p
Disk /dev/vdb: 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: 0x3e60020e
Device Boot Start End Blocks Id System
 
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):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
 
Command (m for help): p
 
Disk /dev/vdb: 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: 0x3e60020e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

3、运行命令fdisk -lu /dev/vdb 查看新分区。

如果出现以下信息,表示新分区/dev/vdb1创建成功。

[root@ecshost~ ]# fdisk -lu /dev/vdb
 
Disk /dev/vdb: 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: 0x3e60020e
 
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux

4、运行命令mkfs.ext4 /dev/vdb1在新分区上创建一个文件系统。

本示例中,创建一个ext4文件系统。您也可以根据自己的需要,选择创建其他文件系统,例如:如果您需要在 Linux、Windows和Mac系统之间共享文件,可以使用mkfs.vfat创建VFAT文件系统。

说明 创建文件系统所需时间取决于数据盘大小。

[root@ecshost~ ]# mkfs.ext4 /dev/vdb1
 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
 
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

5、(建议)运行命令cp /etc/fstab /etc/fstab.bak备份etc/fstab文件。

6、运行命令echo /dev/vdb1 /data0 ext4 defaults 0 0 >> /etc/fstab向/etc/fstab写入新分区信息。

说明 Ubuntu 12.04系统不支持barrier,您需要运行命令 echo '/dev/vdb1 /data0 ext4 barrier=0 0 0' >> /etc/fstab。

如要把数据盘单独挂载到某个文件夹,例如单独用来存放网页,则将命令中/data0替换成所需的挂载点路径。

7、运行命令cat /etc/fstab查看/etc/fstab中的新分区信息。

[root@ecshost~ ]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Dec 12 07:53:08 2018
#
# 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
#
UUID=d67c3b17-255b-4687-be04-f29190d37396 / ext4 defaults 1 1
/dev/vdb1 /mnt ext4 defaults 0 0

8、运行命令mount /dev/vdb1 /data0挂载文件系统。

9、运行命令df -h 查看目前磁盘空间和使用情况。

出现新建文件系统的信息,表示挂载成功。

<div><br class="Apple-interchange-newline">[root@ecshost~ ]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.6G 36G 5% /
devtmpfs 234M 0 234M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 484K 244M 1% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0
/dev/vdb1 20G 45M 19G 1% /mnt</div>
12345678910    [root@ecshost~ ]# df -h Filesystem Size Used Avail Use% Mounted on/dev/vda1 40G 1.6G 36G 5% /devtmpfs 234M 0 234M 0% /devtmpfs 244M 0 244M 0% /dev/shmtmpfs 244M 484K 244M 1% /runtmpfs 244M 0 244M 0% /sys/fs/cgrouptmpfs 49M 0 49M 0% /run/user/0/dev/vdb1 20G 45M 19G 1% /mnt

10、最后 reboot,重启。

免责声明:本站发布的内容(图片、视频和文字)以原创、来自本网站内容采集于网络互联网转载等其它媒体和分享为主,内容观点不代表本网站立场,如侵犯了原作者的版权,请告知一经查实,将立刻删除涉嫌侵权内容,联系我们QQ:712375056,同时欢迎投稿传递力量。