适用系统

  • openSUSE Leap 15.x
  • openSUSE Tumbleweed
  • SUSE Linux Enterprise Server (SLES)
  • SUSE Linux Enterprise Desktop (SLED)

openSUSE 特点

  • 使用 GRUB2
  • 文件系统通常为 Btrfs(默认)+ XFS(/home)
  • 支持 Snapper 快照
  • 使用 YaST 管理工具
  • AppArmor 作为安全模块(非 SELinux)

方法一:init=/bin/bash(推荐)

步骤 1:编辑 GRUB

  1. 启动时在 GRUB 菜单按 e

  2. 找到 linux 行:

1
linux /boot/vmlinuz-5.14.21-150400 root=/dev/sda2 splash=silent quiet showopts
  1. 在行末添加:
1
init=/bin/bash
  1. F10Ctrl+X 启动

步骤 2:修改密码

1
2
3
4
5
6
7
8
9
10
# 重新挂载为读写
mount -o remount,rw /

# 修改密码
passwd root

# 重启
exec /sbin/init
# 或
reboot -f

方法二:single 单用户模式

操作步骤

  1. GRUB 编辑,在 linux 行末添加:
1
single
  1. F10 启动

  2. 进入单用户模式,直接修改密码

SUSE 特别说明

  • openSUSE/SLES 单用户模式通常直接给 root shell
  • 无需额外密码验证

方法三:rescue 系统救援

使用安装介质

  1. 从 openSUSE 安装 DVD/USB 启动

  2. 选择 Rescue System

  3. 启动后登录(root,无密码或按提示)

  4. 挂载目标系统:

1
2
3
4
5
6
7
8
# 查看分区
fdisk -l

# 挂载根分区
mount /dev/sda2 /mnt

# Btrfs 子卷(如果使用)
mount -o subvol=@ /dev/sda2 /mnt
  1. chroot 并修改:
1
2
3
4
5
6
7
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt
passwd root
exit
reboot

方法四:YaST 救援模式

从安装介质启动 YaST

  1. 使用安装介质启动

  2. 选择 Installation 但在早期步骤选择 Rescue System

  3. YaST 会提供图形化的系统修复选项

  4. 选择修改 root 密码的选项


Btrfs 文件系统处理

默认 Btrfs 子卷布局

openSUSE 使用复杂的 Btrfs 子卷结构:

1
2
3
4
5
6
7
8
9
10
11
@                   /
@/boot/grub2/i386-pc
@/boot/grub2/x86_64-efi
@/home
@/opt
@/root
@/srv
@/tmp
@/usr/local
@/var
@/.snapshots

挂载命令

1
2
3
4
5
6
7
8
# 默认挂载
mount /dev/sda2 /mnt

# 指定根子卷
mount -o subvol=@ /dev/sda2 /mnt

# 查看子卷
btrfs subvolume list /mnt

直接修改 shadow

1
2
3
mount /dev/sda2 /mnt
# shadow 位于 @ 子卷
nano /mnt/@/etc/shadow

Snapper 快照

openSUSE 自动创建快照

如果系统之前工作正常,可以回滚到快照:

  1. GRUB 菜单选择 Start bootloader from a read-only snapshot

  2. 选择一个正常的快照启动

  3. 启动后执行回滚:

1
2
snapper rollback
reboot

查看快照

1
snapper list

LVM 配置(如果使用)

1
2
3
4
5
6
7
8
# 激活 LVM
vgchange -ay

# 查看逻辑卷
lvscan

# 挂载
mount /dev/mapper/system-root /mnt

直接修改 shadow 文件

清空密码

1
2
3
4
5
# 修改前
root:$6$rounds=4096$salt$hash...:18000:0:99999:7:::

# 修改后
root::18000:0:99999:7:::

生成密码哈希

1
openssl passwd -6 -salt randomsalt mypassword

AppArmor

openSUSE 使用 AppArmor 而非 SELinux:

  • 密码修改通常不受 AppArmor 影响
  • 无需类似 .autorelabel 的操作

如需临时禁用

GRUB 添加:

1
apparmor=0

SLES 特别说明

SUSE Linux Enterprise Server

  • 方法与 openSUSE 相同
  • 可能有注册/订阅相关配置
  • 企业环境可能有额外安全措施

集成的 SMT/RMT 服务器

如果无法访问 SUSE 更新服务器,编辑:

1
/etc/zypp/repos.d/

常见问题

Q: Btrfs 只读快照无法修改?

A: 确保不是从只读快照启动:

1
btrfs property get -ts /

如果是只读,需要正常启动或使用 Live 环境。

Q: 找不到 shadow 文件?

A: 检查 Btrfs 子卷结构,可能在 /@/etc/shadow

Q: 修改后无法启动?

A: 尝试从 Snapper 快照恢复,或检查 Btrfs 子卷挂载。

Q: grub 菜单被跳过?

A: 启动时按住 EscShift 键。


适用系统:openSUSE Leap/Tumbleweed, SLES, SLED