Ubuntu 双启动与 LVM 和 LUKS 安装失败

Ubuntu 双启动与 LVM 和 LUKS 安装失败

我有一台支持 UEFI 的 HP Pavilion G7 笔记本电脑和一个 250GB GPT SSD 磁盘。笔记本电脑最初安装了 Windows 8,但后来我全新安装了 Windows 10,并为 Linux 保留了一些空闲空间。

现在我想要拥有 Win10 和 Ubuntu16 Mate 16.04 LTS 双启动,带有 LVM 的 LUKS 加密磁盘。

Ubuntu Mate GUI 安装程序无法实现这种使用 LUKS 和 LVM 的双启动配置,但我发现可以遵循以下说明(针对 Ubuntu 13.04 测试):

如何安装使用 LUKS 加密并双启动的 Ubuntu?

我尝试按照这些说明进行操作,但在启动时总是无法打开加密磁盘,因为cryptsetup失败。

这是我的程序,编号与说明中的相同:

  1. 从 Ubuntu Live DVD 或 USB 启动,然后选择“试用 Ubuntu”。
  2. 使用实时磁盘中包含的 GParted 创建分区。GParted。创建了 2 个分区:用于 LUKS 的启动分区和数据分区。Windows esp 也将用于 Ubuntu。

    (parted) print list                                                       
    Model: ATA Samsung SSD 850 (scsi)
    Disk /dev/sda: 250GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End    Size    File system  Name                          Flags
     1      1049kB  473MB  472MB   ntfs         Basic data partition          hidden, diag
     2      473MB   578MB  105MB   fat32        EFI system partition          boot, esp
     3      578MB   595MB  16.8MB               Microsoft reserved partition  msftres
     4      595MB   123GB  123GB   ntfs         Basic data partition          msftdata
     5      123GB   124GB  835MB   ntfs                                       hidden, diag
     6      124GB   125GB  524MB   ext4         NotUsed
     7      125GB   126GB  1049MB  ext4         linux-boot
     8      126GB   250GB  124GB                linux-data
    
    ubuntu-mate@ubuntu-mate:~$ lsblk
    NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sda      8:0    0 232.9G  0 disk 
    ├─sda1   8:1    0   450M  0 part 
    ├─sda2   8:2    0   100M  0 part (This is Windows esp)
    ├─sda3   8:3    0    16M  0 part 
    ├─sda4   8:4    0 114.4G  0 part 
    ├─sda5   8:5    0   796M  0 part 
    ├─sda6   8:6    0   500M  0 part 
    ├─sda7   8:7    0  1000M  0 part (boot)
    └─sda8   8:8    0 115.7G  0 part (LUKS)
    

    格式化分区 sda7、sda8

  3. 使用这些命令创建 LUKS 容器

    sudo cryptsetup luksFormat /dev/sda8
    sudo cryptsetup luksOpen /dev/sda8 pv_data
    
  4. 正确初始化新的 LUKS 容器至关重要

    ubuntu-mate@ubuntu-mate:~$ sudo dd if=/dev/zero of=/dev/mapper/pv_data bs=16M
    dd: error writing '/dev/mapper/pv_data': No space left on device
    7469+0 records in
    7468+0 records out
    125303783424 bytes (125 GB, 117 GiB) copied, 381.69 s, 328 MB/s
    
  5. 在已挂载的 LUKS 容器内,创建一个 LVM 物理卷、一个卷组和两个逻辑卷。第一个逻辑卷将挂载在 /,第二个逻辑卷将用作交换。

    ubuntu-mate@ubuntu-mate:~$ sudo pvcreate /dev/mapper/pv_data
      Physical volume "/dev/mapper/pv_data" successfully created
    
    ubuntu-mate@ubuntu-mate:~$ sudo vgcreate vg_data /dev/mapper/pv_data
      Volume group "vg_data" successfully created
    
    ubuntu-mate@ubuntu-mate:~$ sudo lvcreate -n lv_swap -L 12g vg_data
      Logical volume "lv_swap" created.
    
    ubuntu-mate@ubuntu-mate:~$ sudo lvcreate -n lv_root -L 80g vg_data
      Logical volume "lv_root" created.
    
    ubuntu-mate@ubuntu-mate:~$ lsblk
    NAME                  MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
    sda                     8:0    0 232.9G  0 disk  
    ...
    └─sda8                  8:8    0 115.7G  0 part  
    └─pv_data           252:0    0 115.7G  0 crypt 
        ├─vg_data-lv_swap 252:1    0    12G  0 lvm   
        └─vg_data-lv_root 252:2    0    80G  0 lvm   
    
  6. 为两个逻辑卷创建文件系统

    ubuntu-mate@ubuntu-mate:~$ sudo mkfs.ext4 /dev/mapper/vg_data-lv_root
    mke2fs 1.42.13 (17-May-2015)
    Creating filesystem with 20971520 4k blocks and 5242880 inodes
    Filesystem UUID: 1cbd1ea6-fa20-41f6-a870-5c159301bee4
    Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   
    
    ubuntu-mate@ubuntu-mate:~$ sudo mkswap /dev/mapper/vg_data-lv_swap
    Setting up swapspace version 1, size = 12 GiB (12884897792 bytes)
    no label, UUID=d665e5d7-b81f-4078-a5d5-bb1dd137fce2
    
  7. 使用图形安装程序安装 Ubuntu,选择手动分区。

    分配://dev/mapper/vg_data-lv_root/boot/dev/sda7、交换到/dev/mapper/vg_data-lv_swap

    将其他分区标记为“不使用”,除了 sda7 boot、lv_root、lv_swap、sda2 efi windows 启动管理器

    选择要安装引导加载程序的设备/dev/sda

  8. 图形安装程序完成后,选择“继续测试”并打开终端。

  9. 查找 LUKS 分区的 UUID:/dev/sda8

    ubuntu-mate@ubuntu-mate:~$ sudo blkid
    /dev/sda1: LABEL="Recovery" UUID="FABE4708BE46BCBF" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="69ee7fd0-ed56-41b2-b974-b76647cb98d5"
    /dev/sda2: UUID="9A47-7CB4" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="3cfbb43a-3bfd-48ac-b673-109f469c4d72"
    /dev/sda4: UUID="82324D05324D0021" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="342a1cfb-8587-4dbc-a180-4872aa23aff5"
    /dev/sda5: UUID="D606B52306B50611" TYPE="ntfs" PARTUUID="6bebe835-96b9-422e-b9c1-baf69ae085b3"
    /dev/sda6: UUID="341a01d8-dcb7-4c51-99aa-22a84d53054b" TYPE="ext4" PARTLABEL="NotUsed" PARTUUID="f2524ea7-8736-4998-8705-5e9d22c42b3c"
    /dev/sda7: UUID="d0033e81-c785-4efc-a0d3-1128b7a99792" TYPE="ext4" PARTLABEL="linux-boot" PARTUUID="08e453f9-84ca-48b0-a26f-915f2462c578"
    /dev/sdb1: LABEL="UBUNTU-MATE" UUID="8EDE-65EA" TYPE="vfat" PARTLABEL="Microsoft Basic Data" PARTUUID="2c0f92b3-5d67-45c7-bc1b-ce8a1a284015"
    /dev/loop0: TYPE="squashfs"
    /dev/sda8: UUID="ec4c6b1d-0bf1-41d4-81ec-754987a5532f" TYPE="crypto_LUKS" PARTLABEL="linux-data" PARTUUID="18bf1837-1dda-477a-9007-e3478e12f565"
    /dev/sdc1: LABEL="FAT32GB" UUID="FE56-878C" TYPE="vfat" PARTUUID="58ee1847-01"
    /dev/mapper/pv_data: UUID="11kz5r-WtT9-c2oU-sDrB-ObWm-OCiP-t0JG9c" TYPE="LVM2_member"
    /dev/mapper/vg_data-lv_swap: UUID="d665e5d7-b81f-4078-a5d5-bb1dd137fce2" TYPE="swap"
    /dev/mapper/vg_data-lv_root: UUID="57c480e3-59c7-4203-ac5c-2a08075fd71c" TYPE="ext4"
    /dev/dm-1: UUID="d665e5d7-b81f-4078-a5d5-bb1dd137fce2" TYPE="swap"
    /dev/sda3: PARTLABEL="Microsoft reserved partition" PARTUUID="dfbb8924-81a1-4646-9baa-3a4977641f5e"
    
  10. 将适当的设备挂载到 /mnt 中的适当位置,并 chroot 到其中:

    sudo mount /dev/mapper/vg_data-lv_root /mnt
    sudo mount /dev/sda7 /mnt/boot
    sudo mount --bind /dev /mnt/dev
    sudo chroot /mnt
    
  11. 在 chrooted 环境中创建一个名为 /etc/crypttab 的文件:

    root@ubuntu-mate:/# cat /etc/crypttab
    # <target name> <source device> <key file> <options>
    pv_data UUID=ec4c6b1d-0bf1-41d4-81ec-754987a5532f none luks,retry=1,lvm=vg_data
    
  12. 在 chrooted 环境中创建一个名为 /etc/initramfs-tools/conf.d/cryptroot 的文件:

    root@ubuntu-mate:/# cat /etc/initramfs-tools/conf.d/cryptroot
    CRYPTROOT=target=pv_data,source=/dev/disk/by-uuid/ec4c6b1d-0bf1-41d4-81ec-754987a5532f
    
  13. 在 chrooted 环境中运行以下命令:

    root@ubuntu-mate:/# update-initramfs -k all -c
    update-initramfs: Generating /boot/initrd.img-4.4.0-38-generic
    cat: /proc/cmdline: No such file or directory
    update-initramfs: Generating /boot/initrd.img-4.4.0-31-generic
    cat: /proc/cmdline: No such file or directory
    

    这些错误严重吗?

  14. 在 chrooted 环境中编辑名为 /etc/default/grub 的文件:

    root@ubuntu-mate:/# cat /etc/default/grub
    # If you change this file, run 'update-grub' afterwards to update
    # /boot/grub/grub.cfg.
    # For full documentation of the options in this file, see:
    #   info -f grub -n 'Simple configuration'
    
    GRUB_DEFAULT=0
    #GRUB_HIDDEN_TIMEOUT=0
    GRUB_HIDDEN_TIMEOUT_QUIET=true
    GRUB_TIMEOUT=10
    GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    #GRUB_CMDLINE_LINUX=""
    GRUB_CMDLINE_LINUX="cryptopts=target=pv_data,source=/dev/disk/by-uuid/ec4c6b1d-0bf1-41d4-81ec-754987a5532f,lvm=vg_data"
    
    # Uncomment to enable BadRAM filtering, modify to suit your needs
    # This works with Linux (no patch required) and with any kernel that obtains
    # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
    #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
    
    # Uncomment to disable graphical terminal (grub-pc only)
    #GRUB_TERMINAL=console
    
    # The resolution used on graphical terminal
    # note that you can use only modes which your graphic card supports via VBE
    # you can see them in real GRUB with the command `vbeinfo'
    #GRUB_GFXMODE=640x480
    
    # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
    #GRUB_DISABLE_LINUX_UUID=true
    
    # Uncomment to disable generation of recovery mode menu entries
    #GRUB_DISABLE_RECOVERY="true"
    
    # Uncomment to get a beep at grub start
    #GRUB_INIT_TUNE="480 440 1"
    root@ubuntu-mate:/# 
    
  15. 在 chrooted 环境中运行以下命令:

    root@ubuntu-mate:/# update-grub
    Generating grub configuration file ...
    ...
    /proc/devices: fopen failed: No such file or directory
    Found linux image: /boot/vmlinuz-4.4.0-38-generic
    Found initrd image: /boot/initrd.img-4.4.0-38-generic
    /proc/devices: fopen failed: No such file or directory
    device node not found
    /proc/devices: fopen failed: No such file or directory
    device node not found
    Found linux image: /boot/vmlinuz-4.4.0-31-generic
    Found initrd image: /boot/initrd.img-4.4.0-31-generic
    /proc/devices: fopen failed: No such file or directory
    /proc/devices: fopen failed: No such file or directory
    /proc/devices: fopen failed: No such file or directory
    device node not found
    ...
    device node not found
    /proc/devices: fopen failed: No such file or directory
    device node not found
    Found memtest86+ image: /memtest86+.elf
    Found memtest86+ image: /memtest86+.bin
    grep: /proc/mounts: No such file or directory
    Cannot find list of partitions!  (Try mounting /sys.)
    done
    root@ubuntu-mate:/# 
    

    这里删除了几十个device node not found错误,update-grub 产生这么多错误是正常的吗?

  16. 重新启动并启动到加密的 Ubuntu。系统将提示您输入密码。

    重启期间,Windows 10 默认启动。如果我点击Esc并从列表中选择 Ubuntu,Ubuntu 会开始启动但cryptsetup失败并显示以下错误消息:

    cryptsetup: cryptsetup failed, bad password or options?
    /scripts/local-top/cryptroot: line:1 /sbin/cryptsetup: not found.
    

这次失败的原因是什么?我该如何解决?

/etc/modules文件是空的。应该有东西吗?

答案1

我终于有时间来解决这个问题。

错误发生在第 10 步。我错过了这部分:

mount -t proc proc /proc
mount -t sysfs sys /sys
mount -t devpts devpts /dev/pts

修复该问题后,安装顺利进行。

有关的其他说明参考答案

  • 作者修改了答案,因此,如果您阅读了所有评论,说您可以跳过步骤 12、14、15,那么您就错了。修改考虑到了这些评论,并且这些步骤已从说明中删除,因此请不要跳过任何步骤。
  • 我按照这些说明安装了 Ubuntu Mate LTS 16.4.1。

我还注意到实际上,无需退出 Ubuntu 安装程序 GUI,就可以使用 LUKS 加密分区安装双启动。此选项的缺点是您只能创建 1 个加密分区。因此,使用 GUI 安装程序,您可以进行如下配置:

  • 非加密启动
  • 加密根

然后如果需要的话,在加密的根目录中创建交换文件这些说明

相关内容