文档中心 > 云服务器 ECS

Linux 自动格式化和分区数据盘

更新时间: 访问次数:2737

免责声明:本文档可能包含第三方产品信息,该信息仅供参考。阿里云对第三方产品的性能、可靠性以及操作可能带来的潜在影响,不做任何暗示或其他形式的承诺。

 

概述

本文介绍如何使用脚本自动格式化并分区数据盘。

 

详细信息

阿里云提醒您:

  • 如果您对实例或数据有修改、变更等风险操作,务必注意实例的容灾、容错能力,确保数据安全。
  • 如果您对实例(包括但不限于ECS、RDS)等进行配置与数据修改,建议提前创建快照或开启RDS日志备份等功能。
  • 如果您在阿里云平台授权或者提交过登录账号、密码等安全信息,建议您及时修改。

参考以下步骤,通过脚本一键式检测Linux实例中是否存在尚未分区的数据盘,并对其格式化和自动挂载。使用自动化脚本可以避免复杂的命令和步骤。如果您不想使用该脚本,可以参考Linux 格式化和挂载数据盘

警告:由于相关操作可能会导致数据丢失。 所以,执行操作之前,请务必确保已经通过快照等手段对数据进行有效备份,或明确相关数据丢失无影响。

 

前提条件

确认在Linux实例中已经安装了解压缩软件,如unzip和tar。由于Linux实例中分为普通云盘和SSD云盘,请根据现场实际情况选择以下对应的步骤。

 

普通云盘

适用于所有非I/O优化,并且挂载普通云盘的Linux实例。

  1. 参考文档远程连接 Linux 实例
  2. 执行如下命令,下载脚本文件。
     wget http://oss.aliyuncs.com/aliyunecs/auto_fdisk.tgz
  3. 执行如下命令,解压脚本文件。
    tar -zxvf auto_fdisk.tgz
  4. 使用root用户,执行如下命令,格式化并挂载文件系统。
    bash auto_fdisk.sh

    注:如果返回No free disk need to be fdisk.Exit script.可能有以下几种原因。

    • 已挂载的云盘已经完成格式化和分区。
    • 您挂载的不是普通云盘。

 

SSD云盘

适用于所有非I/O优化,并且挂载SSD云盘的Linux实例。

  1. 参考文档远程连接 Linux 实例
  2. 执行如下命令,下载脚本文件。
    wget http://aliyun_portal_storage.oss-cn-hangzhou.aliyuncs.com/help%2Fecs%2Fauto_fdisk_ssd.zip
  3. 执行如下命令,解压脚本文件。
    unzip help_ecs_auto_fdisk_ssd.zip
  4. 使用root用户,执行如下命令,格式化并挂载文件系统。
    bash auto_fdisk_ssd.sh
    系统显示类似如下。
    Step 1.No lock file,begin to create lock file and continue.
    Step 2.Begin to check free disk.

    You have a free disk,Now will fdisk it and mount it.
    This system have free disk :
    /dev/vdb
    Step 3.Begin to fdisk free disk.

    Welcome to fdisk (util-linux 2.27.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Device does not contain a recognized partition table.
    Created a new DOS disklabel with disk identifier 0xfdb33cad.

    Command (m for help): Partition type
    p primary (0 primary, 0 extended, 4 free)
    e extended (container for logical partitions)
    Select (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):
    Created a new partition 1 of type 'Linux' and of size 20 GiB.

    Command (m for help): The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.

    mke2fs 1.42.13 (17-May-2015)
    Creating filesystem with 5242624 4k blocks and 1310720 inodes
    Filesystem UUID: fb116eef-2588-433b-8aac-f482b452837c
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000

    Allocating group tables: done
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done

    Step 4.Begin to make directory
    Step 5.Begin to write configuration to /etc/fstab and mount device.
    Filesystem Size Used Avail Use% Mounted on
    udev 479M 0 479M 0% /dev
    tmpfs 100M 2.8M 97M 3% /run
    /dev/vda1 40G 1.7G 36G 5% /
    tmpfs 497M 0 497M 0% /dev/shm
    tmpfs 5.0M 0 5.0M 0% /run/lock
    tmpfs 497M 0 497M 0% /sys/fs/cgroup
    tmpfs 100M 0 100M 0% /run/user/0
    /dev/vdb1 20G 44M 19G 1% /alidata1
    注:如果返回 No free disk need to be fdisk.Exit script.可能有以下几种原因。
    • 您还没有在控制台上挂载云盘
    • 实例上挂载的云盘都已经格式化和分区。
    • 实例上挂载的不是脚本适用的磁盘类型。比如实例上挂载的是普通云盘,但是执行了bash auto_fdisk_ssd.sh命令。

 

适用于

  • 云服务器 ECS

FAQ

关于此文档暂时还没有FAQ
返回
顶部