We highly recommend that you set the access method to ssh public key
. If you lose VM access during the encryption set up procedures, the only reliable access method is ssh public key
. To do so:
Release the OS disk from the VM. To do this, you must delete the VM from Azure.
Create another VM in the same Resource Group and the same Location. This VM needs to be able to see the OS disk on the original VM, because Linux does not support the online resize of a mounted file system.
In our examples we will call this newly created VM /dev/sdc3
.
Attach the OS disk to the new VM. To do so:
dmesg
to find out the device name. In the case of a new Ubuntu 14.04 server, it shows as /dev/sdc
.Resize the root file system on this device to create enough space for a separate boot partition. For example:
Mount the root partition:
# mkdir /tmp/root # mount -o ro /dev/sdc1 /tmp/root
Find out the space required by /boot
subtree,
# du -sh /tmp/root/boot 178M /tmp/root/boot # umount /tmp/root
The new boot partition should at least have two times the amount of space used by /boot
.
The following three steps are required to shrink the original root file system and create a new /boot
partition.
# e2fsck -f /dev/sdc1 # resize2fs /dev/sdc1 <newsize> # fdisk -u /dev/sdc
Note: | Assuming that the size of /dev/sdc1 is 10 GB originally, we have to cut out 500 MB (Considering max size of /boot ) from it. The following is the example of the resize2fs command:
|
# resize2fs /dev/sdc1 9G
Here, the filesystem size will get reduced by 1 GB, out of which 500 MB will be allocated to /boot
.
We will have to delete and recreate the root partition, ensure that the new root partition starts at exactly the same block, and that its size is equal to or greater than the new size of the root file system (after we have run resize2fs
). As a rule of thumb, the size of the new root partition should be 100 MB more than new size of the root file system. Remember to set the boot flag on the root partition.
Here is the actual output on a test machine:
root@prmub1604:~# e2fsck -f /dev/sdc1 e2fsck 1.42.13 (17-May-2015) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdc1: 11/655360 files (0.0% non-contiguous), 79663/2621184 blocks root@prmub1604:~# resize2fs /dev/sdc1 9G resize2fs 1.42.13 (17-May-2015) Resizing the filesystem on /dev/sdc1 to 2359296 (4k) blocks. The filesystem on /dev/sdc1 is now 2359296 (4k) blocks long. root@prmub1604:~# fdisk -u /dev/sdc Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 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: dos Disk identifier: 0x3795c63b Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 20971519 20969472 10G 83 Linux Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): p Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 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: dos Disk identifier: 0x3795c63b Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-20971519, default 2048): 2048 Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +9G Created a new partition 1 of type 'Linux' and of size 9 GiB. Command (m for help): p Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 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: dos Disk identifier: 0x3795c63b Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 18876415 18874368 9G 83 Linux Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): 2 First sector (18876416-20971519, default 18876416): 18876416 Last sector, +sectors or +size{K,M,G,T,P} (18876416-20971519, default 20971519): +500M Created a new partition 2 of type 'Linux' and of size 500 MiB. Command (m for help): p Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 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: dos Disk identifier: 0x3795c63b Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 18876415 18874368 9G 83 Linux /dev/sdc2 18876416 19900415 1024000 500M 83 Linux Command (m for help): a Partition number (1,2, default 2): 1 The bootable flag on partition 1 is enabled now. Command (m for help): p Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 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: dos Disk identifier: 0x3795c63b Device Boot Start End Sectors Size Id Type /dev/sdc1 * 2048 18876415 18874368 9G 83 Linux /dev/sdc2 18876416 19900415 1024000 500M 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. root@prmub1604:~#
Now we have two partitions on the same disk: one is with 9 GB, and another for /boot
with 500 MB.
What to Do Next
Recreate the VM in Azure and make a template from the VM as described in Recreating the VM in Azure.