参考文档: Linux命令大全

需求:测试环境虚拟机某个目录下空间不足,准备通过添加一块磁盘,并将该目录挂载到该磁盘

前面几步在测试服务器上操作的,截图困难,所以网上找了几张设置图

  • 关闭虚拟机(没测试过不关闭的情况)
  • 虚拟机中添加一块新的磁盘


  • 选择磁盘类型


  • 创建新磁盘


  • 设置大小、拆分方式


  • 设定文件名(一般默认即可)


  • 确定(一定要确定,不然不会保存的)


  • 重启虚拟机

  • fdisk观察硬盘实体使用情况
[root@node3 ~]# fdisk -l

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x000bd826 Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 1048575999 523238400 8e Linux LVM //新加的磁盘(100G)
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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 /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 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

  • 选择要进行操作的磁盘
[root@node3 ~]# fdisk /dev/sdb
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 0x2890866a.

  • 输入m列出可以执行的命令:
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 //删除现有分区
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)

  • 输入p列出磁盘目前的分区情况 (如果是新的磁盘 忽略步骤)
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System
/dev/sdb1 1 1 8001 8e Linux LVM
/dev/sdb2 2 26 200812+ 83 Linux
  • 删除现有分区
Command (m for help): d
Partition number (1-4): 1 Command (m for help): d
Selected partition 2

  • 确认分区已经删除
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System Command (m for help):

  • 建立新的磁盘分区(两个主磁盘分区)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p //建立主分区
Partition number (1-4): 1 //分区号
First cylinder (1-391, default 1): //分区起始位置
Using default value 1
last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区(磁盘扇区默认是512Byte) Command (m for help): n //再建立一个分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2 //分区号为2
First cylinder (101-391, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M

  • 建一个扩展分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e //选择扩展分区
Partition number (1-4): 3
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391)://剩下的空间都用做扩展分区
Using default value 391

  • 查看扩展分区
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
/dev/sdb3 126 391 2136645 5 Extended

  • 扩展分区上建立逻辑分区
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l //选择逻辑分区
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (176-391, default 176):
Using default value 176
Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
Using default value 391

  • 查看当前分区情况
Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
/dev/sdb3 126 391 2136645 5 Extended
/dev/sdb5 126 175 401593+ 83 Linux
/dev/sdb6 176 391 1734988+ 83 Linux Command (m for help):

从上面的结果我们可以看到,在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6)

注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。


  • 保存分区操作
Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

分区创建方式按照参考文档的操作,但是我并没有创建这么多分区,100G全部创建了主分区即/dev/sdb1


  • fdisk 查看硬盘分区情况
[root@node3 ~]# fdisk -l

Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x000bd826 Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 1048575999 523238400 8e Linux LVM Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x2890866a Device Boot Start End Blocks Id System
/dev/sdb1 2048 209715199 104856576 83 Linux //新的分区(sbd1:100G) Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 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

  • cat /proc/partitions 查看磁盘文件信息
[root@node3 ~]# cat /proc/partitions
major minor #blocks name 8 0 524288000 sda
8 1 1048576 sda1
8 2 523238400 sda2
8 16 104857600 sdb
8 17 104856576 sdb1
11 0 1048575 sr0
253 0 52428800 dm-0
253 1 2097152 dm-1
253 2 468705280 dm-2

  • mkfs -t ext3 /dev/sdb1格式化分区
[root@node3 ~]# mkfs -t ext3 /dev/sdb1
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
6553600 inodes, 26214144 blocks
1310707 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 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, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
  • mount /dev/sdb1 /guazai
#/usr/hdp/  目录要先存在
[root@node3 ~]# mount /dev/sdb1 /usr/hdp/
  • 查看挂载情况
[root@node3 usr]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 50G 20K 100% /
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 12M 3.8G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 1014M 142M 873M 14% /boot
/dev/mapper/centos-home 447G 1018M 446G 1% /home
tmpfs 781M 0 781M 0% /run/user/0
/dev/sdb1 99G 60M 94G 1% /usr/hdp //挂载成功
  • 取消挂载
[root@node3 /]# umount /dev/sdb1
[root@node3 /]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 52403200 52403180 20 100% /
devtmpfs 3983896 0 3983896 0% /dev
tmpfs 3996168 0 3996168 0% /dev/shm
tmpfs 3996168 11992 3984176 1% /run
tmpfs 3996168 0 3996168 0% /sys/fs/cgroup
/dev/sda1 1038336 145260 893076 14% /boot
/dev/mapper/centos-home 468476420 1041428 467434992 1% /home
tmpfs 799236 0 799236 0% /run/user/0

取消挂载成功

还可以用umount /usr/hdp 取消挂载

VMware Workstation 添加磁盘 挂载目录(centos)的更多相关文章

  1. 【图文教程】Vmware Workstation 12虚拟机中安装CentOS 7详细步骤

    文档维护人:牛棚琐思 <viprs@qq.com> ,如有不妥之处,请不吝赐教. 文档目标:帮助新手在Vmware虚拟机软件中安装CentOS 7超详细教程. 目标人群:本篇教程比较简单, ...

  2. 【Hadoop离线基础总结】Mac版VMware Fusion虚拟机磁盘挂载

    步骤概览 1.打开所要挂载磁盘的虚拟机的设置(此时必须关机) 2.打开硬盘设置 3.添加设备 4.选择新硬盘 5.设置如下图 6.将虚拟机开机,输入 df-lh ,查看当前虚拟机磁盘 7.输入 fdi ...

  3. Linux修改磁盘挂载目录

    比如想把已经挂载在home目录上的硬盘挂载到data目录上, 如下操作 #df -h(查看分区情况及数据盘名称) # mkdir /data(如果没有data目录就创建,否则此步跳过) # umoun ...

  4. Vmware Workstation添加centos 7系统网络问题(无IP情况)

    简单配置 命令行输入ip addr 查询不到IP的情况,如下: 解决办法: 1. vi  /etc/sysconfig/network-scripts/ifcfg-ens33 2. 最后一行,ONBO ...

  5. vmware workstation LINUX磁盘扩容

    1.edit virtual machine settings -> 选中硬盘->右侧utilities->expand(虚拟机不能存在镜像),输入要扩容到的大小 2.扩容之后进入系 ...

  6. VMware workstation批量创建虚拟机和自动化安装操作系统(一)

    一. 简述 作为从事IT行业运维工作的Linuxer,大多情况下需要在测试环境中部署业务系统并进行测试,在没有足够的计算存储网络条件下,使用虚拟机进行虚拟集群的创建和使用,是一种不错的学习和实践方式. ...

  7. vmware workstation 上创建的centos 7.2 ,新添加一块网卡。无法找到配置文件。

    在vmware workstation 11上,新建一个centos 7.2系统. 初装带有一个块网卡:能够在/etc/sysconfig/network-scripts/目录下找到相应的网卡配置文件 ...

  8. 不停机为虚拟机添加主机磁盘(以VMware Workstation为例)

    VMware Workstation软件上安装的centos7系统,新增磁盘后使用fdisk -l命令查看不到新增的磁盘,有没有办法在不重启的情况下添加上新磁盘? 有办法 具体如下: # 查看主机总线 ...

  9. CentOS添加磁盘分区

    (这里的磁盘在vmware workstation VM中添加) 1.关闭虚拟机,在虚拟机设置中添加一个硬盘,然后开启虚拟机. 2.使用fdisk -l命令查看,这时会发现一个为被使用的设备,有2G的 ...

随机推荐

  1. NX二次开发-基于NX开发向导模板的NX对Excel读写操作(OLE方式(COM组件))

    在看这个博客前,请读者先去完整看完:NX二次开发-基于MFC界面的NX对Excel读写操作(OLE方式(COM组件))https://ufun-nxopen.blog.csdn.net/article ...

  2. 前台页面中json和字符串相互转化

    比如我有两个变量,我要将a转换成字符串,将b转换成JSON对象: var a={"name":"tom","sex":"男&quo ...

  3. CSS:CSS 伪类(Pseudo-classes)

    ylbtech-CSS:CSS 伪类(Pseudo-classes) 1.返回顶部 1. CSS 伪类(Pseudo-classes) CSS伪类是用来添加一些选择器的特殊效果. 语法 伪类的语法: ...

  4. SAS市场研究应用介绍:组合/联合分析

    SAS市场研究应用介绍:组合/联合分析 一 SAS市场研究模块介绍 市场研究是指研究组织(企业)与客户.公众三者关系的规律的过程,是市场营销领域中的一个重要元素.它把消费者.客户.公众和营销者通过信息 ...

  5. 校验文件是否是同一个文件,以及mac中使用MD5命令

    背景 sz了war包,因为查看不到里面的内容,并不确定是否是同一个文件. 解决 通过MD5校验 md5sum xxxx 但是在mac中是没有这个命令的下载半天没下载下来,下面是快捷操作. 1.打开终端 ...

  6. 【react】---Hooks的基本使用---【巷子】

    一.react-hooks概念 React中一切皆为组件,React中组件分为类组件和函数组件,在React中如果需要记录一个组件的状态的时候,那么这个组件必须是类组件.那么能否让函数组件拥有类组件的 ...

  7. C语言——二维数组

    目录 二维数组 一.二维数组的定义 二.二维数组的初始化 三.通过赋初值定义二维数组的大小 四.二维数组与指针 二维数组 一.二维数组的定义 类型名 数组名[ 常量表达式1 ][ 常量表达式2 ] i ...

  8. 54-Ubuntu-打包压缩-4-bzip2压缩和解压缩介绍

    bzip2 tar和bizp2命令结合可以实现文件打包和压缩 tar只负责打包,但不压缩 用bzip2压缩tar打包后的文件,其扩展名一般为xxx.tar.bz2 在tar命令有一个选项-j可以调用b ...

  9. 2018-2-13-win10-uwp-iot

    title author date CreateTime categories win10 uwp iot lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:2 ...

  10. 安装 Confluence6.7.1 笔记

    安装 Confluence6.7.1 我是使用命令行进入mysql的mysql -uroot -p123456 创建数据库 CREATE DATABASE confluence DEFAULT CHA ...