欢迎访问凯铧科技有限公司网站! |7X24服务热线:158-0160-3153
  • 阿里云服务器

    简单高效、处理能力可弹性伸缩的计算服务

    了解详情
当前位置:首页 > 常见问题 > 帮助中心 >
云服务器Linux如何分区格式化 2017-08-25 15:27:21

硬盘有 disk size 和 partition size 两个概念。

如果您的硬盘是第一次加载的硬盘,就需要进行分区、格式化,和 mount 操作。 如果是老硬盘,且没有扩容,就不用再分区、格式化了,直接 mount 就行。

警告 如果硬盘容量大于1TB,建议使用 parted 工具进行分区。

以 Ubuntu Linux 为例,以下操作需要 root 权限。

第一步我们先为磁盘分区


  • 使用 fdisk 分区

    通过 fdisk -l 命令查看挂载的硬盘,假设为 /dev/sdc

    # fdisk -l  ...  Disk /dev/sdc: 10.7 GB, 10737418240 bytes  64 heads, 32 sectors/track, 10240 cylinders, total 20971520 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: 0x00000000    Disk /dev/sdc doesn't contain a valid partition table

    对硬盘进行分区:

    # fdisk /dev/sdc

    然后根据提示,依次输入 n, p, 1, 以及两次回车,然后是 wq,完成保存。 这样再次通过 fdisk -l 查看时,您可以看到新建的分区/dev/sdc1

    # fdisk -l  ...  Disk /dev/sdc: 10.7 GB, 10737418240 bytes  64 heads, 32 sectors/track, 10240 cylinders, total 20971520 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: 0x17adb4cb    Device Boot      Start         End      Blocks   Id  System  /dev/sdc1            2048    20971519    10484736   83  Linux

  • 使用 parted 分区

    通过 parted -l 命令查看新挂载的硬盘,假设为 /dev/sdc

    # parted -l  ...    错误: /dev/sdc: unrecognised disk label

    对硬盘进行分区:

    # parted /dev/sdc                      

    然后新建新分区

    (parted) mklabel gpt (parted) mkpart primary 1049K -1 (parted) quit

    这时再查看硬盘信息时会看到 /dev/sdc1

    # parted -l  ...  Model: QEMU QEMU HARDDISK (scsi)  Disk /dev/sdc: 10.7GB  Sector size (logical/physical): 512B/512B  Partition Table: gpt    Number  Start   End     Size    File system  Name     标志   1      1049kB  10.7GB  10.7GB               primary

分区后要进行格式化,例如格式化为 ext4 格式

# mkfs -t ext4 /dev/sdc1

最后挂载硬盘:

# mkdir -p /mnt/sdc && mount -t ext4 /dev/sdc1 /mnt/sdc

警告 为了防止宿云服务器在突然断电时可能对数据带来的风险,如果文件系统是ext3,则需要在mount的时候显式的指定”barrier=1”选项,例如”mount -t ext3 -o barrier=1 /dev/sdc1 /mnt/point

 

北京凯铧互联科技有限公司(简称凯铧互联)由多名前阿里云资深技术专家创立,核心员工来自阿里巴巴、腾讯等,做为一家综合性方案商,凯铧互联向各行业用户提供基于公有云,私有云,混合云等基于云计算的各种解决方案。