在虚拟机配置中增加磁盘后,启动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. Centos6.x服务器配置jdk+tomcat+mysql环境

    1,jdk配置 由于jdk官网的链接不直接支持wget,可以使用下面的方法下载jdk,其中jdk版本为jdk1.8.0_91: wget --no-check-certificate --no-coo ...

  2. 自动化(Automation)兼容的数据类型

    自动化(Automation)兼容的数据类型    

  3. javascript generate a guid

    function Guid() { var random = (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); retu ...

  4. [转载] 3. JebAPI 之 jeb.api.ast

    本文转载自: https://www.zybuluo.com/oro-oro/note/143651 0. 序 Jeb 本身是支持变量重命名的,所以,混淆了的变量名.类名可以修改. 实际上,它还可以做 ...

  5. Open Live Writer的配置

    --------siwuxie095 1.首先到官网下载OLW:http://openlivewriter.org/ 2.选择 Other services 3.填写"博客地址". ...

  6. hadoop中master免登录slave

    hadoop集群免登录配置 在主机master上执行如下: 1. $cd ~/.ssh(如果没有此目录,可以手动创建) 2. $ssh-keygen -t rsa  ----------------- ...

  7. 链接,光标,DHTML,缩放

    18.1css中链接的使用超链接伪类属性:a:link 表示该链接文字尚未被点选a:visited 表示该链接文字已被点选过a:active 表示该链接文字正被点选,但未被放开a:hover 表示当鼠 ...

  8. python3中的zip

    在 python2 中zip可以将两个列表并入一个元组列表,如: a = [1,2,3,4] b = [5,6,7,8] c = zip(a,b) 结果:c [(1,5),(2,6),(3,7),(4 ...

  9. c# 线程信号量 Mutex

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. 常用linux指令

    删除:rm -rf -r 就是向下递归,不管有多少级目录,一并删除       -f 就是直接强行删除,不作任何提示的意思 压缩解压:tar -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向 ...