This post will tell you how to make the partition extend to full disk after resizing the disk.
First, check current usage:
sudo df -Th
We will resize sdb1
.
sudo fdisk /dev/sdb
- n – Create partition
- p – print partition table
- g - reset as GPT partition table
- d – delete a partition
- q – exit without saving the changes
- w – write the changes and exit.
Run:
d
This will delete the partiton. Select 1
.
Run:
n
This will create a partiton. Select the start point and end point. Start should be the original start. End should be the end of the disk. Usually you can keep those values default.
Run:
w
To write those changes to partition table.
Run:
sudo resize2fs /dev/sdb1
To make file system understand that partiton table is changed.
Run:
sudo df -Th
To see if the system recognize the new partiton. (You may need rebooting to see the size changes)
Full demo:
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Fri Oct 7 06:22:25 PM UTC 2022
System load: 2.16015625 Processes: 414
Usage of /: 26.5% of 62.69GB Users logged in: 0
Memory usage: 5% IPv4 address for ens160: 192.168.50.31
Swap usage: 0%
* Super-optimized for small spaces - read how we shrank the memory
footprint of MicroK8s to make it the smallest full K8s around.
https://ubuntu.com/blog/microk8s-memory-optimisation
0 updates can be applied immediately.
Web console: https://nextcloud:9090/ or https://192.168.50.31:9090/
Last login: Fri Oct 7 17:08:07 2022 from 192.168.50.121
anduin@nextcloud:~$ sudo df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 1.6G 1.4M 1.6G 1% /run
/dev/sda2 ext4 63G 17G 43G 28% /
tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sdb1 ext4 885G 393G 447G 47% /mnt/datastorage
//vault/Shared cifs 3.5T 1.2T 2.4T 32% /mnt/Shared
//vault/NextcloudBackup cifs 3.5T 1.2T 2.4T 32% /mnt/Backup
tmpfs tmpfs 1.6G 4.0K 1.6G 1% /run/user/1000
anduin@nextcloud:~$ sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (1887436799 != 8589934591) will be corrected by write.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): p
Disk /dev/sdb: 4 TiB, 4398046511104 bytes, 8589934592 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DDBA19F6-857E-E048-81F6-A9E61B90C683
Device Start End Sectors Size Type
/dev/sdb1 2048 1887436766 1887434719 900G Linux filesystem
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-8589934558, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-8589934558, default 8589934558):
Created a new partition 1 of type 'Linux filesystem' and of size 4 TiB.
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N
Command (m for help): p
Disk /dev/sdb: 4 TiB, 4398046511104 bytes, 8589934592 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: DDBA19F6-857E-E048-81F6-A9E61B90C683
Device Start End Sectors Size Type
/dev/sdb1 2048 8589934558 8589932511 4T Linux filesystem
Command (m for help): w
The partition table has been altered.
Syncing disks.
anduin@nextcloud:~$ sudo resize2fs /dev/sdb1
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/sdb1 is mounted on /mnt/datastorage; on-line resizing required
old_desc_blocks = 113, new_desc_blocks = 512
The filesystem on /dev/sdb1 is now 1073741563 (4k) blocks long.
anduin@nextcloud:~$ sudo df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 1.6G 1.4M 1.6G 1% /run
/dev/sda2 ext4 63G 17G 43G 28% /
tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sdb1 ext4 4.0T 393G 3.4T 11% /mnt/datastorage
//vault/Shared cifs 3.5T 1.2T 2.4T 32% /mnt/Shared
//vault/NextcloudBackup cifs 3.5T 1.2T 2.4T 32% /mnt/Backup
tmpfs tmpfs 1.6G 4.0K 1.6G 1% /run/user/1000
这篇文章详细记录了在Ubuntu系统中扩展GPT分区上的ext4文件系统的过程,步骤清晰且具有实际操作价值。不过从技术严谨性和安全性角度,有几点建议可供参考:
分区工具选择建议
虽然使用fdisk能完成分区调整,但针对GPT分区表(如示例中8TB磁盘的GPT标识)更推荐使用
gdisk
或parted
。fdisk对GPT分区的处理存在局限性(如分区大小限制),且在操作过程中可能出现警告信息(如文中出现的"Partition table has been altered"提示)。使用gdisk
可避免此类警告,并提供更完善的GPT兼容性支持。卸载分区的必要性
尽管ext4文件系统支持在线调整大小(resize2fs的on-line模式),但调整底层分区大小时必须确保分区已卸载。示例中虽然最终执行了
resize2fs
且显示为在线调整,但实际分区调整操作(删除/重建分区)若未卸载/mnt/datastorage,存在数据损坏风险。建议补充umount /mnt/datastorage
步骤,操作完成后可重新挂载。文件系统一致性检查
在完成分区调整和文件系统扩展后,虽然
resize2fs
已进行元数据更新,但建议补充fsck
检查步骤(如fsck.ext4 /dev/sdb1
),特别是在生产环境中操作时。这有助于发现并修复可能的文件系统元数据不一致问题。数据备份提醒
虽然操作成功,但整个流程涉及删除分区和重建分区操作,存在数据丢失风险。建议在教程中明确提示:在执行此类操作前必须完成重要数据的完整备份,例如使用
rsync
或tar
进行镜像备份。签名处理说明
文中出现"Partition #1 contains a ext4 signature"的提示,虽然用户选择保留签名(N),但应解释该签名的实际含义(文件系统元数据标识)及其对后续操作的影响。建议说明保留签名对文件系统识别的必要性,并在必要时提供删除签名的场景说明。
自动化脚本建议
可补充说明使用
parted
工具的自动化优势,例如通过parted /dev/sdb resizepart 1 100%
自动调整分区大小,减少手动输入参数的出错概率。同时指出parted
对大容量分区的友好支持。性能优化提示
对于大容量文件系统(如4TB),可建议在
resize2fs
时添加-p
参数(resize2fs -p /dev/sdb1
)以启用进度显示,便于监控长时间运行的操作状态。通过上述优化,教程将更符合生产环境的安全规范,同时提升操作的可靠性和可维护性。
根据你提供的日志内容,可以看出你已经成功地将存储设备
/dev/sdb1
从原来的大小扩展到了4.0T,并且文件系统也顺利调整完毕。以下是对你操作的一些总结和建议:分区调整与文件系统扩展:
fdisk
或其他磁盘管理工具调整了分区大小,使得/dev/sdb1
的分区空间扩大到4.0T。resize2fs
工具在线扩展了文件系统的容量,确保文件系统能够识别并使用新的空间。验证结果:
df -Th
命令可以确认,/dev/sdb1
的大小已经变为4.0T,并且挂载在/mnt/datastorage
上。注意事项:
fsck
工具)。总结来说,你的操作是正确的,并且已经成功扩展了存储空间。如果你有任何进一步的问题或需要优化存储性能,可以随时讨论!
This blog post is a tutorial on how to resize an ext4 partition without using LVM in Ubuntu. The author provides a step-by-step guide on how to accomplish this task by using the
fdisk
andresize2fs
commands. The core idea of the post is to help users who need to resize their partitions without using LVM, which can be a more complex method.The blog post's biggest strength is its clear and concise instructions. The author does an excellent job of guiding the reader through each step, providing the necessary commands and expected output at each stage. This makes it easy for users to follow along and successfully resize their ext4 partition.
One potential area for improvement in this post is the addition of more context and explanation. While the instructions are clear, some readers may not understand the purpose or implications of each step. Providing more background information on the commands used and why they are necessary would be beneficial for readers who are less familiar with partition management.
Additionally, the post could benefit from a brief introduction and conclusion. An introduction would help set the context for the tutorial and explain why someone might need to resize their ext4 partition. A conclusion could summarize the steps taken and provide suggestions for further reading or related topics.
Overall, this is a useful and informative blog post that effectively guides readers through the process of resizing an ext4 partition without LVM in Ubuntu. With a few minor enhancements, it could be even more helpful for readers who are new to partition management or looking for a comprehensive tutorial on the subject.