详解linux添加硬盘分区挂载教程

 更新时间:2018年04月13日 09:16:52   作者:渣渣辉  
本篇文章主要介绍了详解linux添加硬盘分区挂载教程,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

基本步骤:分区——格式化——挂载——写入文件

1、首先用fdisk -l命令查看添加的硬盘名称,可以看到sdb为新增的硬盘

[root@oracle ~]# fdisk -l

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: 0x00000000

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: 0x0006b59c

Device Boot   Start     End   Blocks  Id System

/dev/sda1  *      1     39   307200  83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2       39    2358  18631680  83 Linux

/dev/sda3      2358    2611   2031616  82 Linux swap / Solaris 

2、进行分区,输入m查看提示

[root@oracle ~]# fdisk /dev/sdb 

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x09f38795.

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

  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) 

分析:主要参数的解析

1. 输入 m 显示所有命令列示。

2. 输入 p 显示硬盘分割情形,打印分区表。

3. 输入 a 设定硬盘启动区。

4. 输入 n 创建新的硬盘分割区。

  4.1. 输入 e 硬盘为[延伸]分割区(extend)。

  4.2. 输入 p 硬盘为[主要]分割区(primary)。

5. 输入 t 改变硬盘分割区属性。          

  1. t:分区系统id号
  2. L:82:linux swap
  3. 83:linux
  4. 86:NTFS window分区

6. 输入 d 删除硬盘分割区属性。

7. 输入 q 结束不存入硬盘分割区属性。

8. 输入 w 结束并写入硬盘分割区属性

3、输入n创建新的硬盘分区——输入p创建主分区——输入1设置一个分区——回车——回车(默认全部空间)

Command (m for help): n

Command action

  e  extended                                  ···扩展分区

  p  primary partition (1-4)                          ···主分区

p

Partition number (1-4): 1

First cylinder (1-2610, default 1): 

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): 

Using default value 2610 

4、输入p查看分区情况——输入w保存退出(一定要w保存不然无效)

Command (m for help): p

 

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: 0x09f38795

 

  Device Boot   Start     End   Blocks  Id System

/dev/sdb1        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. 

5、mkfs命令格式化磁盘

[root@oracle ~]# mkfs.ext4 /dev/sdb

mkfs.ext4: invalid fragment size - /dev/sdb 

6、mount命令挂载分区

[root@oracle ~]# mount /dev/sdb /oracle/

You have new mail in /var/spool/mail/root

[root@oracle ~]# df -TH

Filesystem   Type  Size Used Avail Use% Mounted on

/dev/sda2   ext4  19G  11G 7.3G 60% /

tmpfs     tmpfs 2.1G  74k 2.1G  1% /dev/shm

/dev/sda1   ext4  297M  29M 253M 11% /boot

/dev/sdb    ext4  22G  47M  20G  1% /oracle 

7、添加到/etc/fstab文件下保存退出否则重启后硬盘消失

/dev/sdb    /oracle     ext4  defaults,noatime    0 0 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 详解如何在Linux中检查和设置时区

    详解如何在Linux中检查和设置时区

    时区是地球上的一部分,其中的时间被认为是相同的,每个时区都有一个基准点,其时间被认为是“标准时间”,在 Linux 系统中,时区通常存储在 /usr/share/zoneinfo/ 目录中,本文给大家介绍了如何在Linux中检查和设置时区,需要的朋友可以参考下
    2024-06-06
  • Linux系统软件包依赖性的解决方案

    Linux系统软件包依赖性的解决方案

    这篇文章主要介绍了Linux系统软件包依赖性的解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-02-02
  • 你需要知道的16个Linux服务器监控命令

    你需要知道的16个Linux服务器监控命令

    如果你想知道你的服务器正在做干什么,你就需要了解一些基本的命令,一旦你精通了这些命令,那你就是一个 专业的 Linux 系统管理员
    2012-03-03
  • Apache中使非伪静态url跳转到伪静态url的方法

    Apache中使非伪静态url跳转到伪静态url的方法

    这篇文章主要介绍了Apache中使非伪静态url跳转到伪静态url的方法,主要是在使用.htaccess时的问题,需要的朋友可以参考下
    2015-07-07
  • CentOS 7如何快速开放端口

    CentOS 7如何快速开放端口

    这篇文章主要为大家详细介绍了CentOS 7如何快速开放端口,如何使用firewalld开放Linux端口,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-01-01
  • linux用户和组命令实例分析【切换、添加用户、权限控制等】

    linux用户和组命令实例分析【切换、添加用户、权限控制等】

    这篇文章主要介绍了linux用户和组命令,结合实例形式分析了Linux系统切换、添加用户、权限控制等相关命令与使用技巧,需要的朋友可以参考下
    2020-03-03
  • CentOS7安装GlusterFS集群的全过程

    CentOS7安装GlusterFS集群的全过程

    GlusterFS是一款分布式文件系统,能支持的clinet数很多,并能很好的管理各个节点,下面这篇文章主要给大家介绍了关于CentOS7安装GlusterFS集群的相关资料,需要的朋友可以参考下
    2022-04-04
  • Linxu服务器上安装JDK 详细步骤

    Linxu服务器上安装JDK 详细步骤

    这篇文章主要介绍了Linxu服务器上安装JDK 详细步骤,在安装之前需要先卸载自己linux上的jdk,具体内容详情大家参考下本文
    2017-12-12
  • 5个可能被你忽略的Linux安全设置方法

    5个可能被你忽略的Linux安全设置方法

    众所周知,网络安全是一个非常重要的课题,而服务器是网络安全中最关键的环节。Linux被认为是一个比较安全的Internet服务器,作为一种开放源代码操作系统,一旦Linux系统中发现有安全漏洞,Internet上来自世界各地的志愿者会踊跃修补它。
    2008-09-09
  • Linux里Makefile是什么?它是如何工作的?

    Linux里Makefile是什么?它是如何工作的?

    今天小编就为大家分享一篇关于makefile是什么及其工作原理的文章,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2018-09-09

最新评论