美文网首页
fdisk和mount命令使用总结

fdisk和mount命令使用总结

作者: 落辰风雷 | 来源:发表于2018-07-31 20:52 被阅读0次

因为公司业务需求,比较头疼就是要来回在机房和办公室跑,去刻录镜像并更改磁盘分区,为了节约时间,这里对工作过程中一些浪费时间的操作做了一些总结。

fisk磁盘进行分区

相比于parted命令,fdisk能对2T一下磁盘进行分区,而parted可以支持2T及以上的磁盘分区

详细用法:

 fdisk [options] <disk>    change partition table
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks

Options:
 -b <size>             sector size (512, 1024, 2048 or 4096)
 -c[=<mode>]           compatible mode: 'dos' or 'nondos' (default)
 -h                    print this help text
 -u[=<unit>]           display units: 'cylinders' or 'sectors' (default)
 -v                    print program version
 -C <number>           specify the number of cylinders
 -H <number>           specify the number of heads
 -S <number>           specify the number of sectors per track

这里主要描述一些流程性的操作

  • 查看系统磁盘挂载情况 fdisk -l
  • 进行磁盘分区
     fdisk /dev/hda
    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.
    Command (m for help): 
    
    • 输入m,查看帮助
       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,新建分区
       All primary partitions are in use
        Adding logical partition 6
        First sector (82417664-250069679, default 82417664): 
      

      这里可以看到有一个first sector。由于这个磁盘已经是有分区的,所以它会从剩余空间的第一个块开始默认作为起始块,如果各位的磁盘时纯净的,格式化或者用零写过一遍,那么起始块应该是1,这个时候可以自己设定分区块的大小。比如254,353。。。。。。只要不超过磁盘的总块数就可以

    • 输入p,查看分区情况
      Disk /dev/hda: 1000.2 GB, 1000204886016 bytes, 1953525168 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: 0x000f003e
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/hda1   *        2048    40962047    20480000   83  Linux
      /dev/hda2        40962048    53250047     6144000   83  Linux
      /dev/hda3        53250048    61442047     4096000   83  Linux
      /dev/hda4        61442048   250069679    94313816    5  Extended
      /dev/hda5        61444096    82415615    10485760   83  Linux
      /dev/hda6        82417664   250069679    83826008   83  Linux
      
    • 输入w,对分区进行保存

      如果各位对自己创建分区的结果很满意的话,这一步是必须的哦,不然以上操作默认是不保存的。

mount挂载分区

比如我在一台服务器上刻录完卡,这个时候系统已经存在于我们的系统卡上,但是网络还未配置,即使在控制器上正常运行,也没有能力加入我们的集群,所以为系统添加网络服务是很有必要的。
这个时候我们可以在之前刻卡的设备上顺便修改系统的网络配置。

  • 将我们的系统卡的一个分区挂载到刻卡设备上
    mount /dev/hdc /mnt/mount

    操作前提是:我登录在刻卡服务器上。以上/dev/hdc磁盘时我的系统卡即我要配置网络的系统所在地,/mnt/mount是我进行磁盘挂载的目录

  • 进入系统网络配置,一般我们会对eth0即一号网口进行ip配置
    vim /mnt/mount/etc/sysconfig/network-scripts/ifcfg-eth0
    显示如下
    DEVICE=eth0
    ONBOOT=yes
    STARTMODE=onboot
    MTU=1500
    BOOTPROTO=static
    IPADDR=0.0.0.0
    NETMASK=
    GATEWAY=
    
  • 对eth0网口进行编辑,主要配置ip,子网掩码,网关
    DEVICE=eth0
    ONBOOT=yes
    STARTMODE=onboot
    MTU=1500
    BOOTPROTO=static
    IPADDR=10.192.54.111
    NETMASK=255.255.255.0
    GATEWAY=10.192.54.254
    

    这里也并非一定要对eth0进行更改,可以根据自己实际情况进行网口的ip配置,有可能eth0自己不想用,可以更换为eth1.....

配置好ip,检查好之后我们就可以带着系统卡返回到自己的控制器,启动之后就可以在内网下进行自己的工作了。

相关文章

网友评论

      本文标题:fdisk和mount命令使用总结

      本文链接:https://www.haomeiwen.com/subject/wxxkvftx.html