All the time Hyper-V
Linux
Disk expansion of virtual host is troublesome. Today we will introduce how to use fdisk
and resize2fs
Data disk capacity expansion.
Description:
Host system: Windows Server 2012 R2 Hyper-V
Virtual host: CentOS Linux release 7.4.1708 (Core)
Usual contact Hyper-V
More, so disk expansion is common. Windwos
Disk expansion is the simplest. This article will not cover it.
Today I will Centos
The virtual host performs the demonstration. The small machine is divided into two disks (both independent disks), and one is the system disk /dev/sda
, the other is the database disk /dev/sdb
The current requirement is that SDB should change from the original 30GB
Expand to 100GB
。
1. Check the disk partition and mounting status before capacity expansion
[ root@renwole-com ~]# fdisk -l Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 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: 0x5f149419 Device Boot Start End Blocks Id System /dev/sdb1 2048 62914559 31456256 83 Linux Disk /dev/sda: 10.7 GB, 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 Disk label type: dos Disk identifier: 0x00043041 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVM Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 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 /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 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
[ root@renwole-com ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cl-root xfs 8.0G 950M 7.1G 12% / devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs tmpfs 1.9G 8.3M 1.9G 1% /run tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 138M 877M 14% /boot tmpfs tmpfs 379M 0 379M 0% /run/user/0 /dev/sdb1 ext4 30G 60M 28G 1% /apps
Note: orange part /dev/sdb1
Partition size is 30GB
, which is also attached 30GB
。
2. Unload and mount
delete /etc/fstab
The following boot disk auto mount information in the file:
/dev/sdb1 /apps ext4 defaults 0 0
3. Start virtual host disk expansion
Hyper-V virtual machine operations:
open Hyper-V
Manager, find the small machine that needs to be expanded and shut down, then right-click Settings, click the disk that needs to be expanded, (usually the data disk) Edit - Next by default - Select Next by extension, this step needs attention, assuming that your original disk is 30G
, then you want to expand to 100G
, please fill in one hundred
Click Next to finish. Then start the virtual host.
View the disk partitions after capacity expansion:
[ root@renwole-com ~]# fdisk -l Disk /dev/sda: 10.7 GB, 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 Disk label type: dos Disk identifier: 0x00043041 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 20971519 9436160 8e Linux LVM Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x5f149419 Device Boot Start End Blocks Id System /dev/sdb1 2048 62914559 31456256 83 Linux Disk /dev/mapper/cl-root: 8585 MB, 8585740288 bytes, 16769024 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 /dev/mapper/cl-swap: 1073 MB, 1073741824 bytes, 2097152 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
sdb
The partition size is changed from the original 30GB
Expand to 100GB
, but partition sdb1
No capacity expansion is used 70GB
What about space?
4. Delete partition
Delete different partitions, delete data, delete partitions and rebuild them:
[ root@renwole-com ~]# fdisk /dev/sdb 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): d #Delete sdb1 partition Selected partition 1 Partition 1 is deleted Command (m for help): n #New Section Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): one #Specify partition code 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 Partition 1 of type Linux and of size 100 GiB is set Command (m for help): w #Enter w to save The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Check the disk partition again
[ root@renwole-com ~]# fdisk -l ... Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x5f149419 Device Boot Start End Blocks Id System /dev/sdb1 2048 209715199 104856576 83 Linux ...
Has changed from the original 30G
Expand to 100G
However, it can't be used yet. The following operations are required to ensure successful capacity expansion:
[ root@renwole-com ~]# resize2fs -f /dev/sdb1 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/sdb1 to 26214144 (4k) blocks. The filesystem on /dev/sdb1 is now 26214144 blocks long.
Capacity expansion succeeded.
5. Attach the disk
[ root@renwole-com ~]# mount /dev/sdb1 /apps/ [ root@renwole-com ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cl-root xfs 8.0G 950M 7.1G 12% / devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs tmpfs 1.9G 8.3M 1.9G 1% /run tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 138M 877M 14% /boot tmpfs tmpfs 379M 0 379M 0% /run/user/0 /dev/sdb1 ext4 99G 60M 94G 1% /apps [ root@renwole-com ~]# ls /apps/ web mysql
As shown above, The data disk of the Linux virtual host has been successfully expanded. Check that the data is not lost.
In addition, write your disk information to /etc/fstab
File, otherwise the disk needs to be manually mounted after reboot.
Note: In the same sentence, before operating any data, you must first back it up to form a good habit to prevent data loss.