Increase Azure Linux VM Disk Size

  • fennng 

After:

Before:

When I created my Linux on Azure, I used the default 30G size. I used it up after 1 year. Then I had to increased the disk size. I decided to increase the disk size to 60G. I did this on Azure portal, it’s pretty straightforward.

I stopped my VM and increased the disk size then restarted my VM. But nothing has changed.

I then found this link, then I realized that Azure portal didn’t do all the magics for me, I had to increase the partition manually.

https://docs.microsoft.com/en-us/azure/virtual-machines/linux/expand-disks

But the way shown on this page didn’t help me, I got the following error on the first step. I couldn’t continue.

fennng@fengUbuntu3:~$ sudo umount /dev/sda1
umount: /: target is busy.

Then I found this page.
https://lnx.azurewebsites.net/resizing-a-linux-vm-system-disk-in-microsoft-azure/

Above page shows the right way to do it, but when I first time tried it, I got the following error.

Command (m for help): w
GPT PMBR size mismatch (62914559 != 125829119) will be corrected by w(rite).
fdisk: failed to write disklabel: Invalid argument

Then I found another link for the solution

https://serverfault.com/questions/716270/resizing-partition-fdisk-fails-with-invalid-argument

To Summarize, I needed to run parted to fix the GPT then run the fdisk command to rewrite the partition table. Then use resize2fs command to make it take affect. Restarting the VM is not necessary. I can do this online, even it’s a system partition.

The following are the full steps:

fennng@fengUbuntu3:~$ sudo parted
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) print
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 62914560 blocks) or continue with the current
setting?
Fix/Ignore? Fix
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
14 1049kB 5243kB 4194kB bios_grub
15 5243kB 116MB 111MB fat32 boot, esp
1 116MB 32.2GB 32.1GB ext4

(parted)

fennng@fengUbuntu3:~$ sudo fdisk /dev/sda

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

Command (m for help): m

Help:

Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition

Misc
m print this menu
x extra functionality (experts only)

Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file

Save & Exit
w write table to disk and exit
q quit without saving changes

Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table

Command (m for help): p
Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 86027915-3219-49D0-BD7B-9D73DBA28691

Device Start End Sectors Size Type
/dev/sda1 227328 62914526 62687199 29.9G Linux filesystem
/dev/sda14 2048 10239 8192 4M BIOS boot
/dev/sda15 10240 227327 217088 106M EFI System

Partition table entries are not in disk order.

Command (m for help): d
Partition number (1,14,15, default 15): 1

Partition 1 has been deleted.

Command (m for help): n
Partition number (1-13,16-128, default 1): 1
First sector (34-125829086, default 227328):
Last sector, +sectors or +size{K,M,G,T,P} (227328-125829086, default 125829086):

Created a new partition 1 of type 'Linux filesystem' and of size 59.9 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): w

The partition table has been altered.
Syncing disks.

fennng@fengUbuntu3:~$ sudo resize2fs /dev/sda1
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 8
The filesystem on /dev/sda1 is now 15700219 (4k) blocks long.

fennng@fengUbuntu3:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.7G 0 1.7G 0% /dev
tmpfs 344M 1.8M 343M 1% /run
/dev/sda1 58G 27G 32G 46% /
tmpfs 1.7G 0 1.7G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup
/dev/sda15 105M 3.4M 102M 4% /boot/efi
tmpfs 344M 0 344M 0% /run/user/1000
标签:

《Increase Azure Linux VM Disk Size》有2个想法

  1. Just followed my own guide to increase my vm disk to 128G, I almost forgot everything in this article, found it very useful, time saver.

  2. Interesting, when I increased the VM disk size, my scratch disk (used as swap) has been increased from 3.9G to 6.9G too.

    fennng@fengUbuntu3:~/Dropbox/fengUbuntu/fengdrawbot2$ df -h
    Filesystem Size Used Avail Use% Mounted on
    udev 1.7G 0 1.7G 0% /dev
    tmpfs 342M 1.9M 341M 1% /run
    /dev/sda1 117G 43G 74G 37% /
    tmpfs 1.7G 0 1.7G 0% /dev/shm
    tmpfs 5.0M 0 5.0M 0% /run/lock
    tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup
    /dev/sda15 105M 3.4M 102M 4% /boot/efi
    /dev/sdb1 6.9G 3.9G 2.7G 60% /mnt
    tmpfs 342M 0 342M 0% /run/user/1000
    fennng@fengUbuntu3:~/Dropbox/fengUbuntu/fengdrawbot2$

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注