Extend Linux OS Volume in Cloud

Extend Linux OS Volume in Cloud"Whenever the OS disk is expanded in cloud environment, the partition table should be corrected in the OS and filesystem needs to be extended as well."Here are steps to extend Linux Volume. This may be applied to all Linu
摘要由CSDN通过智能技术生成

目录

Extend Linux OS Volume in Cloud

Part 1 MBR Partition Table

Part 2 GPT Partition Table


"Whenever the OS disk is expanded in cloud environment, the partition table should be corrected in the OS and filesystem needs to be extended as well."

Here are steps to extend Linux Volume. This may be applied to all Linux distros.

Part 1 MBR Partition Table

  1. SSH to the VM.
  2. Check the name of disk you expand in Cloud Provider Console. In this scenario, I expand the /dev/sda from 30GB to 50GB.

sudo fdisk -l

(If there is an error like bellow, that means the disk has GPT partition table. Please jump to Part 2 to continue.)

     3.Check the filesystem of the last disk partition. Usually there are two types “ext4” and “xfs”. In my scenario, /dev/sda has "xfs" filesystem.

df -Th

     4.Modify partition table.

    sudo fdisk /dev/sda

  • Command: d (This will delete the partition table but it won’t delete data on the disk)
  • Partition number: (Press Enter if to keep default value)
  • Command: n (Create a new partition)
  • Select: P
  • Partition number: (Press Enter if to keep default value)
  • First Sector: (Press Enter if to keep default value)
  • Last sector: (Press Enter to keep default value if don’t need to create more partitions)
  • Command:  p (Verify the partition table and check if the partition is in the new size)

  • Command: w (Save the partition table, before this you can quit at any time to discard all modifications)

      5.Reboot the VM.

      6.Extend the file system.

  • If the filesystem is “xfs” in step 3, run command bellow:

      sudo xfs_growfs /dev/sda2

  • If the filesystem is “ext4” in step 3, run command bellow:

      sudo resize2fs /dev/sda2

(If there is an error “/dev/sda2 is not a mounted XFS filesystem”, please use mount point like ‘/’ instead of disk name)

       7.Verify the filesystem.

 

Part 2 GPT Partition Table

  1. SSH to the VM
  2. Check the label of disk you expand. In this scenario, I expand the /dev/sda from 30GB to 70GB.

sudo fdisk -l

    3.Check the filesystem of the last disk partition. Usually there are two types “ext4” and “xfs”. In this scenario, /dev/sda has "xfs" filesystem.

df -Th

 

    4.Fix the GPT table.

sudo parted /dev/sda unit s print

  • Fix/Ignore/Cancel? Fix
  • Fix/Ignore? Fix

(If there is no error displayed, that means it succeeds.)

 

    5.Modify partition table.

sudo fdisk /dev/sda

  • Command: d (This will delete the partition table but it won’t delete data on the disk)
  • Partition number: (Press Enter if to keep default value)
  • Command: n (Create a new partition)
  • Select: P
  • Partition number: (Press Enter if to keep default value)
  • First Sector: (Press Enter if to keep default value)
  • Last sector: (Press Enter to keep default value if don’t need create more partitions)
  • Command:  p (Verify the partition table and check if the partition is in the new size)

  • Command: w (Save the partition table, before this you can quit at any time to discard all modifications)

     6.Reboot the VM

     7.Extend the file system.

  • If the file system is “xfs” in step 3, run command bellow:

sudo xfs_growfs /

(Don’t use disk name here. If the partition was not mounted on ‘/’, please change ‘/’ to the right mount point)

  • If the file system is “ext4” in step 3, run command bellow:

sudo resize2fs /

(Don’t use disk name here. If the partition was not mounted on ‘/’, please change ‘/’ to the right mount point)

    8.Verify the file system

df -Th

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值