Linux下如何挂载磁盘[通俗易懂]

Linux下如何挂载磁盘[通俗易懂]使用虚拟机时发现磁盘空间不够了,需要挂载一个磁盘以供继续使用,但是磁盘不是添加就可以使用的,还需要进行挂载。一、添加磁盘添加加新硬盘重启服务器添加完之后就可以重启机器了,如果你机器是开启的,进入系统并不能看见你刚添加的那块磁盘,只有等系统重启,重新加载之后才会显示安装的那块磁盘二、进入系统使用root用户进入系统三、查看硬盘信息[root@localhost~]#fdi

大家好,又见面了,我是你们的朋友全栈君。

使用虚拟机时发现磁盘空间不够了,需要挂载一个磁盘以供继续使用,但是磁盘不是添加就可以使用的,还需要进行挂载。

一、添加磁盘

添加加新硬盘重启服务器

添加完之后就可以重启机器了,如果你机器是开启的,进入系统并不能看见你刚添加的那块磁盘,只有等系统重启,重新加载之后才会显示安装的那块磁盘

二、进入系统

使用root用户进入系统

三、 查看硬盘信息

[root@localhost ~]# fdisk -l //磁盘命令
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c4cb5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd0f5c869

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

可以看到这台机器加载了三个磁盘sda、sdb、sdc
其中sda是初始磁盘,sdb已经初始化且经过使用,sdc是刚刚加载的,未格式化的新磁盘

四、创建新硬盘分区

[root@localhost ~]# fdisk /dev/sdc #进入磁盘
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x45a3cadb.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

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  #各分区类型所对应的ID
   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)

知道命令之后就可以进行分区了

Command (m for help): p //打印分区信息,可以看到当前并没有分区

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x45a3cadb

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n //创建一个新的分区
Command action
   e   extended//输入e为创建扩展分区 
   p   primary partition (1-4) //输入p为创建逻辑分区 
p
Partition number (1-4): 1//划分逻辑分区
First cylinder (1-2610, default 1): //我这里直接回车,是不想把该磁盘分成多个分区,把整个磁盘作为1个分区
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): 
Using default value 2610

Command (m for help): p //再次查看可以看到该磁盘已经有1个分区了

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x45a3cadb

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2610    20964793+  83  Linux
Command (m for help): w //保存分区
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

再次使用”fdisk -l”命令查看磁盘信息

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x406a4c58

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        2610    20964793+  83  Linux

第三块磁盘/dev/sdc已经分区好了

五、格式化分区

[root@localhost ~]# mkfs.ext3 /dev/sdc1
//将/dev/sdc1格式化为ext3类型,好像大部分的磁盘都是格式化为ext3类型,具体为什么没有深入研究,暂时不清楚,想了解的朋友可以自己查一下
[root@localhost ~]# mkfs.ext3 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
160 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

正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

格式化完毕,此时就可以使用“mount”命令挂载分区了,然后使用这个磁盘空间了

六、挂载分区以及开机自动挂载

[root@localhost ~]# df -h //此时只有sda1和sdb1两个磁盘挂载
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 15G 1.5G 92% /
tmpfs                         932M   76K  932M   1% /dev/shm
/dev/sda1                     485M   40M  421M   9% /boot
/dev/sdb1                      20G  1.2G   18G   7% /disk/diskone
/dev/sr0                      4.2G  4.2G     0 100% /media/CentOS_6.5_Final
[root@localhost /]# cd /disk/
[root@localhost disk]# ll
总用量 4
drwxr-xr-x. 4 root root 4096 728 17:04 diskone
[root@localhost disk]# cd diskone/
[root@localhost diskone]# ll
总用量 20
drwx------. 2 root root 16384 728 16:12 lost+found
drwxr-xr-x. 2 root root  4096 728 17:09 software
[root@localhost diskone]# cd ../
[root@localhost disk]# mkdir disktwo //创建被挂载的路径
[root@localhost disk]# ll
总用量 8
drwxr-xr-x. 4 root root 4096 728 17:04 diskone
drwxr-xr-x. 2 root root 4096 81 16:48 disktwo
[root@localhost disk]# mount /dev/sdc1 /disk/disktwo/ //进行挂载
[root@localhost disk]# df -h //再次查看,发现sdc1已经挂载在/disk/disktwo路径下
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 15G 1.5G 92% /
tmpfs                         932M   76K  932M   1% /dev/shm
/dev/sda1                     485M   40M  421M   9% /boot
/dev/sdb1                      20G  1.2G   18G   7% /disk/diskone
/dev/sr0                      4.2G  4.2G     0 100% /media/CentOS_6.5_Final
/dev/sdc1                      20G  173M   19G   1% /disk/disktwo

磁盘已经挂载上了
下面设置开机自动挂载
编辑/etc/fstab文件,再最后面添加
/dev/sdc1(磁盘分区) /disk/disktwo(挂载目录) ext3(文件格式)defaults 0 0

vim /etc/fstab
/dev/sdc1(磁盘分区)  /disk/disktwo(挂载目录) ext3(文件格式)defaults  0  0

之后重启就OK啦!!!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/150859.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 哪些属于网页抓取算法_网页排序算法有哪些

    哪些属于网页抓取算法_网页排序算法有哪些如果搜索文档有很多重复的文本,比如一些文档是转载的其他的文档,只是布局不同,那么就需要把重复的文档去掉,一方面节省存储空间,一方面节省搜索时间,当然搜索质量也会提高。simhash是google用来处理海量文本去重的算法。

    2022年9月28日
    1
  • N70常用软件大集合

    N70常用软件大集合管理软件[文件管理]SmartFilemanv1.03汉化版[进程管理]AppManv1.04完美简体中文优化MMC绿色版[文件管理]SystemExplorerv1.8汉化版[程序管理]Fexplorerv1.15完美汉化完全版《N70拨号大字体》+《N70解决opera8.5上网一些地方显示口口的字体》英文机N70用的完美中文字体[压缩工具]解压利器zipman2.

    2022年7月11日
    24
  • XILINX_linux基本命令的使用

    XILINX_linux基本命令的使用petalinux-v2018.2rootfs配置开发用到的常用工具,使能如下选项,FilesystemPackages→base→util-linuxutil-linux-mkfsFilesystemPackages→base→e2fsprogs [*]e2fsprogs []e2fsprogs-dev…

    2025年11月1日
    3
  • 大数据分析应用领域有哪些[通俗易懂]

    大数据分析应用领域有哪些[通俗易懂]  软件和服务的大数据分析市场收入预计将从2018年的$42B增长到2027年的$103B,复合年增长率(CAGR)为10.48%。这就是为什么,大数据分析认证是业内最全神贯注的技能之一。在这个“大数据分析应用领域”文章中,我将带您进入各个行业领域,在这里我将解释大数据分析如何使它们发生革命性变化。  大数据分析应用  大数据分析应用程序的主要目标是通过分析大量数据来帮助公司做出更具信息量的业务决策。它可能包括Web服务器日志,Internet点击流数据,社交媒体内容和活动报告,来自客户电子邮

    2022年5月29日
    41
  • 点云数据格式转换(使用CloudCompare软件)

    点云数据格式转换(使用CloudCompare软件)在网上找了一些点云数据格式的转换方法 突然发现 CloudCompare 软件转换点云数据的格式很方便 所以就记录一下 CloudCompare 软件下载地址 http www cloudcompare org 注 要注意一下 如果你的电脑显卡有点旧 就不要下载最新版的 CloudCompare 11 否则你启动软件的时候可能会报错 解决办法就是下载相对老一点的 CloudCompare 6 版本

    2025年9月15日
    2
  • oj在计算机领域中指什么,【计算机专业论文】计算机专业教学中OJ平台的应用(共2762字)…

    oj在计算机领域中指什么,【计算机专业论文】计算机专业教学中OJ平台的应用(共2762字)…摘要:传统的教学模式对计算机专业学生的能力培养存在着诸多问题,而OJ(OnlineJudge在线检测程序源代码)平台为计算机教学提供了新的思路,因为OJ平台在学生日常训练方面有一套行之有效的机制,所以对学生的学习兴趣、分析解决问题能力、创新能力等方面的培养都起到了积极的推动作用,OJ平台还可以对学生实践能力进行最直接的考核,因此将OJ平台引入计算机专业教学,可实现以平台促教学,以平台促教改。关键词…

    2022年6月16日
    30

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号