{"id":15,"date":"2016-05-24T15:03:36","date_gmt":"2016-05-24T21:03:36","guid":{"rendered":"http:\/\/peterod.azurewebsites.net\/?p=15"},"modified":"2016-05-24T15:03:36","modified_gmt":"2016-05-24T21:03:36","slug":"step-by-step-how-to-resize-a-linux-vm-os-disk-in-azure-arm","status":"publish","type":"post","link":"http:\/\/www.perktime.org\/index.php\/2016\/05\/24\/step-by-step-how-to-resize-a-linux-vm-os-disk-in-azure-arm\/","title":{"rendered":"Step by Step: how to resize a Linux VM OS disk in Azure (ARM)"},"content":{"rendered":"<h3><strong>Update 06\/18\/2018: This article has been superseded by this one from Azure support: <a href=\"https:\/\/blogs.msdn.microsoft.com\/linuxonazure\/2017\/04\/03\/how-to-resize-linux-osdisk-partition-on-azure\">https:\/\/blogs.msdn.microsoft.com\/linuxonazure\/2017\/04\/03\/how-to-resize-linux-osdisk-partition-on-azure <\/a><\/strong><\/h3>\n<p>The default OS disk size for most Linux distros in Azure is 30GB. While Linux makes it easy to add other disks as mount points, you may wish to increase the size of the OS disk using the steps in this article.<br \/>\nHere\u2019s what you need to do. I used a CentOS 6.8 Linux VM from the Azure Marketplace in this example. Default filesystem is ext4. With CentOS\/RHEL 7.x, the default file system is XFS. <strong><em>On Ubuntu it is not necessary to do steps 2-11 as it automatically will resize the disk on boot.<\/em><\/strong><br \/>\n<strong>Note: Before proceeding it\u2019s highly recommended that you backup your Azure VM first. <\/strong>You can do this using Azure Backup or use AzCopy to make a copy of your VHD.<br \/>\n1) Resize the OS disk using these PowerShell cmdlets or the Azure CLI. The VM needs to be in stopped (deallocated) state to run these commands<br \/>\nPowerShell:<br \/>\n$rg = \u201cYourResourceGroupName\u201d<br \/>\n$vmName = \u201cYourVMName\u201d<br \/>\n$vm = Get-AzureRmVM -ResourceGroupName $rg -Name $vmName<br \/>\n$vm.StorageProfile[0].OSDisk[0].DiskSizeGB = 127\u00a0 # change the size as required<br \/>\nUpdate-AzureRmVM \u2013ResourceGroupName $rg -VM $vm<br \/>\n&nbsp;<br \/>\nAzure CLI:<br \/>\naz vm update &#8211;resource-group YourResourceGroupName &#8211;name YourVMName &#8211;set storageProfile.osDisk.diskSizeGB=1024<br \/>\n&nbsp;<br \/>\n2) Start your Linux VM. Login to your Azure VM using SSH:<br \/>\n<a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/05\/image733.png\"><img decoding=\"async\" loading=\"lazy\" style=\"border-width: 0px; padding-top: 0px; padding-right: 0px; padding-left: 0px;\" title=\"image\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2016\/05\/image_thumb600.png\" alt=\"image\" width=\"525\" height=\"327\" border=\"0\" \/><\/a><br \/>\nAs you can see the OS disk is 30GB.<br \/>\n3) Run this command: sudo fdisk \/dev\/sda<br \/>\n4) Type \u201cu\u201d to change the units to sectors.<br \/>\n5) Type \u201cp\u201d to list the current partition details. Note the starting sector (e.g. 2048).<br \/>\n6) Once you are in fdisk, delete the partition (note: you aren\u2019t deleting the data, just altering the partition table). Type \u201cd\u201d and then select the partition (if required as it will choose partition 1 if it\u2019s the only partition).<br \/>\n7) Create a new partition with \u201cn\u201d. Type p to create a primary partition. Type 1 to create the first partition (or another partition number, if required). Use the same starting sector from step 5 and use the desired end sector or accept the default end sector to use the entire disk.<br \/>\n8) Type \u201ca\u201d and select partition 1 to mark the boot partition as active. Type \u201cp\u201d to to ensure all settings are correct:<br \/>\n<a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/01\/image54.png\"><img decoding=\"async\" loading=\"lazy\" style=\"border-width: 0px; padding-top: 0px; padding-right: 0px; padding-left: 0px;\" title=\"image\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/01\/image_thumb24.png\" alt=\"image\" width=\"529\" height=\"319\" border=\"0\" \/><\/a><br \/>\n9) Write the partition with \u201cw\u201d. You will get a warning that says: <em>WARNING: Re-reading the partition table failed with error 16: Device or resource busy.<\/em> This is normal.<br \/>\n10) Reboot using \u201csudo reboot\u201d<br \/>\n11) Once the VM is up and running, login to your Azure VM using SSH and type \u201csudo resize2fs \/dev\/sdaX\u201d to resize the filesystem for CentOS\/RHEL 6.x (where X is the partition number you created in step 7. In CentOS\/RHEL 7.x the command is \u201cxfs_growfs -d \/dev\/sdaX\u201d. This may take some time to complete.<br \/>\n12) Verify the new size with df -h<br \/>\n<a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/01\/image55.png\"><img decoding=\"async\" loading=\"lazy\" style=\"border-width: 0px; padding-top: 0px; padding-right: 0px; padding-left: 0px;\" title=\"image\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/2017\/01\/image_thumb25.png\" alt=\"image\" width=\"519\" height=\"315\" border=\"0\" \/><\/a><br \/>\n&nbsp;<br \/>\nNow go and enjoy your new bigger OS disk!<br \/>\n<strong>Updated 1\/3\/2017: Thanks to Terry Charles for noting that step 8 to mark the boot partition was inadvertently omitted. Also, thanks to rhelguy and Sherif Adel for the correct resize command for CentOS\/RHEL 7.x. <\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update 06\/18\/2018: This article has been superseded by this one from Azure support: https:\/\/blogs.msdn.microsoft.com\/linuxonazure\/2017\/04\/03\/how-to-resize-linux-osdisk-partition-on-azure The default OS disk size for most Linux distros in Azure is 30GB. While Linux makes it easy to add other disks as mount points, you may wish to increase the size of the OS disk using the steps in this &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.perktime.org\/index.php\/2016\/05\/24\/step-by-step-how-to-resize-a-linux-vm-os-disk-in-azure-arm\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Step by Step: how to resize a Linux VM OS disk in Azure (ARM)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/posts\/15"}],"collection":[{"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.perktime.org\/index.php\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}