参考文档: Linux命令大全

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

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

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


  • 选择磁盘类型


  • 创建新磁盘


  • 设置大小、拆分方式


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


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


  • 重启虚拟机

  • fdisk观察硬盘实体使用情况
  1. [root@node3 ~]# fdisk -l
  2. Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors
  3. Units = sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disk label type: dos
  7. Disk identifier: 0x000bd826
  8. Device Boot Start End Blocks Id System
  9. /dev/sda1 * 2048 2099199 1048576 83 Linux
  10. /dev/sda2 2099200 1048575999 523238400 8e Linux LVM
  11. //新加的磁盘(100G)
  12. Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
  13. Units = sectors of 1 * 512 = 512 bytes
  14. Sector size (logical/physical): 512 bytes / 512 bytes
  15. I/O size (minimum/optimal): 512 bytes / 512 bytes
  16. Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
  17. Units = sectors of 1 * 512 = 512 bytes
  18. Sector size (logical/physical): 512 bytes / 512 bytes
  19. I/O size (minimum/optimal): 512 bytes / 512 bytes
  20. Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
  21. Units = sectors of 1 * 512 = 512 bytes
  22. Sector size (logical/physical): 512 bytes / 512 bytes
  23. I/O size (minimum/optimal): 512 bytes / 512 bytes
  24. Disk /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 sectors
  25. Units = sectors of 1 * 512 = 512 bytes
  26. Sector size (logical/physical): 512 bytes / 512 bytes
  27. I/O size (minimum/optimal): 512 bytes / 512 bytes

  • 选择要进行操作的磁盘
  1. [root@node3 ~]# fdisk /dev/sdb
  2. Welcome to fdisk (util-linux 2.23.2).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Device does not contain a recognized partition table
  6. Building a new DOS disklabel with disk identifier 0x2890866a.

  • 输入m列出可以执行的命令:
  1. command (m for help): m
  2. Command action
  3. a toggle a bootable flag
  4. b edit bsd disklabel
  5. c toggle the dos compatibility flag
  6. d delete a partition //删除现有分区
  7. l list known partition types
  8. m print this menu
  9. n add a new partition //添加新的分区
  10. o create a new empty DOS partition table
  11. p print the partition table //查看分区情况
  12. q quit without saving changes
  13. s create a new empty Sun disklabel
  14. t change a partition's system id
  15. u change display/entry units
  16. v verify the partition table
  17. w write table to disk and exit
  18. x extra functionality (experts only)

  • 输入p列出磁盘目前的分区情况 (如果是新的磁盘 忽略步骤)
  1. Command (m for help): p
  2. Disk /dev/sdb: 3221 MB, 3221225472 bytes
  3. 255 heads, 63 sectors/track, 391 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sdb1 1 1 8001 8e Linux LVM
  7. /dev/sdb2 2 26 200812+ 83 Linux
  • 删除现有分区
  1. Command (m for help): d
  2. Partition number (1-4): 1
  3. Command (m for help): d
  4. Selected partition 2

  • 确认分区已经删除
  1. Command (m for help): p
  2. Disk /dev/sdb: 3221 MB, 3221225472 bytes
  3. 255 heads, 63 sectors/track, 391 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. Command (m for help):

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

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

  • 查看扩展分区
  1. Command (m for help): p
  2. Disk /dev/sdb: 3221 MB, 3221225472 bytes
  3. 255 heads, 63 sectors/track, 391 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sdb1 1 100 803218+ 83 Linux
  7. /dev/sdb2 101 125 200812+ 83 Linux
  8. /dev/sdb3 126 391 2136645 5 Extended

  • 扩展分区上建立逻辑分区
  1. Command (m for help): n
  2. Command action
  3. l logical (5 or over)
  4. p primary partition (1-4)
  5. l //选择逻辑分区
  6. First cylinder (126-391, default 126):
  7. Using default value 126
  8. Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M
  9. Command (m for help): n
  10. Command action
  11. l logical (5 or over)
  12. p primary partition (1-4)
  13. l
  14. First cylinder (176-391, default 176):
  15. Using default value 176
  16. Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
  17. Using default value 391

  • 查看当前分区情况
  1. Command (m for help): p
  2. Disk /dev/sdb: 3221 MB, 3221225472 bytes
  3. 255 heads, 63 sectors/track, 391 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sdb1 1 100 803218+ 83 Linux
  7. /dev/sdb2 101 125 200812+ 83 Linux
  8. /dev/sdb3 126 391 2136645 5 Extended
  9. /dev/sdb5 126 175 401593+ 83 Linux
  10. /dev/sdb6 176 391 1734988+ 83 Linux
  11. Command (m for help):

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

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


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

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


  • fdisk 查看硬盘分区情况
  1. [root@node3 ~]# fdisk -l
  2. Disk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 sectors
  3. Units = sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disk label type: dos
  7. Disk identifier: 0x000bd826
  8. Device Boot Start End Blocks Id System
  9. /dev/sda1 * 2048 2099199 1048576 83 Linux
  10. /dev/sda2 2099200 1048575999 523238400 8e Linux LVM
  11. Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
  12. Units = sectors of 1 * 512 = 512 bytes
  13. Sector size (logical/physical): 512 bytes / 512 bytes
  14. I/O size (minimum/optimal): 512 bytes / 512 bytes
  15. Disk label type: dos
  16. Disk identifier: 0x2890866a
  17. Device Boot Start End Blocks Id System
  18. /dev/sdb1 2048 209715199 104856576 83 Linux //新的分区(sbd1:100G)
  19. Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
  20. Units = sectors of 1 * 512 = 512 bytes
  21. Sector size (logical/physical): 512 bytes / 512 bytes
  22. I/O size (minimum/optimal): 512 bytes / 512 bytes
  23. Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
  24. Units = sectors of 1 * 512 = 512 bytes
  25. Sector size (logical/physical): 512 bytes / 512 bytes
  26. I/O size (minimum/optimal): 512 bytes / 512 bytes
  27. Disk /dev/mapper/centos-home: 480.0 GB, 479954206720 bytes, 937410560 sectors
  28. Units = sectors of 1 * 512 = 512 bytes
  29. Sector size (logical/physical): 512 bytes / 512 bytes
  30. I/O size (minimum/optimal): 512 bytes / 512 bytes

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

  • mkfs -t ext3 /dev/sdb1格式化分区
  1. [root@node3 ~]# mkfs -t ext3 /dev/sdb1
  2. mke2fs 1.42.9 (28-Dec-2013)
  3. Filesystem label=
  4. OS type: Linux
  5. Block size=4096 (log=2)
  6. Fragment size=4096 (log=2)
  7. Stride=0 blocks, Stripe width=0 blocks
  8. 6553600 inodes, 26214144 blocks
  9. 1310707 blocks (5.00%) reserved for the super user
  10. First data block=0
  11. Maximum filesystem blocks=4294967296
  12. 800 block groups
  13. 32768 blocks per group, 32768 fragments per group
  14. 8192 inodes per group
  15. Superblock backups stored on blocks:
  16. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  17. 4096000, 7962624, 11239424, 20480000, 23887872
  18. Allocating group tables: done
  19. Writing inode tables: done
  20. Creating journal (32768 blocks): done
  21. Writing superblocks and filesystem accounting information: done
  • mount /dev/sdb1 /guazai
  1. #/usr/hdp/ 目录要先存在
  2. [root@node3 ~]# mount /dev/sdb1 /usr/hdp/
  • 查看挂载情况
  1. [root@node3 usr]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/centos-root 50G 50G 20K 100% /
  4. devtmpfs 3.8G 0 3.8G 0% /dev
  5. tmpfs 3.9G 0 3.9G 0% /dev/shm
  6. tmpfs 3.9G 12M 3.8G 1% /run
  7. tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
  8. /dev/sda1 1014M 142M 873M 14% /boot
  9. /dev/mapper/centos-home 447G 1018M 446G 1% /home
  10. tmpfs 781M 0 781M 0% /run/user/0
  11. /dev/sdb1 99G 60M 94G 1% /usr/hdp //挂载成功
  • 取消挂载
  1. [root@node3 /]# umount /dev/sdb1
  2. [root@node3 /]# df -k
  3. Filesystem 1K-blocks Used Available Use% Mounted on
  4. /dev/mapper/centos-root 52403200 52403180 20 100% /
  5. devtmpfs 3983896 0 3983896 0% /dev
  6. tmpfs 3996168 0 3996168 0% /dev/shm
  7. tmpfs 3996168 11992 3984176 1% /run
  8. tmpfs 3996168 0 3996168 0% /sys/fs/cgroup
  9. /dev/sda1 1038336 145260 893076 14% /boot
  10. /dev/mapper/centos-home 468476420 1041428 467434992 1% /home
  11. 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. obj.offsetHeight与obj.style.height $(obj).height()与$(obj).css('height')

    相同:都可以获取obj的高度区别:(1)obj.offsetHeight可以获取外部.内嵌和内联中定义的高,而obj.style.height只能获取内联中定义的高:(2)obj.offsetHeig ...

  2. 兼容ie8的多维数组——深拷贝

    浅拷贝只是把对象的内存位置指针给拷贝了,若修改拷贝对象,则原对象也会跟踪修改. var a = {a : 'old', b : { c : 'old'}} var b = Object.assign( ...

  3. 炼数成金数据分析课程---10、python中如何画图

    炼数成金数据分析课程---10.python中如何画图 一.总结 一句话总结: 主要matplotlib库,pandas中也可以画一些基础图 大纲+实例快速学习法 1.matplotlib的最简单画图 ...

  4. P1493 分梨子

    P1493 分梨子 题目描述 Finley家的院子里有棵梨树,最近收获了许多梨子.于是,Finley决定挑出一些梨子,分给幼稚园的宝宝们.可是梨子大小味道都不太一样,一定要尽量挑选那些差不多的梨子分给 ...

  5. 使用Netfilter进行数据包分析

    #include <linux/init.h>#include <linux/module.h>#include <linux/skbuff.h>#include ...

  6. 2019河北省大学生程序设计竞赛(重现赛)J-舔狗 (拓扑排序)

    题目链接:https://ac.nowcoder.com/acm/contest/903/J 题意:给你 n 个舔狗和他喜欢的人,让你俩俩配对(只能和喜欢它的和它喜欢的),求剩下的单身狗数量. 思路: ...

  7. Quartz特点

    运行环境 Quartz 可以运行嵌入在另一个独立式应用程序 Quartz 可以在应用程序服务器(或servlet容器)内被实例化,并且参与XA事务 Quartz 可以作为一个独立的程序运行(其自己的J ...

  8. 实验报告&总结

    Java实验报告 班级计科二班 学号 20188429 姓名 罗璇哲 完成时间 评分等级 实验三 String类的应用 一. 实验目的 (1) 掌握类String类的使用: (2) 学会使用JDK帮助 ...

  9. Organizing Containers of Balls

    题目 David has several containers, each with a number of balls in it. He has just enough containers to ...

  10. Logic回归总结

    转自http://blog.csdn.net/dongtingzhizi/article/details/15962797 当我第一遍看完台大的机器学习的视频的时候,我以为我理解了逻辑回归,可后来越看 ...