zoukankan      html  css  js  c++  java
  • ②linux fdisk

    磁盘基本分区Fdisk

    1.添加一块小于2TB的磁盘进行使用,步骤如下:
    1.给虚拟机添加一块新的硬盘
    2.使用fdisk进行分区
    3.使用mkfs进行格式化
    4.使用mount进行挂载
    PS: 生产分区建议,如无特殊需求直接使用整个磁盘即可,无需分区。
    PS: 学习分区建议: 1P+1E(3L) 2P+1E(2L) 3P+1E(1L) (仅适用于练习)

    [root@xuliangwei ~]# fdisk -l
    [root@xuliangwei ~]# fdisk  /dev/sdb
    Command (m for help): m         #输入m列出常用的命令
    Command action
       a   toggle a bootable flag               #切换分区启动标记
       b   edit bsd disklabel                   #编辑sdb磁盘标签
       c   toggle the dos compatibility flag    #切换dos兼容模式
       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     #创建新的Sun磁盘标签
       t   change a partitions system id       #修改分区ID,可以通过l查看id
       u   change display/entry units           #修改容量单位,磁柱或扇区
       v   verify the partition table           #检验分区表
       w   write table to disk and exit         #保存退出
       x   extra functionality (experts only)   #拓展功能
    

    1.fdisk创建主分区

    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)  #主分区
       e   extended  #扩展分区
    Select (default p): p   #选择创建主分区
    Partition number (1-4, default 1):  #默认创建第一个主分区
    First sector (2048-2097151, default 2048): #默认扇区回车
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +50M #分配50MB
    

    2.fdisk创建扩展分区

    Command (m for help): n  #新建分区
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): e   #创建扩展分区
    Partition number (2-4, default 2):
    First sector (104448-2097151, default 104448):
    Using default value 104448
    Last sector, +sectors or +size{K,M,G} (104448-2097151, default 2097151): #空间都给到扩展分区
    

    3.fdisk创建逻辑分区

    Command (m for help): n  #新建分区
    Partition type:
       p   primary (1 primary, 1 extended, 2 free)
       l   logical (numbered from 5)
    Select (default p): l   #创建逻辑分区
    Adding logical partition 5
    First sector (106496-2097151, default 106496):
    Using default value 106496
    Last sector, +sectors or +size{K,M,G} (106496-2097151, default 2097151): +100M  #分配100MB空间
    

    4.fdisk查看分区情况,并保存

    Command (m for help): p #查看分区创建
    Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      104447       51200   83  Linux
    /dev/sdb2          104448     2097151      996352    5  Extended
    /dev/sdb5          106496      311295      102400   83  Linux
    
    #保存分区
    Command (m for help): w
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    检查磁盘是否是MBR分区方式

    [root@xuliangwei ~]# fdisk /dev/sdb -l|grep type
    Disk label type: dos
    
    #安装parted, 刷新内核立即生效,无需重启
    [root@xuliangwei ~]# yum -y install parted
    [root@xuliangwei ~]# partprobe /dev/sdb
    

    2.格式化磁盘
    mkfs格式化磁盘,实质创建文件系统,文件系统类似于将房子装修成3室一厅,还是2室一厅。

    选项:

    -b 设定数据区块占用空间大小,目前支持1024、2048、4096 bytes每个块。

    -t 用来指定什么类型的文件系统,可以是ext4, xfs

    -i 设定inode的大小

    -N 设定inode数量,防止Inode数量不够导致磁盘不足

    #1.格式化整个磁盘
    [root@xuliangwei ~]# mkfs.ext4  /dev/sdb 
    
    #2.格式化磁盘的某个分区
    [root@xuliangwei ~]# mkfs.xfs  /dev/sdb1
    

    3.使用mount挂载并使用
    如果需要使用该磁盘的空间,需要准备一个空的目录作为挂载点,与该设备进行关联。

    [root@xuliangwei ~]# mkdir /data
    [root@xuliangwei ~]# mount /dev/sdb1 /data
    
  • 相关阅读:
    spring boot整合mybatis+mybatis-plus
    Spring Boot Shiro 权限管理
    Spring Boot 热部署(转)
    SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例
    详解Spring Boot配置文件之多环境配置
    Java 泛型-泛型类、泛型方法、泛型接口、通配符、上下限
    mybatis中整合ehcache缓存框架的使用
    Java总结篇系列:Java泛型
    java中接口之间的继承
    Java中接口继承泛型接口
  • 原文地址:https://www.cnblogs.com/yangtao416/p/14515730.html
Copyright © 2011-2022 走看看