Aliyun - Extend Linux system disk

Extended partition and file system_Linux system disk{#concept_ocb_htw_dhb .concept}

This article provides instructions on how to use the growpart and resize2fs tools to expand the partition size of the Linux system disk and expand the file system.

Applies to {#section_u9c_3g5_ljs .section}

The steps in this article are applicable to cloud disks with the following partitions and file system formats:

  • Partition format supports mbr, gpt
  • File system supports ext*, xfs, btrfs

Getting ready {#section_h25_n5w_dhb .section}

  1. Create snapshots to back up data to prevent data loss due to operational errors.

  2. Expand the cloud disk capacity through the ECS console or API .

  3. Remotely connect to the ECS instance. For connection methods, see Connection Method Navigation .

  4. Install the growpart or xfsprogs expansion formatting tool according to the operating system.

    • CentOS 7、Aliyun Linux:

      yum install cloud-utils-growpart
      yum install xfsprogs

      Ubuntu 14、Ubuntu 16、Ubuntu 18、Debian 9:

      apt install cloud-guest-utils
      apt install xfsprogs

      • Debian 8, OpenSUSE 42.3, OpenSUSE 13.1, SUSE Linux Enterprise Server 12 SP2: Please use the growpart or xfsprogs tool of the upstream version (upstream)

        Note:  When the expansion fails due to the problem of the expansion formatting tool, you can uninstall the tool and restart Install.

    • Check the kernel version of the instance, such as by uname -aviewing the kernel version.

    • Here, the CentOS 7 operating system is used as an example to demonstrate the steps of partition expansion.

    • Run fdisk -lto view the size of the existing cloud disk.

      The example returns a cloud disk (/dev/vda) with a capacity of 100GiB.

    • Operation steps of high kernel version {#section_gxq_3tw_dhb .section}

      [root@ecshost ~]# fdisk -l
      Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
      Disk identifier: 0x0008d73a
         Device Boot      Start         End      Blocks   Id  System
      /dev/vda1   *        2048    41943039    20970496   83  Linux

      Run df -hto view the partition size of the cloud disk.

      The example returns that the partition capacity (/dev/vda1) is 20GiB.

      [root@ecshost ~]# df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/vda1        20G  1.5G   18G   8% /
      devtmpfs        7.8G     0  7.8G   0% /dev
      tmpfs           7.8G     0  7.8G   0% /dev/shm
      tmpfs           7.8G  344K  7.8G   1% /run
      tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
      tmpfs           1.6G     0  1.6G   0% /run/user/0

      Run growpart <DeviceName\><PartionNumber\>and call growpart to expand the cloud disk and the corresponding number of partitions that need to be expanded.

      The example command shows expanding the first partition of the system disk.

      [root@ecshost ~]# growpart /dev/vda 1
      CHANGED: partition=1 start=2048 old: size=41940992 end=41943040 new: size=209710462,end=209712510

    • Note:  If you are using the xfs file system, run xfs_growfs /dev/vda1the expansion file system.

    • Run df -hto view the partition size of the cloud disk.

      The returned partition (/dev/vda1) is 100GiB, indicating that it has been successfully expanded

      [root@ecshost ~]# df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/vda1        99G  1.6G   93G   2% /
      devtmpfs        7.8G     0  7.8G   0% /dev
      tmpfs           7.8G     0  7.8G   0% /dev/shm
      tmpfs           7.8G  500K  7.8G   1% /run
      tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
      tmpfs           1.6G     0  1.6G   0% /run/user/0

      Operation steps of low kernel version {#section_vxq_3tw_dhb .section}

      Here, the CentOS 6 operating system is used as an example to demonstrate the steps of partition expansion.

    • Install the dracut-modules-growroot tool.

      [root@ecshost ~]# yum install -y dracut-modules-growroot

    • If you are using other package managers, please modify yum to the corresponding command.

    • Overwrite existing initramfs files.

      [root@ecshost ~]# dracut -f

      Run fdisk -lto view the size of the existing cloud disk.

      The example returns a cloud disk (/dev/vda) with a capacity of 100GiB.

      [root@ecshost ~]# fdisk -l
      Disk /dev/vda: 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: 0x0003a7b4
         Device Boot      Start         End      Blocks   Id  System
      /dev/vda1   *           1        2611    20970496   83  Linux

      Run df -hto view the partition size of the cloud disk.

      The example returns that the partition capacity (/dev/vda1) is 20GiB.

      [root@ecshost ~]# df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/vda1        20G  1.1G   18G   6% /
      tmpfs           7.8G     0  7.8G   0% /dev/shm

      Run growpart <DeviceName\><PartionNumber\>and call growpart to expand the cloud disk and the corresponding number of partitions that need to be expanded.

      The example command shows expanding the first partition of the system disk.

      [root@ecshost ~]# growpart /dev/vda 1
      CHANGED: partition=1 start=2048 old: size=41940992 end=41943040 new: size=209710462,end=209712510

    • Reboot the instance on the console or call the API RebootInstance. For detailed steps, see Reboot Instance and RebootInstance .

    • Remotely connect to the instance again.

    • Run resize2fs <PartitionName\>and call resize2fs to expand the file system.

      The example command shows expanding the file system for the /dev/vda1 partition of the system disk.

      [root@ecshost ~]# resize2fs /dev/vda1
      resize2fs 1.41.12 (17-May-2010)
      Filesystem at /dev/vda1 is mounted on /; on-line resizing required
      old desc_blocks = 2, new_desc_blocks = 7
      Performing an on-line resize of /dev/vda1 to 26213807 (4k) blocks.
      The filesystem on /dev/vda1 is now 26213807 blocks long.

    • Note:  If you are using the xfs file system, run xfs_growfs /dev/vda1the expansion file system.

    • Run df -hto view the partition size of the cloud disk.

      The returned partition (/dev/vda1) is 100GiB, indicating that the capacity has been expanded successfully.

      [root@ecshost ~]# df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/vda1        99G  1.1G   93G   2% /
      tmpfs           7.8G     0  7.8G   0% /dev/shm

Guess you like

Origin blog.csdn.net/lmrylll/article/details/131272799