在虚拟机配置中增加磁盘后,启动Linux,使用root登录。

首先查看未分区的磁盘,使用下面命令:

## 查看未使用的磁盘
fdisk -l

磁盘/dev/sdb后面没有任何分区,是新挂载的磁盘

输入下面命令来开始对磁盘/dev/sdb进行分区

## 开始格式化磁盘 ##
fdisk /dev/sdb

有如下提示:

[root@localhost dev]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.). Changes will remain in memory only, until you decide to write them.
Be careful before using the write command. 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)

首选使用n来创建一个扩展分区,输入选项n:

Command (m for help): n
Partition type:
p primary ( primary, extended, free)
e extended
Select (default p):

选择创建扩展分区,输入选项e,然后选择扩展分区编号、起始位置和大小,我们选择整个磁盘只创建一个扩展分区:

Select (default p): e
Partition number (-, default ):
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value
Partition of type Extended and of size GiB is set

扩展分区创建好后,可以在此基础上进行创建逻辑分区,我们创建2个逻辑分区并分别设置为10G:

Command (m for help): n
Partition type:
p primary ( primary, extended, free)
l logical (numbered from )
Select (default p): l
Adding logical partition
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ): +10G
Partition of type Linux and of size GiB is set Command (m for help): n
Partition type:
p primary ( primary, extended, free)
l logical (numbered from )
Select (default p): l
Adding logical partition
First sector (-, default ):
Using default value
Last sector, +sectors or +size{K,M,G} (-, default ):
Using default value
Partition of type Linux and of size GiB is set

最后使用选项p来查看分好的分区:

Command (m for help): p

Disk /dev/sdb: 21.5 GB,  bytes,  sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x40e44e64 Device Boot Start End Blocks Id System
/dev/sdb1 Extended
/dev/sdb5 Linux
/dev/sdb6 Linux

为磁盘分配好分区后,需要使用选项w来进行保存:

Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

在执行partprobe命令来重新读取分区信息,如果有警告可以忽略。

## 重新读取分区信息 ##
partprobe

然后需要对磁盘进行格式化,使用mkfs将磁盘格式化为ext4格式(注意扩展分区不能进行格式化)

mkfs -t ext4 /dev/sdb5

mke2fs 1.42. (-Dec-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done

然后我们创建两个目录来挂载这两个逻辑分区:

## 然后创建目录 ##
mkdir /disk5 /disk6 ## 使用mount命令来挂载目录 ##
mount /dev/sdb5 /disk5
mount /dev/sdb6 /disk6

最后使用mount命令来查看挂载情况

[root@localhost dev]# ## 使用mount命令来查看挂载情况 ##
[root@localhost dev]# mount | grep "sdb"
/dev/sdb5 on /disk5 type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb6 on /disk6 type ext4 (rw,relatime,seclabel,data=ordered)

对VM挂载新加入的磁盘的更多相关文章

  1. CentOS 7 环境下挂载新磁盘

    最近某个项目需要给数据库服务器添加磁盘,由于太久没搞过,就给虚拟机加了10G的空间,用来练习一下磁盘的挂载 一. 首先执行"fdisk -l"命令,查看磁盘信息 [root@loc ...

  2. centos7挂载新加4T硬盘到/home目录

    以下操作均在root环境下运行. 1.查看硬盘 # fdisk -l 发现硬盘为/dev/sdb 大小4T 2.如果此硬盘以前有过分区,则先对磁盘格式化: # mkfs -t ext4 /dev/sd ...

  3. CentOS创建管理LVM分区(挂载新分区)

    来源: CentOS 8.0 创建管理LVM分区(挂载新分区) https://www.iwmyx.cn/centos80cjgllvmfa.html 1.查看可用磁盘 fdisk -l 2.新盘(/ ...

  4. Linux 分区扩容(根分区扩容,SWAP 分区扩容,挂载新分区为目录)

    请访问原文链接:https://sysin.org/blog/linux-partition-expansion/,查看最新版.原创作品,转载请保留出处. 作者:gc(at)sysin.org,主页: ...

  5. linux挂载新硬盘并进行分区格式化

    最近要给小伙伴们写几篇文章,关于<linux下误删除文件之后该如何恢复>.对于没有进程占用的文件想要进行数据恢复,不同的文件系统格式需要使用不同的工具,比如:ext4.xfs等.我找遍了我 ...

  6. centos6.4 挂载新盘并移动mysql数据目录

    1 centos 挂载新盘并格式化 以vmware workstation12 中安装的centos6. 虚拟机为例进行演示 关机,添加硬盘 开机,格式化硬盘,并挂载 通过命令查看硬盘 fdisk – ...

  7. Linux 阿里云挂载新分区

    阿里云服务器可以自己购买数据盘并挂载使用,虽然官方也提供了挂载的教程,但是还是有些朋友不清楚其中的细节,为此,我在这里来给大家分享一下详细的挂载办法. 工具/原料 已经购买开通阿里云服务器,并且在开通 ...

  8. CentOS挂载新硬盘

    1.查看当前硬盘使用状况: df -h root@VM_160_34_centos:~> df -h Filesystem Size Used Avail Use% Mounted on /de ...

  9. 【转】linux挂载新硬盘,开机自动挂载

    [转]linux挂载新硬盘,开机自动挂载 ※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※ Linux的硬盘识别: 2.6 kernel以后,linux会将 ...

随机推荐

  1. no 'object' file generated

    c++编译的时候出现如下的错误: no 'object' file generated   [解决方法] Go to project properties -> configurations p ...

  2. dubbo properties

    DUBBO配置项的优先级: java -D优先于 Spring配置,Spring配置优先于 properties文件的配置,这也符合一般项目的规则. 覆盖策略: JVM启动-D参数优先,这样可以使用户 ...

  3. cef3 获得 谷歌浏览器 网页源码 哈哈

    Get HTML Source from Chromium Embedded http://stackoverflow.com/questions/13324095/get-html-source-f ...

  4. cognos函数学习

    1.aggregate(currentMeasure within set set([意健险], [财产险], [车险])) 汇总所有 2.tuple([保费],[车险]) 3.percentage( ...

  5. C. Santa Claus and Robot 思考题

    http://codeforces.com/contest/752/problem/C 这题的意思其实就是叫你固定x个点,使得按顺序走这x个点后,产生的轨迹是给定的序列. 对于有若干条最短路径走到第i ...

  6. 修正下载链接的树莓派Flash教程(前置:Chromium浏览器)

    前端时间想在网上搜罗一下树莓派安装Flash的教程,结果到下载插件那里wget总是死活下载不了,后面发现原链接已经404了,在Bing搜索了一番之后发现Flash播放器的网址已经改了.首先安装Chro ...

  7. 千人基因组计划数据库下载某段区域SNP

    进入http://browser.1000genomes.org/index.html网站 假定要寻找“6:133098746-133108745”这段距离的SNP数据,“6”表示6号染色体,后面的数 ...

  8. Search and Replace

    function myReplace(str, before, after) { //return str; if(before[0] === before[0].toUpperCase()){ af ...

  9. 如何在spark中读写cassandra数据 ---- 分布式计算框架spark学习之六

    由于预处理的数据都存储在cassandra里面,所以想要用spark进行数据分析的话,需要读取cassandra数据,并把分析结果也一并存回到cassandra:因此需要研究一下spark如何读写ca ...

  10. VC++6.0 Debug单步调试

    相信大家对谭浩强童鞋都不陌生,想当年,是他 引领我们步入了C的殿堂,我们从他那里学会了如何写代码,他却没有教我们如何Debug,而我们伟大的老师,也对此只字不提.相信很少有人可以一次性写出 完全正确的 ...