美文网首页
fdisk详细剖析笔记

fdisk详细剖析笔记

作者: Godtoy | 来源:发表于2017-04-24 08:11 被阅读0次

    fdisk 简单使用

    fdisk 工具原理就是修改磁盘的分区表,和分区信息。

    查看帮助

    #fdisk --help
    
    (1)磁盘列表
    #fdisk -l
    
    (2)管理某个磁盘
    #fdisk /dev/sdb
    交互模式,可以直接m查看帮助信息,后面可以使用非交互模式,脚本自动格式化
    磁盘分区建议:1p+1e  2p+1e 3p+1e 扩展分区是必要的,
    但是在格式化磁盘的时候,最好事先做好规划,LVM文件格式可以动态的进行磁盘大小的控制,但是性能非常的慢,企业当中一般使用户硬件级别的LVM不使用软LVM
    
    一般操作基本都是:
    n 创建新的分区
    p 主分区 (1-4)
    1 分区号 (1-4)
    w 保存退出
    
    (3)分区完成后,需要此步骤,否则去使用这些分区时会出现错误信息。当然,如果不这样做的话,也可以采取重新启动系统的方法。
    # partprobe /dev/sdb
    
    image.png
    (4)格式化文件系统
    #mkfs
    一般使用ext4
    
    image.png
    也可以使用,让文件系统不做检查
    #tune2fs -c -1 /dev/sdb1
    
    挂载文件系统到文件夹
    #mount /dev/sdb1 /mnt
    
    (6)挂载使用
    #mount /dev/sdb1 /mnt
    #df -hl
    

    非交互是fdisk的使用

    1.把fdisk的命令参数写到一个文件当中fdisk.txt

    fdisk.txt 内容

    o
    n
    p
    1
    2048
    +1G
    w
    

    o代表创建DOS MBR的分区表
    2.操作

    root@ubuntu-docker:/server# fdisk /dev/sdb <fdisk.txt
    
    Welcome to fdisk (util-linux 2.27.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    命令(输入 m 获取帮助): Created a new DOS disklabel with disk identifier 0xcb13d195.
    
    命令(输入 m 获取帮助): Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): 分区号 (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 
    Created a new partition 1 of type 'Linux' and of size 1 GiB.
    
    命令(输入 m 获取帮助): The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
    root@ubuntu-docker:/server# 
    

    在非交互式情况下,请注意fdisk的分区的时候选择磁盘空间的时候看清是选择柱面,还是选择磁盘的扇区,这两个是不一样的。

    相关文章

      网友评论

          本文标题:fdisk详细剖析笔记

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