前提条件
已经在甲骨文控制台为实例磁盘扩容空间(磁盘容量只能增大,不能减小!)
当前教程仅为 DD 系统使用!
原版系统可使用扩容后控制台生成的命令重新加载
以下命令在 root 环境执行!
查看磁盘/分区信息
分别执行 df -h、fdisk -l 命令查看/dev/sda2 是否存在未分配的容量
fd -h:
Filesystem Size Used Avail Use% Mounted on
udev 12G 0 12G 0% /dev
tmpfs 2.4G 956K 2.4G 1% /run
/dev/sda2 147G 102G 37G 74% /
tmpfs 12G 20K 12G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/sda1 512M 16M 497M 3% /boot/efi
tmpfs 2.4G 0 2.4G 0% /run/user/0
fdisk -l:
root@ubuntu:~# fdisk -l
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: B50ABF1D-D4A6-457B-90B9-2B8EBE6A7652
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 314570751 313520128 149.5G Linux filesystem
# 总容量为200G,实际容量为149.5G;存在未分配的容量
使用 fdisk 命令扩容分区
# 执行分区命令
root@ubuntu:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
# p 查看分区
Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: B50ABF1D-D4A6-457B-90B9-2B8EBE6A7652
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 419430366 418379743 199.5G Linux filesystem
# d 选择2 删除/dev/sda2分区(不会损坏原有数据)
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
# p 查看/dev/sda2分区是否删除
Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: B50ABF1D-D4A6-457B-90B9-2B8EBE6A7652
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
# n 新建分区,选择2,First sector和Last sector回车保持默认;选择N 不删除ext4分区签名!!!
Command (m for help): n
Partition number (2-128, default 2): 2
First sector (1050624-419430366, default 1050624): 1050624
Last sector, +sectors or +size{K,M,G,T,P} (1050624-419430366, default 419430366):
Created a new partition 2 of type 'Linux filesystem' and of size 199.5 GiB.
Partition #2 contains a ext4 signature.
# 选择N 不删除ext4分区签名!!!
Do you want to remove the signature? [Y]es/[N]o: n
# p 查看新建的/dev/sda2分区
Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: gpt
Disk identifier: B50ABF1D-D4A6-457B-90B9-2B8EBE6A7652
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 419430366 418379743 199.5G Linux filesystem
# wq 保存并退出
Command (m for help): wq
The partition table has been altered.
Syncing disks.
重载分区使其生效
# 执行resize2fs /dev/sda2使分区生效
root@ubuntu:~# resize2fs /dev/sda2
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 19, new_desc_blocks = 25
The filesystem on /dev/sda2 is now 52297467 (4k) blocks long.
# reboot重启系统
root@ubuntu:~# reboot