Can we assign a Data Disk space to OS Disk in Linux VM

Abhishek Verma 26 Reputation points
2022-05-30T07:28:49.217+00:00

I have 128 GB of OS Disk space on a Ubuntu Linux VM.
As I wanted to increase its size, I attached a new Data Disk of 512 GB to the existing VM but instead of adding space to the OS disk, a new partition got created. Later, I figured out that there existed a Resizing option to increase the OS Disk size.
But seems like I already messed it up.

Is it possible to use the space of the newly made partition of 512 GB OS Data Disk to increase the size of the existing OS Disk?
Like if we can assign some space of Data Disk to OS Disk.

If possible, how can I do that?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
668 questions
0 comments No comments
{count} votes

Accepted answer
  1. srbhatta-MSFT 8,586 Reputation points Microsoft Employee
    2022-05-30T09:24:42.973+00:00

    Hello @Abhishek Verma ,
    Thanks for reaching out to Microsoft QnA. Happy to answer your query.
    OS disk is separate from Data disks, and we cannot shrink the size of a data disk and add that space to OS disk. What you can do is resize the OS disk from the Portal under Size+Performance under the OS disk tab.
    Once the OS disk has been resized, you can SSH into your VM and do a lsblk, you will see the new size of the disk. Now, you can either increase the size of any of the existing partition of the OS disk, or create a new partition.

    To create a new partition, or resize an existing partition of the OS disk, please follow the steps mentioned here : Expand the OS disk of a Linux VM .

    I have done a repro in my lab, I am attaching the commands there. i expanded the size of the OS disk from 64gb to 128 gb, and created a new partition sda3 of 64 gb. We have to then format the partition and mount it on a mountpoint.
    Here are the steps : demo.
    After following these steps format the partition with the required file system. For eg:
    sudo mkfs -t ext4 /dev/sda3
    lsblk -f
    sudo mkdir mntpnt (Creating a mountpoint to mount sda3)
    sudo mount /dev/sda3 mntpnt (Mounting sda3 to mountpoint mntpnt)

    Hope this helps.

    ----------------------

    Please accept as answer and upvote if the information provided was helpful.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.