Create Linux VM with larger OS disk in Azure

Create Linux VM with larger OS disk in Azure

Linux OS disk is 30 GB by default in Azure. Develop environment requires larger OS disk, you can do it by following steps. (For production environment, OS disk is only for OS, you should mount separate data disk for your request.)

  1. Create new VM.
  2. Expand OS disk
  3. Recognize the OS disk changes in VM
  4. Create custom image
  5. Create VMs from the image

Note: Achieve the target via Azure CLI 2.0 in this document.
Limitation: Create VM from customized image can only succeed within the same resource group.

Create VM

  • Create resource group

az group create --name royhk --location eastasia

  • Create VM
az vm create --resource-group royhk \   
     --name RoyRedhat \  
     --image RHEL \  
     --public-ip-address "" \  
     --size Standard_E8s_v3 \  
     --admin-username redhat \  
     --generate-ssh-keys
  • ssh to the VM and check partition.

ssh redhat@172.16.1.5

[redhat@RoyRedhat ~]$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0      2:0    1    4K  0 disk 
sda      8:0    0   32G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
└─sda2   8:2    0 31.5G  0 part /
sdb      8:16   0  128G  0 disk 
└─sdb1   8:17   0  128G  0 part /mnt/resource
sr0     11:0    1  628K  0 rom 

verify that root disk / was in /dev/sda2, we need this info for fdisk command later.

Expand OS disk

  • Deallocate VM

az vm deallocate -g royhk -n RoyRedhat

  • Expand OS disk size

check disk

az disk list -g royhk -o table

expand size

az disk update -g royhk -n RoyRedhat_OsDisk_1_55f7af3d651548b49ce9971420023d7d --size-gb 100

Recognize the OS disk changes in VM

  • Start VM

az vm start -g royhk -n RoyRedhat

  • ssh to VM; delete and re-create partion (data will not be lost)
[root@RoyRedhat ~]# fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!).

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x0008c758

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2              64        4178    33041408   83  Linux

Command (m for help): d
Partition number (1,2, default 2): 
Partition 2 is deleted

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 
First cylinder (64-13054, default 64): 
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-13054, default 13054): 
Using default value 13054
Partition 2 of type Linux and of size 99.5 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

Note: you can ignore the WARNING message.

  • Tell the Linux kernel about the presence and numbering of on-disk partitions

partx -u /dev/sda2

  • resize the disk

xfs_growfs -d /dev/sda2

  • verify

df -h

[root@RoyRedhat ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       100G  2.7G   97G   3% /
devtmpfs         32G     0   32G   0% /dev
tmpfs            32G     0   32G   0% /dev/shm
tmpfs            32G  8.3M   32G   1% /run
tmpfs            32G     0   32G   0% /sys/fs/cgroup
/dev/sda1       497M  117M  380M  24% /boot
/dev/sdb1       126G  2.1G  118G   2% /mnt/resource
tmpfs           6.3G     0  6.3G   0% /run/user/1000

Create custom image

tutorial-custom-images

To create an image of a virtual machine, you need to prepare the VM by deprovisioning, deallocating, and then marking the source VM as generalized.

  • Deprovision the VM

    Deprovisioning generalizes the VM by removing machine-specific information. During deprovisioning, the host name is reset to localhost.localdomain. SSH host keys, nameserver configurations, root password, and cached DHCP leases are also deleted.

ssh redhat@172.16.1.5
sudo waagent -deprovision+user -force
exit

  • Deallocate VM

az vm deallocate -g royhk -n RoyRedhat

  • mark the VM as generalized

az vm generalize --resource-group royhk --name RoyRedhat

  • Create the image

az image create -g royhk \
-n redhat100gImage \
--source RoyRedhat

Create VMs from the image

az vm create -g royhk -n royVMfromImage --image redhat100gImage --generate-ssh-keys

Verify:

[centos@royVMfromImage ~]$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       100G  2.7G   97G   3% /
devtmpfs        1.7G     0  1.7G   0% /dev
tmpfs           1.7G     0  1.7G   0% /dev/shm
tmpfs           1.7G  8.3M  1.7G   1% /run
tmpfs           1.7G     0  1.7G   0% /sys/fs/cgroup
/dev/sda1       497M  117M  380M  24% /boot
/dev/sdb1       6.8G  2.1G  4.4G  32% /mnt/resource
tmpfs           344M     0  344M   0% /run/user/1000
[centos@royVMfromImage ~]$ ls /usr/java
jdk1.8.0_162
[centos@royVMfromImage ~]$

Customized packages, data disk and expanded OS disk are kept in new created VM.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,772评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,458评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,610评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,640评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,657评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,590评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,962评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,631评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,870评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,611评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,704评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,386评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,969评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,944评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,179评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,742评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,440评论 2 342

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,279评论 0 10
  • 欢迎大家给我发私信线下一起交流沟通,私信即有惊喜健身好礼免费赠送!! 我们都知道,下拉这个练背的经典动作有两个版本...
    硬刻时代阅读 3,573评论 0 5
  • Android多国语言文件夹文件汇总如下: 中文(中国):values-zh-rCN 中文(台湾):values-...
    JasonLdj阅读 682评论 0 1
  • 昨晚第一次去听直播课,老师讲的是如何画这只狗狗,可惜我只听了前面一小时,毛发怎么画的不知道。结果我回来后画的是只剃...
    Margaret_liu阅读 280评论 0 0
  • 公交车上 夏日困乏 我坐在后排靠门口的第一排座位 , 爱心座的位置上坐着一个同校的男孩子, 很长一段时间我都记不起...
    df7148fa875c阅读 99评论 0 0