惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Blog — PlanetScale
Blog — PlanetScale
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
U
Unit 42
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
B
Blog RSS Feed
Vercel News
Vercel News
F
Fortinet All Blogs
Know Your Adversary
Know Your Adversary
T
Troy Hunt's Blog
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
Jina AI
Jina AI
小众软件
小众软件
T
Threatpost
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
B
Blog
腾讯CDC
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
S
Schneier on Security
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
K
Kaspersky official blog
G
Google Developers Blog
T
Tor Project blog
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Google Online Security Blog
Google Online Security Blog
Latest news
Latest news
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
罗磊的独立博客

hiDandelion's Space

如何使用NodePass iOS App实现NAT穿透 VRChat如何上传自己的Windows/Android双端角色模型Avatar VRChat如何上传自己的角色模型Avatar 双极型晶体管BJT的掺杂方式、少子分布与理想直流特性 DigitalOcean入门机型Basic Regular $6评测 双极型晶体管BJT的直流电流关系与EM模型 双极型晶体管BJT非理想性能合集 如何升级甲骨文Oracle Cloud Infrastructure为付费账户 如何删除GCP Logging中的日志 - 一次被GCP Ops Agent坑惨的经历 谷歌云GCP入门机型E2.micro评测
如何使用growpart扩展Linux的系统分区容量
hiDandelion · 2024-01-09 · via hiDandelion's Space

背景#

当我们为运行Linux系统的计算机进行磁盘还原或为主机更换更大容量硬盘时,有时会遇到系统分区小于磁盘大小的情况,从而无法有效利用整块磁盘,这时我们需要扩展Linux系统分区。为了最大可能简化操作,我们将采用在线扩展的方式,即可以先进入系统,在分区已挂载的情况下进行扩展。

操作#

查看磁盘和分区#

使用以下指令以查看磁盘信息:

fdisk -l

将输出磁盘和分区信息:

Disk /dev/vda: 2 TiB, 2199023255552 bytes, 4294967296 sectors
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: 744D726A-2AC1-7744-89B3-072E6920B57A

Device       Start      End  Sectors Size Type
/dev/vda1     2048     6143     4096   2M BIOS boot
/dev/vda2     6144  2103295  2097152   1G Linux filesystem
/dev/vda3  2103296 20971486 18868191   9G Linux filesystem

在这里,/dev/vda是我们的磁盘,可见我们的磁盘空间为2TB。

使用以下指令以查看分区信息:

df -h

将输出分区和目录信息:

Filesystem      Size  Used Avail Use% Mounted on
udev             24G     0   24G   0% /dev
tmpfs           4.8G  524K  4.8G   1% /run
/dev/vda3       8.8G  2.2G  6.2G  27% /
tmpfs            24G     0   24G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/vda2       974M   87M  820M  10% /boot
tmpfs           4.8G     0  4.8G   0% /run/user/0

可见,/dev/vda3是根目录所在分区,也是我们的目标系统分区。

调整分区表#

使用growpart指令扩展分区,需要指定磁盘和分区编号。由于在上面的步骤我们已确认磁盘为/dev/vda,分区为/dev/vda3,使用以下指令以扩展/dev/vda3,注意在这行命令中,/dev/vda与3之间存在一个空格:

growpart /dev/vda 3

将输出调整后的结果:

CHANGED: partition=3 start=2103296 old: size=18868191 end=20971486 new: size=4292863967 end=4294967262

写入文件系统#

使用以下指令将对/dev/vda3的更改写入文件系统

resize2fs /dev/vda3

将输出调整后的内容:

resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/vda3 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 256
The filesystem on /dev/vda3 is now 536607995 (4k) blocks long.

检查#

再次使用以下指令检查已完成的更改:

fdisk -l

将输出磁盘和分区信息:

Disk /dev/vda: 2 TiB, 2199023255552 bytes, 4294967296 sectors
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: 744D726A-2AC1-7744-89B3-072E6920B57A

Device       Start        End    Sectors Size Type
/dev/vda1     2048       6143       4096   2M BIOS boot
/dev/vda2     6144    2103295    2097152   1G Linux filesystem
/dev/vda3  2103296 4294967262 4292863967   2T Linux filesystem

可见系统分区已更改为目标大小。