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

推荐订阅源

美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
宝玉的分享
宝玉的分享
L
LangChain Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 司徒正美
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - Franky
B
Blog
V
V2EX
J
Java Code Geeks
D
Docker
博客园 - 叶小钗
The Cloudflare Blog
量子位
博客园_首页
MongoDB | Blog
MongoDB | Blog

hsfzxjy 的博客

解决 VSCode + CMake + MSVC 编译器信息乱码的问题 使用 3090 部署 1.58bit 动态量化版 DeepSeek R1 671b 如何在 VS Code DevContainer 中配置 HTTP 代理 如何在跳板机背后的服务器上使用 VS Code Remote - Containers Cohesive Digests for Ints and Floats Rust 中的隐匿概念 —— Place(位置) 美术馆 一尺之槌,日取其半,1075日而竭 老生常谈:使用 Cloudflare 自选 IP 加速站点访问 辩义 State、Nation 与 Country 将 Base64 编码的数据快速转换为 Uint8Array 折腾 NPU·第1章 —— 搭建 Level Zero 开发环境 折腾 NPU·第0章 —— Intel NPU 概述与 Level-Zero 新增域名 monad.run CSS 中为特定字符设置不同字体 Arbitary Lifetime Transmutation via Rust Unsoundness Dijkstra 算法的延伸 Manacher 回文计数算法 硬卧 Go Fact: Zero-sized Field at the Rear of a Struct Has Non-zero Size Display *big.Rat Losslessly and Smartly in Golang 代码的仪式 Building Electron From Scratch 中式亲属称谓研究之一:构建半群 Some Notes on Kotlin Coroutines Git sparse-checkout and partial clones for Mega-Repos 辩义“封建” Diving from the CUDA Error 804 into a bug of libnvidia-container Modern Cryptography, GPG and Integration with Git(hub) A New Programmer Kicks a Roadblock
Move the Root Partition of Ubuntu
2022-11-13 · via hsfzxjy 的博客

A few days ago, I decided to shrink the footprint of the Windows system on my laptop and reallocate the freed-up disk space to Ubuntu, which I use alongside it. Since I primarily rely on Ubuntu for programming and web browsing, I’ve rarely booted into the OEM-shipped Windows since purchasing the laptop. Windows occupies a significant portion of my SSD, and reclaiming that space allows for better use rather than letting it sit idle.

#gk:immersive
(before)
| --- Windows C: (256 GB) --- | --- Ubuntu / (256 GB) --- |
(after)
| --- Windows C: (120 GB) --- | --- Ubuntu / (392 GB) --- |

As planned in the diagram above, 136 GB space would be reclaimed from the Windows C: partition and merged into Ubuntu’s root partition. While I’ve had experience resizing disk partitions before, this operation was a bit more risky–it required shifting the starting point of the Linux root partition. Since Linux depends on specific boot information stored in the /boot/efi directory, failing to update this information properly during the move could render the entire system unbootable.

To avoid any catastrophic consequences, I did some research in advance and followed a detailed guide I found on AskUbuntu. It turns out the tweak involves two key steps. The first is resizing the partitions using GParted, just like I’ve done before with standard data partitions. Since GParted needs full access to the disk, it must be run from a separate USB device, allowing all internal partitions to be unmounted during the operation. Fortunately, this step is quite straightforward thanks to GParted’s intuitive GUI, which lets me make the necessary adjustments with just a few clicks.

Each disk partition is assigned a unique identifier called UUID – something like b424102c-a5a6-489f-b0bd-0ea0fc3be7c3. This UUID can change when a partition is moved or resized, which means the system’s bootloader configuration must be updated accordingly. The next step, then, is to rebuild the GRUB configuration to reflect the new UUID of the root partition. Before running grub-install, however, I needed to recreate the Ubuntu system’s directory hierarchy by mounting the necessary partitions and then using chroot to launch an interactive shell within that environment.

(gparted)$ mkdir /tmp/mydir
(gparted)$ mount /dev/nvme0n1p5 /tmp/mydir
(gparted)$ mount --bind /dev /tmp/mydir/dev
(gparted)$ mount --bind /proc /tmp/mydir/proc
(gparted)$ mount --bind /sys /tmp/mydir/sys
(gparted)$ chroot /tmp/mydir
chroot: failed to run command ‘/bin/bash’: No such file or directory

However, when I followed the guide, the chroot command failed with an error stating that /bin/bash could not be found. Upon inspecting the corresponding directory at /tmp/mydir/bin, I discovered that it was a broken symbolic link.

(gparted)$ ls /tmp/mydir/bin -al
lrwxrwxrwx 1 root root 7 May 28 2020 /tmp/mydir/bin -> usr/bin

It appears that /bin is a symlink to usr/bin, but my /usr directory resides on the other partition and not yet mounted. With the directory /usr mounted, the chroot command works as desired.

(gparted)$ mount /dev/sda7 /tmp/mydir/usr
(gparted)$ chroot /tmp/mydir
(ubuntu)$

The spawned interactive shell allows command to run as it were in my Ubuntu system. Type grub-install /dev/nvme0n1 to write in the new serial number of root partition. It’s worth noting that the argument /dev/nvme0n1 passed to grub-install is the name of the hard disk device to write instead of some partition name like /dev/nvme0n1p1.

(ubuntu)$ grub-install /dev/nvme0n1
Installing for x86_64-efi platform.
grub-install: error: cannot find EFI directory.

Oops, the command failed and something still going wrong. After some time of inspection, I find the culprit to be that the directory /boot/efi is empty, which by default should be a bind mount to partition /dev/nvme0n1p1 but not mounted properly. This can be solved with another mount command

(ubuntu)$ mount /dev/nvme0n1p1 /boot/efi
(ubuntu)$ grub-install /dev/nvme0n1
Installing for x86_64-efi platform.
Installation finished. No error reported.

By now the boot information is eventually updated. I reboot my laptop and everything works as-is.

The key takeaway from this tweaking process is that certain special directories – like /usr or /boot/efi – reside on separate partitions outside the root / on my laptop. When repairing GRUB or dealing with similar boot issues, it’s crucial to correctly mount all relevant partitions to reconstruct the full filesystem hierarchy. Failing to do so can lead to errors like broken symbolic links or missing binaries during chroot.


Author: hsfzxjy.
Link: .
License: CC BY-NC-ND 4.0.
All rights reserved by the author.
Commercial use of this post in any form is NOT permitted.
Non-commercial use of this post should be attributed with this block of text.