Linux硬盘分区的操作步骤

网站编辑2021-07-09 10:56:18434

  Linux硬盘的分区,就要知道MBR、扩展分区和逻辑分区的概念,今天小编就给大家介绍下Linux硬盘分区的详细步骤
  1、查看硬盘大小,并分区。
  [root@colud ~]# fdisk -l
  Disk /dev/sda: 10.7 GB, 10737418240 bytes
  255 heads, 63 sectors/track, 1305 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: 0x000c16ac
  Device Boot      Start         End      Blocks   Id  System
  /dev/sda1   *           1          64      512000   83  Linux
  Partition 1 does not end on cylinder boundary.
  /dev/sda2              64        1306     9971712   8e  Linux LVM
  Disk /dev/sdb: 59.1 GB, 59055800320 bytes
  255 heads, 63 sectors/track, 7179 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: 0xda4662fa
  Device Boot      Start         End      Blocks   Id  System
  ...........

  后边还有好多就不列出来了,此时可以看到有一个/dev/sdb硬盘是没有进行分区的。可以看到大小是59.1G。解析来对这个磁盘进行分区即可。


  2、对空白盘分区
  使用fdisk命令管理/dev/sdb,进去以后输入“n”执行增加分区,选择“P”创建主分区,填写分区编号,选择分区大小First cylinder起始柱面默认即可,然后写上去分区想分多大,可以使用+100M,10G,20G等直接写明需要多大的分区,Last cylinder如果也用默认即是整个磁盘分一个分区,最后使用“w”保存下分区即可。命令操作如下所示,当有多块磁盘时按照步骤重复分区就可以了:
  [root@colud ~]# fdisk /dev/sdb
  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
  Command action
  e   extended
  p   primary partition (1-4)
  p
  Partition number (1-4): 1
  First cylinder (1-7179, default 1): 1
  Last cylinder, +cylinders or +size{K,M,G} (1-7179, default 7179): +20G
  Command (m for help): p
  Disk /dev/sdb: 59.1 GB, 59055800320 bytes
  255 heads, 63 sectors/track, 7179 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: 0xda4662fa
  Device Boot      Start         End      Blocks   Id  System
  /dev/sdb1               1        2612    20980858+  83  Linux
  Command (m for help): w
  The partition table has been altered!
  Calling ioctl() to re-read partition table.
  Syncing disks.
  3、格式化分区
  常见的分区格式有ext2、ext3、ext4、xfs等格式,此处可以使用ext4格式来对分区进行格式化,需要其他格式的根据你的实际情况决定就可以。
  命令为:mkfs.ext4 /dev/sdb1 ,此处的sdb1是刚分出来的新分区。
  [root@colud ~]# mkfs.ext4 /dev/sdb1
  mke2fs 1.41.12 (17-May-2010)
  文件系统标签=
  操作系统:Linux
  块大小=4096 (log=2)
  分块大小=4096 (log=2)
  Stride=0 blocks, Stripe width=0 blocks
  1313760 inodes, 5245214 blocks
  262260 blocks (5.00%) reserved for the super user
  第一个数据块=0
  Maximum filesystem blocks=0
  161 block groups
  32768 blocks per group, 32768 fragments per group
  8160 inodes per group
  Superblock backups stored on blocks:
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  4096000
  正在写入inode表: 完成
  Creating journal (32768 blocks): 完成
  Writing superblocks and filesystem accounting information: 完成
  This filesystem will be automatically checked every 23 mounts or
  180 days, whichever comes first.  Use tune2fs -c or -i to override.
  4、对分区进行挂载,使系统每次重启可以自动挂载此分区,否则将无法往此分区写数据。
  对分区挂载步骤如下:
  创建挂载点:mkdir /data
  手动挂载分区:moutn /dev/sdb1 /data
  将挂载信息写入分区表,方便系统启动自动挂载:
  vi /etc/fstab 然后在最后一行写入挂载信息:
  /dev/sdb1               /data                   ext4    defaults        0 0

最新推荐

右侧广告图1
  • 数据库审计

    在满足等保2.0‘安全审计’相关要求的同时,智能解析数据库通信流量,细粒度审计数据库访问行为,通过对数据库全量行为的审计溯源、危险攻击的实时告警、风险语句的智能预警,提供敏感的数据库资产安全的监控保障

    ¥3000.00/月

    等保合规

  • 负载均衡

    负载均衡SLB是一种对流量进行按需分发的服务,通过将流量分发到不同的后端服务来扩展应用系统的服务吞吐能力,并且可以消除系统中的单点故障,提升应用系统的可用性。

    ¥0.04/小时

    实例5折带宽8折

  • 弹性裸金属服务器

    弹性裸金属服务器是一种可弹性伸缩的高性能计算服务,计算性能与传统物理机无差别,具有安全物理隔离的特点。分钟级的交付周期将提供给您实时的业务响应能力,助力您的核心业务飞速成长。

    ¥12405.00/月

    折扣优惠

右侧广告图2