在虚拟机配置中增加磁盘后,启动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. 第19章 queue队列容器

    /* 第19章 queue队列容器 19.1 queue技术原理 19.2 queue应用基础 19.3 本章小结 */ // 第19章 queue队列容器 // 19.1 queue技术原理 // ...

  2. System.DateTime.Now的内容

    ?System.DateTime.Now{2016/10/09 15:19:12}    Date: {2016/10/09 0:00:00}    dateData: 985948826838121 ...

  3. SQL语句调优 - 统计信息的含义与作用及维护计算

    统计信息的含义与作用                                                                                          ...

  4. Web开发新时代

    Web1.0===主流技术:HTML+CSS Web2.0===主流技术:Ajax(Javascript/DOM/异步数据请求) Web3.0===主流技术:HTML5+CSS3 HTML5亮点:Ca ...

  5. poj 2987 最大权闭合图

    Language: Default Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 8744   Accept ...

  6. java基础九[网络与线程](阅读Head First Java记录)

    网络socket连接 Java API的网络功能包(java.net)已经将底层的TCP连接等都封装好了,我们只需要通过Socket对象来建立客户端和服务器的连接,然后客户端能向服务器发送请求,并接收 ...

  7. Android-Junit-Report测试报告生成——Android自动化测试学习历程

    视频地址: http://www.chuanke.com/v1983382-135467-384869.html 这个内容其实已经在用了,我在上一篇文章robotium—只有apk文件的测试中已经讲过 ...

  8. MySQL-->基础-->001-->MySQL基本操作

    一.MySQL安装 卸载mysql 第一步 sudo apt-get autoremove --purge mysql-server-5.0 sudo apt-get remove mysql-ser ...

  9. 第九章 springboot + mybatis + 多数据源 (AOP实现)

    在第八章 springboot + mybatis + 多数据源代码的基础上,做两点修改 1.ShopDao package com.xxx.firstboot.dao; import org.spr ...

  10. Practice:输入年月日,判断该时间为一年的第几天

    #-*- coding:utf- -*- ''' Created on -- # 输入年月日,判断为一年的第几天 @author: AdministrInputator ''' def leapYea ...