Tutorial on extending the root file system on a Linux Virtual Machine
Problem description
By default, Linux virtual machines deployed on the Azure platform have limited root file system capacity and need to be expanded.
Problem Analysis
By default, Linux virtual machines deployed on the Azure platform have a relatively small root file system capacity. during use, the root file system is often full, resulting in unavailability of virtual machines, you need to manually resize the root file system.
Solution Important
Before performing the following operations, you must back up the system disk of the VM. The following steps are based on CentOS 6.8. Other Linux versions may differ slightly.
Important
In CentOS 7.x, the default root partition is/dev/sda2. You only need to expand the/dev/sda2 partition and do not need to activate it.
- Disable virtual machines through the Azure portal.
Run the following Powershell command to expand the system disk:
Get-AzureVM-ServiceName "vfldev"-Name "vfldev" | get-AzureOSDisk # Replace the preceding parameters with the correct ServiceName and VM Name. Update-AzureDisk-DiskName "vfldev-vfldev-0-201503091934500547"-Label "ResiZedOS"-ResizedSizeInGB 100 # Replace the DiskName with the name of the OSdisk obtained in step 1 and enter the disk size you want to resize.
Start the VM through the Azure portal.
Log on to the virtual machine and switch to the root user to view the root file system capacity of the current virtual machine.
[root@resizeSDA chpaadmin]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 30G 1.1G 27G 4% /devtmpfs 832M 0 832M 0% /devtmpfs 840M 0 840M 0% /dev/shmtmpfs 840M 8.3M 832M 1% /runtmpfs 840M 0 840M 0% /sys/fs/cgroup/dev/sdb1 69G 53M 66G 1% /mnt/resource
Open a partition table
[Root @ resizeSDA chpaadmin] # fdisk/dev/sdaWelcome 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): pDisk/dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1*512 = 512 bytesSector size (logical/physical ): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes /512 bytesDisk label type: dosDisk identifier: 0x00093e4e # record the partition information Device Boot Start End Blocks Id System/dev/sda1 * 2048 62914559 31456256 83 Linux # Switch to the Command (m for help) with the sector as the computing unit ): uChanging display/entry units to sectors. # if the preceding content is displayed, proceed to the next step. If it is displayed as Command (m for help): uChanging display/entry units to cylinders (DEPRECATED !). # Run the "u" command and switch to "sector. # Delete partition Command (m for help): dSelected Partition 1 partition 1 is deleted # create Partition Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): First sector (2048-209715199, default 2048 ): using default value 2048 Last sector, + sectors or + size {K, M, G} (2048-209715199, default 209715199): Using default value 209715199 Parti Tion 1 of type Linux and of size 100 GiB is set # After the partition is modified, print the partition information and confirm that the information is correct. Command (m for help): pDisk/dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1*512 = 512 bytesSector size (logical/physical): 512 bytes/512 bytesI/O size (minimum/optimal ): 512 bytes/512 bytesDisk label type: dosDisk identifier: 0x00093e4e # note that the start value here must be consistent with the information in the previous Partition Table: Device Boot Start End Blocks Id System/dev/sda1 2048 209715199 104856576 83 Linux # activate the partition Command (m for help): aSelected partition 1 # print the partition again, confirm that the Command (m for help) is activated: pDisk/dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectorsUnits = sectors of 1*512 = 512 bytesSector size (logical/physical ): 512 bytes/512 bytesI/O size (minimum/optimal): 512 bytes/512 bytesDisk label type: dosDisk identifier: 0x00093e4e De Vice Boot Start End Blocks Id System/dev/sda1 * 2048 209715199 104856576 83 Linux # if the information is incorrect or you are not sure, please contact us in time. If the information is correct, write partition table Command (m for help): wrThe 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 atthe next reboot or after you run partprobe (8) or kpartx (8) Syncing disks.
After the partition table is modified, restart the VM.
[root@resizeSDA chpaadmin]# init 6
Log on to the VM, switch to the root user, and check the capacity of the current root file system.
[root@resizeSDA chpaadmin]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 30G 1.1G 27G 4% /devtmpfs 832M 0 832M 0% /devtmpfs 840M 0 840M 0% /dev/shmtmpfs 840M 8.3M 832M 1% /runtmpfs 840M 0 840M 0% /sys/fs/cgroup/dev/sdb1 69G 53M 66G 1% /mnt/resource
Modify the size of the root file system.
[root@resizeSDA chpaadmin]# resize2fs /dev/sda1resize2fs 1.42.9 (28-Dec-2013)Filesystem at /dev/sda1 is mounted on /; on-line resizing requiredold_desc_blocks = 4, new_desc_blocks = 13The filesystem on /dev/sda1 is now 26214144 blocks long.
Check the root file system size.
[root@resizeSDA chpaadmin]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 99G 1.1G 93G 2% /devtmpfs 832M 0 832M 0% /devtmpfs 840M 0 840M 0% /dev/shmtmpfs 840M 8.3M 832M 1% /runtmpfs 840M 0 840M 0% /sys/fs/cgroup/dev/sdb1 69G 53M 66G 1% /mnt/resource
At this point, the root file system has been resized. Visit http://market.azure.cn now