blog-site

git clone git://git.lin.moe/blog-site.git

 1---
 2title: "Alpine BTRFS 修复记录"
 3date: 2023-06-19T19:49:05+08:00
 4---
 5
 6## 问题
 7alpine 3.18 更新 linux-lts 后,启动失败,进入救援系统,报错日志
 8```
 9mount: mounting /dev/sda3 on /newroot failed: Invalid argument
10```
11
12## 过程
13
141. 首先想到的是文件系统出错了。  
15   进入到 liveos ,`btrfs check /dev/sda3` 无异常   
16
172. 这大概是内核加载的时候出了什么问题。  
18   首先重新做一遍 `initramfs`,方法是在 liveos 里把分区都挂上,chroot 进去修  
19   
20   ```
21   export chroot_dir=/mnt
22   mount /dev/sda3 ${chroot_dir}
23   mount /dev/sda1 ${chroot_dir}/boot
24   
25   mount -o bind /dev ${chroot_dir}/dev
26   mount -t proc none ${chroot_dir}/proc
27   mount -o bind /sys ${chroot_dir}/sys
28   
29   chroot ${chroot_dir} /bin/ash -l 
30   
31   ```
32
33	检查 `/etc/mkinitfs/mkinitfs.conf` 配置,对比其他机器,发现缺了 `btrfs` 的 features 。  
34	
35	加上之后 `apk fix linux-lts` 发现在 `syslinux-6.04_pre1-r13.trigger` 报了一个警告:
36	```
37	WARNING: Root device is not specified in /etc/update-extlinux.conf.
38	```
39	暂时先没管,重启,失败
40
413. 修 bootloader  
42   前面提到的 `/etc/update-extlinux.conf` 文件就是 syslinux 的配置文件,首先把 root 设备的配置加上
43   
44   ```
45   root=UUID=xxxxxxxxxxxxxxxxxx
46   ```
47   
48   然后看到这样一行配置
49   ```
50   # modules
51   # modules which should be loaded before pivot_root
52   modules=sd-mod,usb-storage,ext4
53   ```
54   把 `ext4` 改成 `btrfs`,重新运行 `apk fix linux-lts`,警告消失,重启正常进入系统
55
56## 后日谈  
57为什么配置文件会变成这个样子,完全没有头绪。这台机器之前也更新过内核重启,没什么问题。  
58	
59另一台安装时间只相差十几天的机器,完全正常,修复配置参考的也是这台正常的机器。