zoukankan      html  css  js  c++  java
  • linux硬盘分区和fdisk命令

    分区的几个概念

    硬盘分区有三种,主分区、扩展分区、逻辑分区。
    一个硬盘主分区至少有1个,最多4个,扩展分区可以没有,最多1个。且主分区+扩展分区总共不能超过4个。逻辑分区可以有若干个。
    在windows下激活的主分区是硬盘的启动分区,他是独立的,也是硬盘的第一个分区,正常分的话就是C区。 在linux下主分区和逻辑分区都可以用来放系统,引导os开机。
    一块硬盘分出主分区后,其余的部分可以分成扩展分区,一般是剩下的部分全部分成扩展分区,也可以不全分,那剩的部分就浪费了。
    但扩展分区是不能直接用的,他是以逻辑分区的方式来使用的,所以说扩展分区可分成若干逻辑分区。他们的关系是包含的关系,所有的逻辑分区都是扩展分区的一部分。
    在linux中第一块硬盘分区为hda分区,主分区编号为hda1-4,逻辑分区从5开始。
    硬盘的容量=主分区的容量+扩展分区的容量
    扩展分区的容量=各个逻辑分区的容量之和

    fdisk命令

    fdisk是一个创建和维护分区的命令,常用用法:

    • fdisk [选项] <disk>  改变分区
    • fdisk [选项] -l <disk>  列出所有分区

    菜单操作说明:

    a 设置可引导标记(活动分区/引导分区之间切换)
    b 编辑BSD磁盘标签
    c 设置DOS操作系统兼容标记(兼容/不兼容之间切换)
    d 删除一个分区
    l 显示已知的分区类型,其中82为Linux swap分区,83为Linux分区
    m 显示帮助信息
    n 增加一个新的分区
    o 创建一个新的空白的DOS分区表
    p 显示磁盘当前的分区表
    q 退出fdisk程序,不保存任何修改
    s 创建一个新的空白的Sun磁盘标签
    t 改变一个分区的系统ID,就是改变分区类型(比如把Linux Swap分区改为Linux分区)
    u 改变显示或输入单位
    v 验证磁盘分区表
    w 将分区表写入磁盘并退出(保存并退出)
    x 额外功能(专家级)

    实例一

    显示当前分区情况:fdisk -l 

    [root@localhost ~]# fdisk -l
    
    Disk /dev/sda: 250.1 GB, 250059350016 bytes
    
    255 heads, 63 sectors/track, 30401 cylinders
    
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
    Disk identifier: 0xd10cd10c


    #从上面信息可以看出,这个硬盘是250G的,有255个磁面;63个扇区;30401个磁柱;每个 cylinder(磁柱)的容量是 8225280 bytes=8225.280 K(约为)=8.225280M(约为);
    Device Boot Start End Blocks Id System /dev/sda1 1 3917 31463271 7 HPFS/NTFS /dev/sda2 3918 30401 212732730 f W95 Ext'd (LBA) /dev/sda5 3918 12841 71681998+ 7 HPFS/NTFS /dev/sda6 12842 21765 71681998+ 7 HPFS/NTFS /dev/sda7 21766 23070 10482381 b W95 FAT32 /dev/sda8 23071 25620 20482843+ 83 Linux /dev/sda9 25621 25747 1020096 82 Linux swap / Solaris /dev/sda10 25748 30401 37383223+ 83 Linux

    #通过上面的信息,我们知道此机器中挂载一个硬盘sda ;其中 sda有两个主分区(包括扩展分区),分别是主分区 sda1 和sda2(扩展分区) ;逻辑分区是 hda5到hda10
    #根据起始磁柱的数值,上一个分区的End的值+1 就是下一个分区的Start 的值,所以sda1主分区与sda2扩展分区完全占用了30401个磁柱;
    #同理,sda5至sda10也连续无间断的占用了整个sda2磁柱(3918-30401),说明/dev/sda整个硬盘已完全划分。

    实例二

    使用操作菜单,创建一个新的分区

    [root@jollypay-V4-1 ~]# 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 0xe155fe8e.
    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)
    
    Command (m for help): n                           //输入n,表示新建
    Command action
       e   extended                                   //扩展分区,创建扩展分区会占用一个主分区,并且只有创建扩展分区后才能创建逻辑分区
       p   primary partition (1-4)                    //主分区,最多创建4个
    p                                                 //输入p,表示新建主分区
    Partition number (1-4): 1                         //输入1,即sdb1分区
    First cylinder (1-13054, default 1):              //开始磁柱,默认为1(回车)
    Using default value 1
    Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):   //终止磁柱,默认为最后(回车),不仅仅可以用数值表示,也可以这么写,+500M
    Using default value 13054
    
    Command (m for help): w                            //写入磁盘,保存并退出,否则之前的操作都无效。如果不想写入磁盘就使用q
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

    注意:fdisk用来对小于2T的磁盘进行分区,如果大于2T需用parted工具

    参考:https://www.cnblogs.com/w-wfy/p/8870598.html

    https://blog.csdn.net/qq_25408423/article/details/82867492

  • 相关阅读:
    AcWing 1059. 股票买卖 VI Leetcode714. 买卖股票的最佳时机含手续费 dp
    AcWing 1058. 股票买卖 V Leetcode309. 最佳买卖股票时机含冷冻期
    Js取float型小数点后两位数的方法
    浏览器退 事件
    微信中得到的GPS经纬度放在百度,腾迅地图中不准的原因及处理
    dropdownlist 控件的判断
    有一个无效 SelectedValue,因为它不在项目列表中。
    CSS从大图中抠取小图完整教程(background-position应用)
    去掉 input type="number" 右边图标
    页面中星号与字体对齐
  • 原文地址:https://www.cnblogs.com/xulan0922/p/12769341.html
Copyright © 2011-2022 走看看