zoukankan      html  css  js  c++  java
  • 【磁盘/文件系统】第二篇:标准磁盘分区流程针对fdisk(硬盘容量小于2T且分区数不能大于15个分区)

    前奏:先插上一块磁盘(做了RAID的磁盘才能分区)

    查看磁盘连上服务器没有,或者说是可以进行分区前奏

      [root@PandaLi ~]# ll /dev/sd
      sda sda1 sda2 sda3 sdb sdc

    第一步:创建分区命令

    (这里说一下为什么要使用 -c 和 -u参数)

    [root@PandaLi ~]# 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 0x7711a1b3.
    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    【警告:dos兼容模式被弃用】
    switch off the mode (command 'c') and change display units to            【强烈建议在分区的时候使用-c 和 -u 参数】
    sectors (command 'u').

    Command (m for help):

    创建分区标准命令:fdisk -cu /dev/sdb    [对/dev/sdb进行分区]

    [root@PandaLi ~]# fdisk -cu /dev/sdb
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0xa8d09c04.
    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)

    Command (m for help):

    fdisk命令参数介绍

         m、获取帮助
         p、打印分区表。
         n、新建一个新分区。
         d、删除一个分区。
         q、退出不保存。
         w、把分区写进分区表,保存并退出。

    Command (m for help): n    ####创建一个分区
    Command action
       e   extended
       p   primary partition (1-4)
    p    ####创建一个主分区
    Partition number (1-4): 1    ####设置主分区编号
    First sector (2048-2097151, default 2048):     ####主分区开始位置(默认是扇区)
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +200M      ####主分区结束位置 (可以使用K M G 单位)
    
    Command (m for help): p    ####查看当前分区信息
    
    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 identifier: 0xa8d09c04
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      411647      204800   83  Linux
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 
    Value out of range.
    Partition number (1-4): 2
    First sector (411648-2097151, default 411648): 
    Using default value 411648
    Last sector, +sectors or +size{K,M,G} (411648-2097151, default 2097151): +300M
    
    Command (m for help): p
    
    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 identifier: 0xa8d09c04
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      411647      204800   83  Linux
    /dev/sdb2          411648     1026047      307200   83  Linux
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    e    ####创建一个扩展分区
    Partition number (1-4): 3
    First sector (1026048-2097151, default 1026048): 
    Using default value 1026048
    Last sector, +sectors or +size{K,M,G} (1026048-2097151, default 2097151): 
    Using default value 2097151
    
    Command (m for help): p
    
    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 identifier: 0xa8d09c04
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      411647      204800   83  Linux
    /dev/sdb2          411648     1026047      307200   83  Linux
    /dev/sdb3         1026048     2097151      535552    5  Extended
    
    Command (m for help): n
    Command action
       l   logical (5 or over)
       p   primary partition (1-4)
    l    ####创建一个逻辑分区(必须先要有扩展分区才能有逻辑分区)
    First sector (1028096-2097151, default 1028096): 
    Using default value 1028096
    Last sector, +sectors or +size{K,M,G} (1028096-2097151, default 2097151): +100M
    
    Command (m for help): p
    
    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 identifier: 0xa8d09c04
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      411647      204800   83  Linux
    /dev/sdb2          411648     1026047      307200   83  Linux
    /dev/sdb3         1026048     2097151      535552    5  Extended
    /dev/sdb5         1028096     1232895      102400   83  Linux

    Command (m for help): t      ####修改分区的ID
    Partition number (1-5): 5
    Hex code (type L to list codes): l  ####查看全部编号(小写L)

    0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
    1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
    2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
    3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
    4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
    5 Extended 42 SFS 86 NTFS volume set da Non-FS data
    6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
    7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
    8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
    9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
    a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
    b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
    c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
    e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
    f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
    10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
    11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
    12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
    14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
    16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
    17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
    18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
    1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
    1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
    1e Hidden W95 FAT1
    Hex code (type L to list codes): 82    ####把ID修改为82
    Changed system type of partition 5 to 82 (Linux swap / Solaris)

    Command (m for help): p

    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 identifier: 0xa8d09c04

    Device Boot Start End Blocks Id System
    /dev/sdb1 2048 411647 204800 83 Linux
    /dev/sdb2 411648 1026047 307200 83 Linux
    /dev/sdb3 1026048 2097151 535552 5 Extended
    /dev/sdb5 1028096 1232895 102400 82 Linux swap / Solaris

    Command (m for help): d    ####删除一个分区

    Partition number (1-5): 5

    Command (m for help): p

    Disk /dev/sdb: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders, total 2097152 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 identifier: 0xa8d09c04

    Device Boot Start End Blocks Id System
    /dev/sdb1 2048 411647 204800 83 Linux
    /dev/sdb2 411648 1026047 307200 83 Linux
    /dev/sdb3 1026048 2097151 535552 5 Extended

    Command (m for help):

    Command (m for help): w    ####保存退出(q 是不保存退出)
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@PandaLi ~]#

    第二步:查看内核是否已经识别分区命令
      cat /proc/partitions

    第三步:通知内核重新读取磁盘分区表
      方法一:
        partprobe /dev/sdb    【推荐】
      方法二:
        partx [-a,-n] /dev/DEVICE

                 参数:
        -a:读取全部分区表
        -n:读取指定的分区表
      方法三:
        kpartx [-a,-f] /dev/DEVICE
        参数:
        -a:读取全部分区表
        -f:强制读取分区表 【注意:这种方法不建议使用,如果上面的读取方法不行的话,最后才使用这种方法】

    第四步:格式化创建文件系统
      mkfs.ext4 /dev/sdb1

      注意:
        格式化文件系统的时候必须要指定格式化哪个分区
        格式化文件系统之后,系统会默认挂载25次或180天之后进行磁盘检查

    第五步:让系统不对我们新创建的分区进行磁盘检查
      tune2fs -c 0 -i 0 /dev/sdb1

            注意:这里也是必须要指定哪个分区

    第六步:文件系统的临时挂载
      临时挂载:mount /dev/sdb1 /mnt/     【这里也是必须要指定哪个分区】

    第七步:文件系统永久挂载
      方法一:设置开机自动运行
        把挂载命令放入到/etc/rc.local
      方法二:添加到开机自动挂载配置文件
        /etc/fstab      【设备文件 挂载点 设备文件类型 挂载参数 是否进行备份 是否进行磁盘检查】
        如果想以UUID挂载的话,可以使用命令查看分区的UUID编号:命令(blkid)

    第八步:查看挂载情况
      mount
      cat /proc/mounts

    备注:更多信息请查看本地资料:磁盘章节内容

  • 相关阅读:
    「消息队列」看过来!
    stl中map的四种插入方法总结
    4.shell编程-文本处理三剑客之sed
    3.shell编程-文件查找之find命令
    2.shell编程-函数的高级用法
    1.shell编程-变量的高级用法
    Django打造大型企业官网(八)
    Django打造大型企业官网(七)
    Django打造大型企业官网(六)
    Django打造大型企业官网(五)
  • 原文地址:https://www.cnblogs.com/l75790/p/9432670.html
Copyright © 2011-2022 走看看