zoukankan      html  css  js  c++  java
  • 磁盘管理 -- fdisk

    • 磁盘结构
    • 磁盘接口
    • MBR
    • 磁盘分区表示
    • 磁盘分区管理
    • fdisk 进行分区
    • 格式化分区
    • 开机挂载分区

    磁盘结构


    • 磁盘的屋里结构
      • 盘片: 硬盘有多个盘片, 每个盘片两面
      • 磁头: 每面有一个磁头
    • 硬盘的数据结构
      • 扇区: 盘片被分为多个扇形区域, 每个扇形区存放 512 字节的数据
      • 磁道: 同一盘片不同半径的同心圆
      • 柱面: 不同盘片相同半径构成的圆柱面
    • 硬盘存储容量 = 磁头数 * 磁道(柱面)数 * 每道扇区数 * 每个扇区的字节数
    • 可以用柱面 / 磁头 / 扇区 来唯一定位磁盘上的每一个区域

    磁盘接口


    • IDE (并口)
    • SATA (串口)
      • 速度快
      • 纠错能力强
    • SCSI
      • 转速快
      • CPU 占用资源低
      • 支持热插拔
         

    MBR


    • 定义: MBR (Master Boot Record) 主引导记录
    • 位置: MBR 位于硬盘第一个物理扇区处
    • MBR 中包含硬盘的主引导程序和硬盘分区表, 分区表有 4 个分区记录区, 每个分区记录区占 16 个字节, 共 64 字节, 446 字节存放主引导程序, 2 字节校验;

    磁盘分区表示


    • Linux中将硬盘等设备均表示为文件

        /dev/sda5  /dev == 硬件设备文件所在的目录 ;   sd == 表示 SCSI 设备 ; a == 表示硬盘的顺序号 ( a,b,c... ) ;  5 == 分区的顺序号  ( 1,2,3...);

                                hd == 表示 IDE 设备

    磁盘分区管理


    • MBR/msdos 分区模式
      • 分区类型: 主分区 , 扩展分区 , 逻辑分区
      • 分区模式: 1~4 主分区; 1~3 主分区 + 扩展分区 ( 可分 n 个逻辑分区)
      • 最大支持容量 2.2TB
      • 扩展分区不能格式化
    • GPT 分区模式, 最大 18EB ( 1EB = 1000PB ; 1PB = 1000TB )

    fdisk 进行分区


    // 查看硬盘信息
    lsblk 
        NAME                           MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
        sda                              8:0    0   150G  0 disk 
        ├─sda1                           8:1    0   200M  0 part /boot
        ├─sda2                           8:2    0     2G  0 part [SWAP]
        └─sda3                           8:3    0 147.8G  0 part 
          ├─vg_centos6-LogVol02 (dm-0) 253:0    0  67.8G  0 lvm  /
          ├─vg_centos6-LogVol00 (dm-1) 253:1    0    40G  0 lvm  /usr
          └─vg_centos6-LogVol01 (dm-2) 253:2    0    40G  0 lvm  /data
        sdb                              8:16   0   100G  0 disk            // 新添加的硬盘;
    
    // 对 sdb 硬盘进行分区
    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 0xb9f722f6.
        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): n                // n 为新增分区;
               e   extended                    // e 表示 扩展分区;
               p   primary partition (1-4)    // p 表示 主分区;
        
        p
        Partition number (1-4): 1            // 第一个分区
        First cylinder (1-13054, default 1):     // 分区大小,默认从1开始
        Using default value 1
        Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): +50G        // 自己设定大小, 可使用 K M G
    
        Command (m for help): p            // 打印分区信息;
    
        Disk /dev/sdb: 107.4 GB, 107374182400 bytes
        255 heads, 63 sectors/track, 13054 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: 0xb9f722f6
    
           Device Boot      Start         End      Blocks   Id  System
        /dev/sdb1               1        6528    52436128+  83  Linux
        
        Command (m for help): n            // 新增分区
        Command action
           e   extended
           p   primary partition (1-4)
        e                                // 选择 扩展分区
        Partition number (1-4): 4        // 编号可自行选择;
        First cylinder (6529-13054, default 6529):             // 磁盘开始
        Using default value 6529
        Last cylinder, +cylinders or +size{K,M,G} (6529-13054, default 13054):         // 分区大小, 默认全部;
        Using default value 13054
    
        Command (m for help): p            // 打印查看;
    
        Disk /dev/sdb: 107.4 GB, 107374182400 bytes
        255 heads, 63 sectors/track, 13054 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: 0xb9f722f6
    
           Device Boot      Start         End      Blocks   Id  System
        /dev/sdb1               1        6528    52436128+  83  Linux
        /dev/sdb4            6529       13054    52420095    5  Extended
    
        Command (m for help): n
        Command action
           l   logical (5 or over)            // 逻辑分区
           p   primary partition (1-4)
        l            
        First cylinder (6529-13054, default 6529): 
        Using default value 6529
        Last cylinder, +cylinders or +size{K,M,G} (6529-13054, default 13054): +20G
    
        Command (m for help): p
    
        Disk /dev/sdb: 107.4 GB, 107374182400 bytes
        255 heads, 63 sectors/track, 13054 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: 0xb9f722f6
    
           Device Boot      Start         End      Blocks   Id  System
        /dev/sdb1               1        6528    52436128+  83  Linux
        /dev/sdb4            6529       13054    52420095    5  Extended
        /dev/sdb5            6529        9140    20980858+  83  Linux
        
        Command (m for help): W                // W 为保存分区
        The partition table has been altered!        //     分区表已被更改
    
        Calling ioctl() to re-read partition table.
        Syncing disks.                        // 同步磁盘

    格式化分区


    // 格式化分区 ( 常见的分区格式: ext4 , xfs , ext3 等), 7以下不存在"xfs"
    mkfs.ext4 /dev/sdb1
        mke2fs 1.41.12 (17-May-2010)
        Filesystem label=
        OS type: Linux
        Block size=4096 (log=2)
        Fragment size=4096 (log=2)
        Stride=0 blocks, Stripe width=0 blocks
        3278576 inodes, 13109032 blocks
        655451 blocks (5.00%) reserved for the super user
        First data block=0
        Maximum filesystem blocks=4294967296
        401 block groups
        32768 blocks per group, 32768 fragments per group
        8176 inodes per group
        Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
            4096000, 7962624, 11239424
    
        Writing inode tables: done                            
        Creating journal (32768 blocks): done
        Writing superblocks and filesystem accounting information: done
    
        This filesystem will be automatically checked every 25 mounts or
        180 days, whichever comes first.  Use tune2fs -c or -i to override.
        
    // 查看分区格式; 同时可查看分区的 UUID;
    blkid /dev/sdb1            // 或者直接 blkid 查看所有

    开机挂载分区


    // 编辑开机挂载配置文件 /etc/fstab
    vim /etc/fstab
        ... ...
        /dev/sdb1               /data                   ext4    defaults        1 2
        
    // 第一部分: 指定要挂载的设备名称或块信息, 也可以是远程文件系统
    // 第二部分: 挂载点, swap 分区, 为 none
    // 第三部分: 指定文件类型
    // 第四部分: 默认 defaults, 表示包含选项: rw, suid, dev, exec, auto, nouser 和 async
        // >> 自动与手动挂载
            // auto: 自动挂载
            // noauto: 手动挂载
        // >> 可执行
            // exec: 是一个默认设置项,使分区中可执行的二进制文件能够执行;
            // noexec: 二进制文件不允许执行, root分区 万万不能 使用
        // >> I/O 同步
            // sync: 所有的I/O将以同步方式进行
            // nosync: 所有的 I/O 将以非同步的方式进行
        // 用户挂载权限
            // user: 允许任何用户挂载设备, 
            // nouser: 只允许 root 用户挂载, 默认设置
    // 第五部分: <dump> 1 表示要将整个<file system>里的内容备份, 0 表示不备份, 现在很少用到 dump 工具, 所以一般选 "0"
    // 第六部分: <pass> 指定如何使用fsck检查硬盘
        // 0 不检查;
        // 1 挂载点"/", 必须是 1; 其他都不能使用 1;
        // 2,3,4... 检查完根分区后, 根据数字大小从小到大依次检查;
  • 相关阅读:
    Liskov替换原则
    OCP开放封闭原则
    SRC单一职责原则
    什么是敏捷设计
    [WCF编程]13.并发:服务并发模式
    [WCF编程]12.事务:服务事务编程(下)
    [WCF编程]12.事务:服务事务编程(上)
    [WCF编程]12.事务:Transaction类
    [WCF编程]12.事务:事务传播
    [WCF编程]12.事务:事务协议与管理器
  • 原文地址:https://www.cnblogs.com/haorong/p/10594214.html
Copyright © 2011-2022 走看看