微软Azure在LINUX的虚拟机提供了30GB的系统磁盘空间,这30GB的系统磁盘空间按照道理来说肯定够广大用户所使用。但是,经常有些操作人员的粗心,导致系统盘占据很大的空间。另外,由于微软对操作系统盘做了很多的优化,不建议在这里存放其他应用程序。
今天我们就给大家介绍一下如何增加操作系统盘的空间
首先,我们看一下我的一个虚拟机的磁盘情况,其/dev/sda1已经被使用了挺大的空间,并且没有其他数据盘在其中;切记不要再/dev/sdb1中存放数据,否则在虚拟机deallocate后,将数据丢失,无法找回;
接下来我们开始,增加操作系统盘的步骤;
1. 关闭目标虚拟机;
2. 通过CLI,将提高磁盘容量到512GB。
增加磁盘大小之前,需要磁盘 ID 或名称
az disk list -g xxxxx --query '[*].{Name:name,Gb:diskSizeGb,Tier:accountType}' --output table
az disk update --name xxxxx_OsDisk_1_b63ce1af58344133a74947d87a60e05a
-g xxxxx--size-gb 512
3. 启动虚拟机
4. 进入虚拟机后,打开分区表
[xxxxx@xxxxx ~]$ sudo 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): p
Disk /dev/sda: 1098.4 GB, 1098437885952 bytes, 2145386496 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
Disk label type: dos
Disk identifier: 0x000c1fec
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 * 1026048 2145386495 1072180224 83 Linux
Command (m for help): 2
2: unknown command
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted
Command (m for help): p
Disk /dev/sda: 1098.4 GB, 1098437885952 bytes, 2145386496 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
Disk label type: dos
Disk identifier: 0x000c1fec
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
Command (m for help):
Command (m for help):
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): 2
First sector (1026048-2145386495, default 1026048):
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-2145386495, default 2145386495):
Using default value 2145386495
Partition 2 of type Linux and of size 1022.5 GiB is set
Command (m for help): p
Disk /dev/sda: 1098.4 GB, 1098437885952 bytes, 2145386496 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
Disk label type: dos
Disk identifier: 0x000c1fec
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 2145386495 1072180224 83 Linux
Command (m for help): a
Partition number (1,2, default 2): 2
Command (m for help): p
Disk /dev/sda: 1098.4 GB, 1098437885952 bytes, 2145386496 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
Disk label type: dos
Disk identifier: 0x000c1fec
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 * 1026048 2145386495 1072180224 83 Linux
Command (m for help): wr
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.
5. Reboot虚拟机
6. .修改根文件系统的大小
由于CentOS6和CentOS7在默认根文件系统的文件系统格式存在差异,需要判断是否为xfs,如果是xfs则应该使用xfs_growfs而不是一味的使用resize2fs
xfs_growfs /dev/sda2
7. 查看调整后的操作系统磁盘空间