![Ubuntu 16.04 停止启动,配置了 LVM 和 LUKS 加密,已尝试超级块恢复](https://linux22.com/image/95635/Ubuntu%2016.04%20%E5%81%9C%E6%AD%A2%E5%90%AF%E5%8A%A8%EF%BC%8C%E9%85%8D%E7%BD%AE%E4%BA%86%20LVM%20%E5%92%8C%20LUKS%20%E5%8A%A0%E5%AF%86%EF%BC%8C%E5%B7%B2%E5%B0%9D%E8%AF%95%E8%B6%85%E7%BA%A7%E5%9D%97%E6%81%A2%E5%A4%8D.png)
突然我的 Ubuntu 16.04 出现initramfs
这样的提示:
BusyBox v.1.22.1 (Ubuntu 1:1.22.0-15ubuntu1) built-in shell (ash)
Enter 'help' for list of built-in commands.
(initramfs)
如果我输入exit
我得到:
Gave up waiting for root device. Common problems:
— Boot args (cat /proc/cmdline)
— Check rootdelay= (did the system wait long enough?)
— Check root= (did the system wait for the right device?)
— Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/mapper/ubuntu--vg-root does not exist. Dropping to a shell!
BusyBox v.1.22.1 (Ubuntu 1:1.22.0-15ubuntu1) built-in shell (ash)
Enter 'help' for list of built-in commands.
(initramfs)
我尝试过的事情,到目前为止没有成功:
- 尝试使用 USB 启动盘恢复超级块备份,仍然可以启动。
- 无法启动到不同的内核,因为
SHIFT
在 grub 时按下时我只能在高级选项中看到一个内核。
当我进入 grub 屏幕时,如果按e
这些就是我的设置:
setparams 'Ubuntu'
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 7ec61194-f216-4f1b-b684-5b2e2d643c25
else
search --no-floppy --fs-uuid --set=root 7ec61194-f216-4f1b-b684-5b2e2d643c25
fi
linux /vmlinux-4.4.0-24-generic root=/dev/mapper/ubuntu--vg-root ro quiet splash $vt_handoff
initrd /initrd.img-4.4.0-24-generic
如果我启动到可启动的 LIVE USB 磁盘,sudo fdisk -l
则会返回:
Disk /dev/sda: 480.1 GB, 480103981056 bytes
255 heads, 63 sectors/track, 58369 cylinders, total 937703088 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
Disk identifier: 0x60229a0a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 999423 498688 83 Linux
/dev/sda2 1001470 937701375 468349953 5 Extended
/dev/sda5 1001472 937701375 468349952 83 Linux
Disk /dev/sdb: (skipping since I think this is the USB disk...)
如果我通过 nautilus 挂载分区(加密的分区会提示我输入密码),然后sudo lsblk
返回:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 447.1G 0 disk
├─sda1 8:1 0 487M 0 part /media/ubuntu/7ec61194-f216-4f1b-b684-5b2e2d643c
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 446.7G 0 part
└─luks-11613ca4-65f2-4079-a750-6f71b6318903 (dm-0) 252:0 0 446.7G 0 crypt
└─ubuntu--vg-root (dm-1) 252:1 0 439.2G 0 lvm
└─ubuntu--vg-swap_1 (dm-2) 252:2 0 7.5G 0 lvm
sdb 8:16 1 1.9G 0 disk
└─sdb1 8:17 1 1.9G 0 part /cdrom
sr0 11:0 1 1024M 0 rom
loop0 7:0 0 938.7M 1 loop
怎么了?是什么阻止系统启动并像往常一样询问我加密密码?谢谢!
答案1
您可以尝试从 LiveCD 运行下面的脚本(可能是链接中的更新版本)。该脚本尝试为您部分自动化该过程。它是针对 NVMe 驱动器编写和测试的,因此如果您使用带有路径的 SATA/IDE 驱动器,则可能需要稍微更改一些内容/dev/sd*
。如果您不使用 EFI,则可以通过在将脚本保存到计算机后运行来删除包含efi
或 的任何行。最终必须为此添加一些检测逻辑。EFI
sed -i -e '/efi/d' -e '/EFI/d' crypt-fix.sh
https://gist.github.com/dragon788/e777ba64d373210e4f6306ad40ee0e80
加密修复.sh
#!/bin/bash
# Call with `sudo bash DEBUG=1 ./crypt-fix.sh` for verbose output
[ -n "$DEBUG"] && set -x
# Prompt user for device from /dev/sd* /dev/nvme* /dev/mmc* prefixes?
# For /dev/sda probably sda1 is EFI and sda2 is boot and sda3 is encrypted
DEVICE=/dev/nvme0n1
EFIPATH="${DEVICE}p1"
BOOTPATH="${DEVICE}p2"
CRYPTPATH="${DEVICE}p3"
TARGETPATH=/mnt
# Need root for mounting stuff
if ! (( $EUID == 0 )); then echo "Please run with `sudo $0`"; fi
clear_mounts () {
# Clears mounts in case of interrupt or upon exit to allow running script multiple times
umount $TARGETPATH/boot/efi
umount $TARGETPATH/boot
umount $TARGETPATH/proc
umount $TARGETPATH/dev
umount $TARGETPATH
vgchange -an
cryptsetup close temp_name
cryptsetup close $CRYPTNAME
set +x
}
trap clear_mounts INT EXIT
cryptsetup open $CRYPTPATH temp_name
vgchange -ay
# Can't get this until LVM devices are scanned above
ROOTPATH=$(ls /dev/mapper/* | grep root)
# Make sure nothing else is mounted on our $TARGETPATH
umount $TARGETPATH
wait
mount $ROOTPATH $TARGETPATH
# Find the name that is required for `update-initramfs` to properly update things
CRYPTNAME=$(cat $TARGETPATH/etc/crypttab | awk '/^[ ]*[^#]/ { print $1; exit }')
umount $TARGETPATH
vgchange -an
cryptsetup close temp_name
# This proper name is required for `update-initramfs` to properly update things
cryptsetup open $CRYPTPATH $CRYPTNAME
wait
vgchange -ay
ROOTPATH=$(ls /dev/mapper/* | grep root)
mount $ROOTPATH $TARGETPATH
mount $BOOTPATH $TARGETPATH/boot
mount $EFIPATH $TARGETPATH/boot/efi
mount -t proc proc $TARGETPATH/proc
mount -o bind /dev $TARGETPATH/dev
# Have also seen people mounting dev/pts and run and sys, they don't appear to be necessary
chroot $TARGETPATH update-initramfs -c -k all
echo "Completed crypt-fix, try rebooting and you should get prompted for your passphrase after grub"