• 扩容Azure免费虚拟机的硬盘大小


    微软免费使用一年的Azure虚拟机,默认提供了一个64G的磁盘,但是系统却只给分配了32个G,尝试了几次扩大分区,最终都导致系统崩溃了,只能重新开虚拟机,无奈,只好网上找来现成的脚本,自动调整分区大小,只需要输入想调整为多少G即可,终于成功把系统分区扩大了。

    更改分区大小的脚本:

    if [[ $# -eq 0 ]] ; then
        echo 'please tell me the device to resize as the first parameter, like /dev/sda'
        exit 1
    fi
    
    
    if [[ $# -eq 1 ]] ; then
        echo 'please tell me the partition number to resize as the second parameter, like 1 in case you mean /dev/sda1 or 4, if you mean /dev/sda2'
        exit 1
    fi
    
    DEVICE=$1
    PARTNR=$2
    APPLY=$3
    
    fdisk -l $DEVICE$PARTNR >> /dev/null 2>&1 || (echo "could not find device $DEVICE$PARTNR - please check the name" && exit 1)
    
    CURRENTSIZEB=`fdisk -l $DEVICE$PARTNR | grep "Disk $DEVICE$PARTNR" | cut -d' ' -f5`
    CURRENTSIZE=`expr $CURRENTSIZEB / 1024 / 1024`
    # So get the disk-informations of our device in question printf %s\\n 'unit MB print list' | parted | grep "Disk /dev/sda we use printf %s\\n 'unit MB print list' to ensure the units are displayed as MB, since otherwise it will vary by disk size ( MB, G, T ) and there is no better way to do this with parted 3 or 4 yet
    # then use the 3rd column of the output (disk size) cut -d' ' -f3 (divided by space)
    # and finally cut off the unit 'MB' with blanc using tr -d MB
    MAXSIZEMB=`printf %s\\n 'unit MB print list' | parted | grep "Disk ${DEVICE}" | cut -d' ' -f3 | tr -d MB`
    
    echo "[ok] would/will resize to from ${CURRENTSIZE}MB to ${MAXSIZEMB}MB "
    
    if [[ "$APPLY" == "apply" ]] ; then
      echo "[ok] applying resize operation.."
      parted ${DEVICE} resizepart ${PARTNR} ${MAXSIZEMB}
      echo "[done]"
    else
      echo "[WARNING]!: Sandbox mode, i did not size!. Use 'apply' as the 3d parameter to apply the changes"
    fi

    该脚本来自:https://serverfault.com/questions/870594/resize-partition-to-maximum-using-parted-in-non-interactive-mode

    沙箱模式,用于预览可能发生的变化:./resize.sh /dev/sda 1

    如果确认没问题,可以使用:./resize.sh /dev/sda 1 apply

    其中1是指第一个分区

    扩展空间成功后,只是分区变大了,文件系统还是原来的大小,就是通过df命令看,还是32G,这时候,需要使用resize2fs指令:resize2fs /dev/sda1

    执行完后,再用df -h查看,空间已经变大了。

  • 相关阅读:
    如何利用京东云的对象存储(OSS)上传下载文件
    2017年4月8日Office 365 使用CSV文件导入邮件组
    在Office 365 的如何给管理员赋予查看所有人邮箱的权限的Powershell
    Office 365 Powershell 连接命令
    Office365创建通讯组
    国际版删除域名的步骤
    如何停止AAD服务
    导出Office365中的组及成员
    AWS/阿里/Azure,云厂商价格大PK
    OA系统与Exchange 日历打通
  • 原文地址:https://www.cnblogs.com/easyc/p/expand_azure_free_vm_os_disk_space.html
Copyright © 2020-2023  润新知