dual boot windows and ubuntu
Contents
dual boot windows and ubuntu
https://askubuntu.com/questions/1506694/dual-boot-with-windows-11-and-bitlocker/1514161#1514161
Ubuntu 版本: 22.04
用 clonezill 备份硬盘
- 在硬盘上准备一块空闲的空间, 用 windows 的磁盘管理工具调整现有的分区
用 balenaEtcher
制作 ubuntu 安装盘 (U盘)
- 在 BIOS 里确认 Secure Boot 已经开启
- 用分区工具在 U 盘或移动硬盘上准备一个大于 100MB 的 FAT32 分区
- 从 U 盘引导, 安装 ubuntu, 选择 Try or install Ubuntu
- Select Language: English
- Install> Install Ubuntu
- Keyboard: English(US)> English(US)
- Wireless
- What apps would you like to install to start with: Minimal installation
- 勾选 Install third-party software for graphics and wi-fi hardware and additional media formats
- 勾选 Configure Secure Boot, 设置 Secure boot 密码
备份 windows 的 EFI 分区 到 U 盘 (/dev/sda2)
open a terminal with ctrl+alt+t
- 切换到 root 用户: sudo -i
lsblk
to list all devices- 挂载 FAT32 分区
mkdir /mnt/persistent
mount /dev/sda2 /mnt/persistent
mkdir /mnt/persistent/efi-backup
- Mount the Windows bootloader partition
mkdir /mnt/efi
mount /dev/nvme0n1p1 /mnt/efi
- Backup all the data on it, and make sure to correctly execute rsync as shown here (with trailing slashes):
rsync -av /mnt/efi/ /mnt/persistent/efi-backup/
- Now we delete the content on the efi partition (don’t be scared, we will copy it back later)
rm -rf /mnt/efi/*
- Umount again the efi partition
umount /mnt/efi
umount /mnt/persistent
安装 Ubuntu
因为 Ubuntu 的安装程序如果选加密 (LUKS) 安装的话, 只能把 window 删掉. 所以我们的第一次安装硬盘是没有加密的, 安装好之后再把 /root 分区的文件, 复制到加密的分区.
- 回到 Ubuntu 的图形化安装环境, 选择 something else, click continue
- 选择 free space, 一般在 /dev/nvme0n1p3 和 /dev/nvme0n1p4 之间
- 点击加号创建分区
- 创建一个 512 MB 的分区 (/dev/nvme0n1p5), ubuntu 的 EFI 分区
- Use as: EFI System Partition
- 创建一个 2048MB 的分区 (/dev/nvme0n1p6), Ubuntu 的 /boot 分区
- Use as: Ext4 journaling file system
- Mount point:
/boot
- 创建一个 12000MB 的的分区 (/dev/nvme0n1p7), Ubuntu 的 /root 分区
- Use as: Ext4 journaling file system
- mount point:
/
- 之后会删掉, 这个分区不需要太大
- 创建一个 512 MB 的分区 (/dev/nvme0n1p5), ubuntu 的 EFI 分区
- Device for bootloader installation: 选择新的 EFI 分区: /dev/nvme0n1p5, 点击 Install Now
- 这里选择了 /dev/nvme0n1p5 但是 Ubuntu 还是会安装到 /dev/nvme0n1p1, (Ubuntu installer 的 bug, 这就是前面备份 windows EFI 分区的原因)安装完成之后再把备份的 windows boot loader 恢复回来
- 选择时区
- Who are you
- Your name: xxx
- Your computer’s name: xxx
- Pick a username: xxx
- Choose a password: xxx
- Confirm your password: xxx
- 安装结束之后不要点击 Restart Now, 点击右上角的
X
关闭窗口, 系统会回到 Ubuntu live usb 的桌面
把 Ubuntu 的 EFI 分区复制到 /dev/nvme0n1p5
open a terminal with ctrl+alt+t, 切换到 root 用户: sudo -i 把 ubuntu installer 刚才安装的 /dev/nvme0n1p1 复制到 /dev/nvme0n1p5
|
|
把之前备份的 windows boot loader 恢复到 /dev/nvme0n1p1
|
|
umount
|
|
把 Ubuntu 复制到加密分区 LVM on LUKS
在 terminal 运行 gparted 创建新分区 (/dev/nvme0n1p8)
选中 /dev/nvme0n1p7 后面的 unallocated 空间
创建分区
- File system: cleared
- click Add
Apply All Operations
关掉 gparted, 回到 root terminal
加密分区 /dev/nvme0n1p8
LVM on LUKS, 管理起来更简单, 可以用一个密码解密所有的分区, 可以加密 swap 分区
|
|
把之前安装的未加密的 Ubuntu 拷到新的加密分区
|
|
删除旧的未加密的 ubuntu, 扩展加密分区
https://wiki.archlinux.org/title/Resizing_LVM-on-LUKS
open gparted, 在 gparted 里删除未加密的 ubuntu 分区, /dev/nvme0n1p7
|
|
chroot to configure new installation
|
|
And now put in a new entry with your copied UUID
|
|
|
|
|
|
Now apply update
|
|
And lets also update grub We will also make it detect Windows vim /etc/default/grub
And add GRUB_DISABLE_OS_PROBER=false Now update update-grub
And lets exit the chroot exit
umount /mnt/root-new/dev/ umount /mnt/root-new/proc/ umount /mnt/root-new/sys umount /mnt/root-new/run umount /mnt/root-new/boot/efi umount /mnt/root-new/boot umount /mnt/root-new
UEFI boot order As a last step we will check the boot order and create a new entry for our new EFI partition
Check all entries
efibootmgr -v
Locate the old Ubuntu entry, which was created for wrong EFI partiiton and delete it
efibootmgr -b 0001 -B
Create new one for correct partition, here nvme0n1p5
efibootmgr –create –disk /dev/nvme0n1 –part 5 –label “Ubuntu” –loader /EFI/ubuntu/shimx64.efi
Check if all fine
efibootmgr -v
/dev/nvme0n1
- /dev/nvme0n1p1: 100MB, window bootloader EFI
- /dev/nvme0n1p2: 16MB, unknown, created by windows
- /dev/nvme0n1p3: 378G, windows data NTFS (bitlocker)
- /dev/nvme0n1p4: 890MB, windows recovery
- /dev/nvme0n1p5: 487MB, ubuntu boot loader EFI
- /dev/nvme0n1p6: 1.9G, ubuntu /boot
- /dev/nvme0n1p7: 11.2G, ubuntu /root (original) (delete)
- /dev/nvme0n1p8: 84.1G, ubuntu (LVM PV + LUKS)
- nvme0n1p8_crypt
- vgubuntu-swap_1 16G ubuntu swap
- vgubuntu-root 67G ubuntu /root
获取和保存 BitLocker recovery key: https://account.microsoft.com/devices/recoverykey
shrink your BitLocker encrypted partition
create an Ubuntu live USB stick
BACKUP device to image via Clonezilla https://blog.csdn.net/dqz1231/article/details/127947178
create an Ubuntu live USB stick
Create another partition in the free space of the USB stick at the end as FAT32
检查 secure boot 是否已经开启
backup EFI partition
create an Ubuntu live USB stick
- partition schema: GPT
balenaEtcher
https://etcher.balena.io/#download-etcher
- flash from file
- select target
- Flash!
secure boot
https://www.cnblogs.com/dongxb/p/16717567.html
https://zhuanlan.zhihu.com/p/481696760
initramfs
https://manpages.ubuntu.com/manpages/focal/en/man8/update-initramfs.8.html
update-initramfs - generate an initramfs image
https://help.ubuntu.com/community/ResizeEncryptedPartitions
LVM + LUKS 磁盘扩容
Author -
LastMod 2024-05-19