Skip to main content
Safely remove Windows from the Windows-Ubuntu Server dual boot.
  1. posts/

Safely remove Windows from the Windows-Ubuntu Server dual boot.

·2906 words·14 mins·
quyendvt
Author
quyendvt
a random guy on the internet

Hugo ships with several built-in shortcodes for rich content, along with a privacy config and a set of simple shortcodes that enable static and no-JS versions of various social media embeds.

Inspect
#

Kiểm tra phân vùng EFI
#

root@ubuntu-aio:~# tree -L 4 /boot/efi
/boot/efi
├── EFI
│   ├── Boot
│   │   ├── bootx64.efi
│   │   ├── fbx64.efi
│   │   └── mmx64.efi
│   ├── Microsoft
│   │   ├── Boot
│   │   │   ├── BCD
│   │   │   ├── BCD.LOG
│   │   │   ├── BCD.LOG1
│   │   │   ├── BCD.LOG2
│   │   │   ├── bg-BG
│   │   │   ├── bootmgfw.efi
│   │   │   ├── bootmgr.efi
│   │   │   ├── boot.pnd.stl
│   │   │   ├── BOOTSTAT.DAT
│   │   │   ├── boot.stl
│   │   │   ├── CIPolicies
│   │   │   ├── cs-CZ
│   │   │   ├── da-DK
│   │   │   ├── de-DE
│   │   │   ├── el-GR
│   │   │   ├── en-GB
│   │   │   ├── en-US
│   │   │   ├── es-ES
│   │   │   ├── es-MX
│   │   │   ├── et-EE
│   │   │   ├── fi-FI
│   │   │   ├── Fonts
│   │   │   ├── fr-CA
│   │   │   ├── fr-FR
│   │   │   ├── hr-HR
│   │   │   ├── hu-HU
│   │   │   ├── it-IT
│   │   │   ├── ja-JP
│   │   │   ├── kd_02_10df.dll
│   │   │   ├── kd_02_10ec.dll
│   │   │   ├── kd_02_1137.dll
│   │   │   ├── kd_02_1414.dll
│   │   │   ├── kd_02_14e4.dll
│   │   │   ├── kd_02_15ad.dll
│   │   │   ├── kd_02_15b3.dll
│   │   │   ├── kd_02_1969.dll
│   │   │   ├── kd_02_19a2.dll
│   │   │   ├── kd_02_1af4.dll
│   │   │   ├── kd_02_8086.dll
│   │   │   ├── kd_07_1415.dll
│   │   │   ├── kd_0C_8086.dll
│   │   │   ├── kdnet_uart16550.dll
│   │   │   ├── kdstub.dll
│   │   │   ├── ko-KR
│   │   │   ├── lt-LT
│   │   │   ├── lv-LV
│   │   │   ├── memtest.efi
│   │   │   ├── nb-NO
│   │   │   ├── nl-NL
│   │   │   ├── pl-PL
│   │   │   ├── pt-BR
│   │   │   ├── pt-PT
│   │   │   ├── qps-ploc
│   │   │   ├── qps-plocm
│   │   │   ├── Resources
│   │   │   ├── ro-RO
│   │   │   ├── ru-RU
│   │   │   ├── SecureBootRecovery.efi
│   │   │   ├── sk-SK
│   │   │   ├── sl-SI
│   │   │   ├── sr-Latn-RS
│   │   │   ├── sv-SE
│   │   │   ├── tr-TR
│   │   │   ├── uk-UA
│   │   │   ├── winsipolicy.p7b
│   │   │   ├── zh-CN
│   │   │   └── zh-TW
│   │   └── Recovery
│   │       ├── BCD
│   │       ├── BCD.LOG
│   │       ├── BCD.LOG1
│   │       └── BCD.LOG2
│   └── ubuntu
│       ├── BOOTX64.CSV
│       ├── grub.cfg
│       ├── grubx64.efi
│       ├── mmx64.efi
│       └── shimx64.efi
└── System Volume Information

48 directories, 39 files
root@ubuntu-aio:~#
root@ubuntu-aio:~# tree -L 3 /boot/efi
/boot/efi
├── EFI
│   ├── Boot
│   │   ├── bootx64.efi
│   │   ├── fbx64.efi
│   │   └── mmx64.efi
│   ├── Microsoft
│   │   ├── Boot
│   │   └── Recovery
│   └── ubuntu
│       ├── BOOTX64.CSV
│       ├── grub.cfg
│       ├── grubx64.efi
│       ├── mmx64.efi
│       └── shimx64.efi
└── System Volume Information

8 directories, 8 files
root@ubuntu-aio:~#
oot@ubuntu-aio:~# tree /boot/efi
/boot/efi
├── EFI
│   ├── Boot
│   │   ├── bootx64.efi
│   │   ├── fbx64.efi
│   │   └── mmx64.efi
│   ├── Microsoft
│   │   ├── Boot
│   │   │   ├── BCD
│   │   │   ├── BCD.LOG
│   │   │   ├── BCD.LOG1
│   │   │   ├── BCD.LOG2
│   │   │   ├── bg-BG
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── bootmgfw.efi
│   │   │   ├── bootmgr.efi
│   │   │   ├── boot.pnd.stl
│   │   │   ├── BOOTSTAT.DAT
│   │   │   ├── boot.stl
│   │   │   ├── CIPolicies
│   │   │   │   └── Active
│   │   │   │       ├── {5DAC656C-21AD-4A02-AB49-649917162E70}.cip
│   │   │   │       ├── {82443e1e-8a39-4b4a-96a8-f40ddc00b9f3}.cip
│   │   │   │       └── {CDD5CB55-DB68-4D71-AA38-3DF2B6473A52}.cip
│   │   │   ├── cs-CZ
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── da-DK
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── de-DE
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── el-GR
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── en-GB
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── en-US
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── es-ES
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── es-MX
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── et-EE
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── fi-FI
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── Fonts
│   │   │   │   ├── chs_boot.ttf
│   │   │   │   ├── cht_boot.ttf
│   │   │   │   ├── jpn_boot.ttf
│   │   │   │   ├── kor_boot.ttf
│   │   │   │   ├── malgun_boot.ttf
│   │   │   │   ├── malgunn_boot.ttf
│   │   │   │   ├── meiryo_boot.ttf
│   │   │   │   ├── meiryon_boot.ttf
│   │   │   │   ├── msjh_boot.ttf
│   │   │   │   ├── msjhn_boot.ttf
│   │   │   │   ├── msyh_boot.ttf
│   │   │   │   ├── msyhn_boot.ttf
│   │   │   │   ├── segmono_boot.ttf
│   │   │   │   ├── segoen_slboot.ttf
│   │   │   │   ├── segoe_slboot.ttf
│   │   │   │   └── wgl4_boot.ttf
│   │   │   ├── fr-CA
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── fr-FR
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── hr-HR
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── hu-HU
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── it-IT
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── ja-JP
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── kd_02_10df.dll
│   │   │   ├── kd_02_10ec.dll
│   │   │   ├── kd_02_1137.dll
│   │   │   ├── kd_02_1414.dll
│   │   │   ├── kd_02_14e4.dll
│   │   │   ├── kd_02_15ad.dll
│   │   │   ├── kd_02_15b3.dll
│   │   │   ├── kd_02_1969.dll
│   │   │   ├── kd_02_19a2.dll
│   │   │   ├── kd_02_1af4.dll
│   │   │   ├── kd_02_8086.dll
│   │   │   ├── kd_07_1415.dll
│   │   │   ├── kd_0C_8086.dll
│   │   │   ├── kdnet_uart16550.dll
│   │   │   ├── kdstub.dll
│   │   │   ├── ko-KR
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── lt-LT
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── lv-LV
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── memtest.efi
│   │   │   ├── nb-NO
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── nl-NL
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── pl-PL
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── pt-BR
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── pt-PT
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── qps-ploc
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── qps-plocm
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── Resources
│   │   │   │   ├── bootres.dll
│   │   │   │   └── en-US
│   │   │   │       └── bootres.dll.mui
│   │   │   ├── ro-RO
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── ru-RU
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── SecureBootRecovery.efi
│   │   │   ├── sk-SK
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── sl-SI
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── sr-Latn-RS
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── sv-SE
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── tr-TR
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   ├── uk-UA
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   └── bootmgr.efi.mui
│   │   │   ├── winsipolicy.p7b
│   │   │   ├── zh-CN
│   │   │   │   ├── bootmgfw.efi.mui
│   │   │   │   ├── bootmgr.efi.mui
│   │   │   │   └── memtest.efi.mui
│   │   │   └── zh-TW
│   │   │       ├── bootmgfw.efi.mui
│   │   │       ├── bootmgr.efi.mui
│   │   │       └── memtest.efi.mui
│   │   └── Recovery
│   │       ├── BCD
│   │       ├── BCD.LOG
│   │       ├── BCD.LOG1
│   │       └── BCD.LOG2
│   └── ubuntu
│       ├── BOOTX64.CSV
│       ├── grub.cfg
│       ├── grubx64.efi
│       ├── mmx64.efi
│       └── shimx64.efi
└── System Volume Information

50 directories, 154 files
root@ubuntu-aio:~#

Kiểm tra phân các boot entry đã lưu vào firmware
#

$ efibootmgr -v
BootCurrent: 0004
Timeout: 2 seconds
BootOrder: 0004,0000,0001,0005
Boot0000* Windows Boot Manager  HD(1,GPT,ea5af0eb-bf0f-4b7a-992d-ac8903e70b08,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)57494e444f5753000100000088000000780000004200430044004f0042004a004500430054003d007b00390064006500610038003600320063002d0035006300640064002d0034006500370030002d0061006300630031002d006600330032006200330034003400640034003700390035007d00000000050100000010000000040000007fff0400
      dp: 04 01 2a 00 01 00 00 00 00 08 00 00 00 00 00 00 00 20 03 00 00 00 00 00 eb f0 5a ea 0f bf 7a 4b 99 2d ac 89 03 e7 0b 08 02 02 / 04 04 46 00 5c 00 45 00 46 00 49 00 5c 00 4d 00 49 00 43 00 52 00 4f 00 53 00 4f 00 46 00 54 00 5c 00 42 00 4f 00 4f 00 54 00 5c 00 42 00 4f 00 4f 00 54 00 4d 00 47 00 46 00 57 00 2e 00 45 00 46 00 49 00 00 00 / 7f ff 04 00
    data: 57 49 4e 44 4f 57 53 00 01 00 00 00 88 00 00 00 78 00 00 00 42 00 43 00 44 00 4f 00 42 00 4a 00 45 00 43 00 54 00 3d 00 7b 00 39 00 64 00 65 00 61 00 38 00 36 00 32 00 63 00 2d 00 35 00 63 00 64 00 64 00 2d 00 34 00 65 00 37 00 30 00 2d 00 61 00 63 00 63 00 31 00 2d 00 66 00 33 00 32 00 62 00 33 00 34 00 34 00 64 00 34 00 37 00 39 00 35 00 7d 00 00 00 00 05 01 00 00 00 10 00 00 00 04 00 00 00 7f ff 04 00
Boot0001  SanDisk SDSA6PM-064G-1006     BBS(HD,,0x0)/VenHw(5ce8128b-2cec-40f0-8372-80640e3dc858,0200)0000424f
      dp: 05 01 09 00 02 00 00 00 00 / 01 04 16 00 8b 12 e8 5c ec 2c f0 40 83 72 80 64 0e 3d c8 58 02 00 / 7f ff 04 00
    data: 00 00 42 4f
Boot0004* Ubuntu        HD(1,GPT,ea5af0eb-bf0f-4b7a-992d-ac8903e70b08,0x800,0x32000)/File(\EFI\UBUNTU\SHIMX64.EFI)
      dp: 04 01 2a 00 01 00 00 00 00 08 00 00 00 00 00 00 00 20 03 00 00 00 00 00 eb f0 5a ea 0f bf 7a 4b 99 2d ac 89 03 e7 0b 08 02 02 / 04 04 34 00 5c 00 45 00 46 00 49 00 5c 00 55 00 42 00 55 00 4e 00 54 00 55 00 5c 00 53 00 48 00 49 00 4d 00 58 00 36 00 34 00 2e 00 45 00 46 00 49 00 00 00 / 7f ff 04 00
Boot0005  G-DRIVE mobile USB 2201       BBS(HD,,0x0)/VenHw(5ce8128b-2cec-40f0-8372-80640e3dc858,0900)0000424f
      dp: 05 01 09 00 02 00 00 00 00 / 01 04 16 00 8b 12 e8 5c ec 2c f0 40 83 72 80 64 0e 3d c8 58 09 00 / 7f ff 04 00
    data: 00 00 42 4f
dvtq-user@ubuntu-aio:/boot/efi$

Kiểm tra các phân vùng
#

root@ubuntu-aio:~# fdisk -l
Disk /dev/loop0: 73.95 MiB, 77545472 bytes, 151456 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 /dev/loop1: 73.95 MiB, 77545472 bytes, 151456 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 /dev/loop2: 76.59 MiB, 80310272 bytes, 156856 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 /dev/loop3: 76.61 MiB, 80326656 bytes, 156888 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 /dev/loop4: 50.77 MiB, 53235712 bytes, 103976 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 /dev/loop5: 50.93 MiB, 53399552 bytes, 104296 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 /dev/sda: 58.69 GiB, 63023063040 bytes, 123091920 sectors
Disk model: SanDisk SDSA6PM-
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 053FC10C-602D-498A-B2EA-2EC24B6D03F2

Device         Start       End  Sectors  Size Type
/dev/sda1       2048    206847   204800  100M EFI System
/dev/sda2     206848    239615    32768   16M Microsoft reserved
/dev/sda3     239616  79931391 79691776   38G Microsoft basic data
/dev/sda4   79931392 121595903 41664512 19.9G Microsoft basic data
/dev/sda5  121595904 123088895  1492992  729M Windows recovery environment


Disk /dev/sdb: 298.09 GiB, 320072933376 bytes, 625142448 sectors
Disk model: mobile USB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 1A4756E0-426B-03B6-B8D5-91C69A90ED00

Device     Start       End   Sectors   Size Type
/dev/sdb1   2048 625141759 625139712 298.1G Microsoft basic data
root@ubuntu-aio:~#

Steps
#

Tạo USB
#

  • Tải ile gparted-live-…-amd64.iso vào USB

Remove Windows OS partion
#

  • Dùng USB boot vào và dùng Mini tool partition wizard để remove 2 phân vùng:

      1. Windows OS (Basic data partition)
      1. Microsoft reserved partition (16MB)
      1. Phân vùng gì đó của windows 730MB
  • Chỉ trừa lại 2 partion là

    • Ext4
    • EFI (fat32) được mount vào /boot
  • Dùng Gparted để merge

  • Lần đầu kjowir động sẽ hơi lâu chút You are in emergency mode, after login enter: journalctl -xb

Dùng mini tool merge các phân vùng lại vào ext4
#

  • Hoặc dùng gparted như sau: https://www.youtube.com/watch?v=eWf_6Xrg-Xo

  • Reboot:

    • Lúc này vì menu boot vẫn default là Ubunut nên vẫn boot được dù phân vùng Windows đã xoá
    • Lúc này menu boot vẫn còn mục Windows Boot Manager

Tạo lại grub (Từ chính ubuntu server)
#

# Check nếu mục GRUB_DISABLE_OS_PROBER=false là OK (uncomment nó đi)
# (vì os-prober bị disable mặc định ở một số bản Ubuntu mới)
nano /etc/default/grub

# Dò tìm lại boot partition để chuẩn bị cho Grub tạo lại file cấu hình /boot/grub/grub.cfg
os-prober

# Generate new grub config
grub-mkconfig -o /boot/grub/grub.cfg
## Log ví dụ:
# [root@kmdtech-pc ~]# grub-mkconfig -o /boot/grub/grub.cfg
# Generating grub configuration file
# Found linux image: /boot/vmlinuz-linux
# Found initrd image: /boot/amd-ucode. img /boot/initramfs-linux. img
# Found fallback initrd image(s) in /boot: amd-ucode. img initramfs-linux-fallback. img
# Warning: os-prober will be executed to detect other bootable partitions.
# Its output will be used to detect bootable binaries on them and create new boot entries.
# Adding boot menu entry for UEFI Firmware Settings
# done
# [root@kmdtech-pc ~]#

# Kiểm tra lại các boot entry => Vẫn thấy có mục Boot0004: Windows Boot Manager
efibootmgr

# Xoá mục dư thừa khỏi firmware boot entry
efibootmgr -b 0004 -B

# Reboot lại
# => Đã mất mục `Windows Boot Manager`

Đào sâu hơn
#

NOTE:

  • Boot loader không tự động scan các file trong phân vùng EFI để tạo menu boot mà nó đọc từ boot entry đã lưu trong firmware
  • Các mục này trong boot entry sẽ map với/ ứng với 1 EFI file trong phân vùng EFI
  • Các binary file này sẽ load cấu hình riêng của nó (tức là /boot/grub/grub.cfg) để render và hiển thị ra grub menuboot. Menu này có
    • Ubuntu
    • Windows boot manager: redirect boot chain sang cho file EFI của windows nằm trong phân vùng EFI

3. GRUB menu vs Firmware boot menu (rất hay bị nhầm)
#

So sánh rõ ràng
#

Thành phầnBản chất
GRUB menuMenu của hệ điều hành
Firmware boot menuMenu của mainboard
Windows entry trong GRUBChainload
Windows entry trong firmwareBoot trực tiếp