Windows 10 Fall Creators Update (1709) destroys Linux Partitions

It was time for me to do the Fall Creator Update to Win10 1709 from my current Win10 1607 installation that i use on my dualboot system together with Fedora 27. And because it is a big update, i decided to do some preparations. I made backups of everything including the disk layout and updated with a flash drive like Microsoft described it here.
The Update itself worked pretty well, after i made sure that Windows is the default UEFI boot entry. No major error and the new Windows features worked immediately.
But: Now Linux was not able to boot.
Usually this is nothing special, it is well known that after big Windows Updates or Installations you have to reinstall GRUB (or whatever bootloader you are using). I am used to this in my >15years of Windows-Linux-Dualboot experience.
But this time it was special.

Lets see what happened… this was the partition layout before the Update (fdisk):

Gerät         Anfang      Ende  Sektoren  Größe Typ
/dev/sda1       2048    534527    532480   260M EFI-System
/dev/sda2     534528    567295     32768    16M Microsoft reserviert
/dev/sda3     567296 265443327 264876032 126,3G Microsoft Basisdaten
/dev/sda4  265443328 266364927    921600   450M Windows-Wiederherstellungsumgebung
/dev/sda5  266364928 268462079   2097152     1G Linux-Dateisystem
/dev/sda6  268462080 537234734 268772655 128,2G Linux-Dateisystem

Here the UUIDs of the Linux partitions with blkid:

/dev/sda5: LABEL="Fedora-Boot" UUID="5bed5e31-25a0-4446-8557-285098cc5812" TYPE="ext2" PARTUUID="826dae72-36a5-408a-89f6-8a16e2906fca"
/dev/sda6: UUID="64725166-1b67-4393-aa3c-b4097e3c869a" TYPE="crypto_LUKS" PARTUUID="3cc18e74-de0b-4e2e-a906-b7328136f737"

And here the partition layout after the Update (gdisk):

Number  Start (sector)    End (sector)  Size       Code  Name
1            2048          534527   260.0 MiB   EF00  EFI System Partition
2          534528          567295   16.0 MiB    0C01  Microsoft reserved ...
3          567296       264405092   125.8 GiB   0700  Basic data partition
4       264407040       265441279   505.0 MiB   2700
5       265443328       266364927   450.0 MiB   2700
6       266364928       268462079   1024.0 MiB  8300
7       268462080       537234734   128.2 GiB   8300

And the UUIDs of the Linux partitions with blkid (it is sdb because its from a booted live system):

/dev/sdb6: PARTUUID="826dae72-36a5-408a-89f6-8a16e2906fca"
/dev/sdb7: PARTUUID="3cc18e74-de0b-4e2e-a906-b7328136f737"

Here we can see that Windows Update shrinked the sda3 partition (Windows C: drive) and created a new Recovery Partition in the resulting space (even thought that we already have one). The Linux Partitions in the Partitiontable did not get touched, their start- and end-sector and PARTUUID are the same. The Linux stuff in the EFI partition is also still present and the Linux Boot entry in the UEFI is still there.
But the UUID, the label and the filesystem type of both partitions vanished. Those information belong to the Filesystem itself and are not part of the partitiontable, they are on the partition itself.
Windows Update destroyed the Linux Partitions. It did overwrite the Filesystem there. The 1GB partition had an ext2 filesystem of /boot and the 128GB partition was an LUKS encrypted partition. Both were wrecked and completely useless now. There was no way to even mount those partitions in a booted live system and no way to repair them (it always complained about brocken superblock and the BackUp superblocks didn’t work either), the data on them was completely lost.
The only way to repair it was with formatting those partitions again and restoring from full backups.

Move Windows 10 to SSD on a UEFI Dualboot System with basic Linux Tools

I have Windows and Fedora in Dualboot on my Notebook. My 1TB HDD is not very fast, so i installed a new additional 275GB SSD and i moved Windows C:\ and Fedora Root to the SSD.
It was very tricky and i am sure that i will forget the commands i used in the future, so i will write it down.

This is the initial Partitioning of the HDD (/dev/sdb):

[root@fedora ~]# fdisk -l /dev/sdb
Festplatte /dev/sdb: 931,5 GiB, 1000204886016 Bytes, 1953525168 Sektoren
Einheiten: Sektoren von 1 * 512 = 512 Bytes
Sektorgröße (logisch/physikalisch): 512 Bytes / 4096 Bytes
E/A-Größe (minimal/optimal): 4096 Bytes / 4096 Bytes
Festplattenbezeichnungstyp: gpt
Festplattenbezeichner: 28542C82-BC46-4DFB-8B09-11B412039DEE

Gerät         Anfang       Ende   Sektoren  Größe Typ
/dev/sdb1       2048     411647     409600   200M EFI-System
/dev/sdb2     411648     444415      32768    16M Microsoft reserviert
/dev/sdb3     444416  265320447  264876032 126,3G Microsoft Basisdaten
/dev/sdb4  418920448  419842047     921600   450M Windows-Wiederherstellungsumgebung
/dev/sdb5  419842048  453396479   33554432    16G Linux Swap
/dev/sdb6  453396480  455493631    2097152     1G Linux-Dateisystem
/dev/sdb7  455493632  663111679  207618048    99G Linux-Dateisystem
/dev/sdb8  663111680 1953525134 1290413455 615,3G Microsoft Basisdaten

You can see that sdb2, sdb3 and sdb4 are the Windows Partitions and everything after it is Linux stuff. I already shrank /dev/sdb3 to an appropriate size (in Windows with the built in Disk Management Tool).
/dev/sdb8 is some ordinary NTFS-Partition with Music, Videos, Downloads, installed Applications etc.. This should stay on the HDD.

Preparing Windows

As i said before, i already shrank the Windows C:\ Partition on the HDD to an approriate size for the SSD (126GB). That is important because i will copy every Byte of the Partition with dd, it will have the same size after migrating to the SSD.

Additionally we have to disable the Windows Recovery Environment stuff on /dev/sdb4, because that thing is very unreliable and doesn’t behave well in Dualboot.
Boot Windows, start cmd with admin rights and type:

reagentc /disable

AND we need to create a Windows 10 Recovery Media (This is important! We need it to install the EFI-Bootloader.).

Create Partitions on the SSD

I use gdisk and fdisk to create and modify partitions in Linux.
Start gdisk as root on the SSD (here /dev/sda)

gdisk /dev/sda

Start with an empty GPT Partiton Table by pressing o, and create a EFI System Partition with 260MiB:
n -> (Partition Number) 1 -> (Startsector) Enter -> (Endsector) +270M -> (Type) EF00 (EFI System Partition)

Now we need to create 3 Partitions on the SSD with exactly the same Size (same amount of Sectors with the same size) , Type, Name AND Attributes as sdb2, sdb3 and sdb4 from the HDD.
Use gdisk -l /dev/sdb and fdisk -l /dev/sdb to get the proper information. If you want to know some Details (like the full Name and Attributes), press i in gdisk and enter the Partition Number. You will have to go to Expert Mode x in gdisk to change the Attributes. When you are done, write the Partition Table with w.

The Partition Table of the SSD now looks like this:

[root@fedora ~]# fdisk -l /dev/sda
Festplatte /dev/sda: 256,2 GiB, 275064201216 Bytes, 537234768 Sektoren
Einheiten: Sektoren von 1 * 512 = 512 Bytes
Sektorgröße (logisch/physikalisch): 512 Bytes / 512 Bytes
E/A-Größe (minimal/optimal): 512 Bytes / 512 Bytes
Festplattenbezeichnungstyp: gpt
Festplattenbezeichner: E3CAB581-554A-4657-974F-84E34627D6B4

Gerät         Anfang      Ende  Sektoren  Größe Typ
/dev/sda1       2048    534527    532480   260M EFI-System
/dev/sda2     534528    567295     32768    16M Microsoft reserviert
/dev/sda3     567296 265443327 264876032 126,3G Microsoft Basisdaten
/dev/sda4  265443328 266364927    921600   450M Windows-Wiederherstellungsumgebung
[root@fedora ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 537234768 sectors, 256.2 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): E3CAB581-554A-4657-974F-84E34627D6B4
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 537234734
Partitions will be aligned on 2048-sector boundaries
Total free space is 270871821 sectors (129.2 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
1            2048          534527   260.0 MiB   EF00  EFI System Partition
2          534528          567295   16.0 MiB    0C01  Microsoft reserved ...
3          567296       265443327   126.3 GiB   0700  Basic data partition
4       265443328       266364927   450.0 MiB   2700

Format EFI System Partition and Clone Windows

We will format the EFI System Partition in FAT32:

mkfs.fat -F32 /dev/sda1

And clone the three Windows Partitions

dd if=/dev/sdb2 of=/dev/sdb2 bs=2M
dd if=/dev/sdb3 of=/dev/sdb3 bs=2M
dd if=/dev/sdb4 of=/dev/sdb4 bs=2M

Change GUID of Windows Partitions

Windows does access it’s Partitions by their UUID (Linux does the same on most Distributions, but in Linux we can just change /etc/fstab and reinstall GRUB — you can’t do this with Windows). If you don’t change the UUIDs, your system will either be not bootable or it will have some strange Bugs like a flickering screen.

List Partitions UUIDs

Start fdisk, on the HDD (fdisk /dev/sdb) go to expert mode (x) and print the partition table (p):

Expertenbefehl (m für Hilfe): p

Festplatte /dev/sdb: 931,5 GiB, 1000204886016 Bytes, 1953525168 Sektoren
Einheiten: Sektoren von 1 * 512 = 512 Bytes
Sektorgröße (logisch/physikalisch): 512 Bytes / 4096 Bytes
E/A-Größe (minimal/optimal): 4096 Bytes / 4096 Bytes
Festplattenbezeichnungstyp: gpt
Festplattenbezeichner: 28542C82-BC46-4DFB-8B09-11B412039DEE
Erster LBA: 34
Letzter LBA: 1953525134
Alternative LBA: 1953525167
LBA mit Partitionseinträgen: 2
Zugeordnete Partitionseinträge: 128

Gerät         Anfang       Ende   Sektoren Typ-UUID                             UUID                                 Name                         Attr.
/dev/sdb1       2048     411647     409600 C12A7328-F81F-11D2-BA4B-00A0C93EC93B AE710130-C001-42B2-8237-E688B102E731 EFI System Partition
/dev/sdb2     411648     444415      32768 E3C9E316-0B5C-4DB8-817D-F92DF00215AE 0310D237-5287-46A3-A41A-9409C78232FC Microsoft reserved partition
/dev/sdb3     444416  265320447  264876032 EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 8A273F28-7483-4972-9D21-5EA1E3326EE9 Basic data partition
/dev/sdb4  418920448  419842047     921600 DE94BBA4-06D1-4D40-A16A-BFD50179D6AC EAA2D666-3BB9-410F-A1BD-B7CB5F140375                              RequiredPartiton
/dev/sdb5  419842048  453396479   33554432 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F 731861D8-7515-4AAA-9907-51E3B3FECCE6
/dev/sdb6  453396480  455493631    2097152 0FC63DAF-8483-4772-8E79-3D69D8477DE4 7E2D59C3-C10E-427F-B9F2-A84031F9FA53
/dev/sdb7  455493632  663111679  207618048 0FC63DAF-8483-4772-8E79-3D69D8477DE4 7E869168-7C7D-427D-881D-89E18094F601
/dev/sdb8  663111680 1953525134 1290413455 EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 B39A1F99-BD8D-4EAD-AB73-EBAF2101A5CF

We can’t have multiple partitions with the same UUID, so it’s best to delete them from the HDD.
You can BackUp the Partitiontable with dd if=/dev/sdb of=./path/to/backup.img bs=512 count=4 before doing that. When you fuck up, just restore it with dd if=./path/to/backup.img of=/dev/sdb bs=512 count=4 and your Windows Partitions will be back.

Copy the UUIDs of sdb2, sdb3 and sdb4 to some file and DELETE the 3 Partitions in fdisk wit d.

Now enter fdisk on the HDD, go to Expert Mode (x) and change the UUID (u) of sda2, sda3 and sda4 (SSD) to the ones you copied from the deleted sdb2, sdb3 and sdb4.

Note: This are the UUIDs (or GUIDs) of the Partitions. Every Filesystem has an UUID too, you can view them witk blkid.
The UUIDs of the three NTFS/FAT32-Filesystems on sda2, sda3 and sda4 are already the same as sdb2,sdb3 and sdb4, because dd copied the whole partition, including the UUID, Bootsector, Extended Attributes, etc.
If you want to change NTFS or FAT32 UUIDs, you need to do it with an hexeditor like hexedit /dev/sdb3. They are at the beginning of the partition.

Boot to Win10 recovery and install EFI-Bootloader

Boot the Windows 10 recovery media and open the command prompt in the Advanced screen.

Check if C:\ is your Systempartition from the SSD (cd /d C: and dir — if there is some Windows and Application folder, it should be correct).

Execute diskpart and enter sel disk 0 and list partition.

C:\Windows\system32>diskpart

Microsoft DiskPart-Version 10.0.14393.0

Copyright (C) 1999-2013 Microsoft Corporation.
Auf Computer: ACERNETBOOK

DISKPART> sel disk 0

Datenträger 0 ist jetzt der gewählte Datenträger.

DISKPART> list volume

  Volume ###  Bst  Bezeichnung  DS     Typ         Größe    Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 1     C                NTFS   Partition    126 GB  Fehlerfre  Startpar
  Volume 2                      FAT32  Partition    260 MB  Fehlerfre  System
  Volume 3                      NTFS   Partition    450 MB  Fehlerfre  Versteck
  Volume 4         Data         NTFS   Partition    615 GB  Fehlerfre


DISKPART>

Volume 2 is our EFI System Partition (FAT32 and 260MiB), we will assign it  a Drive Letter and exit diskpart

DISKPART> sel vol 2

Volume 2 ist jetzt das gewählte Volume.

DISKPART> assign letter=v:

Der Laufwerkbuchstabe oder der Bereitstellungspunkt wurde zugewiesen.

DISKPART> exit

Datenträgerpartitionierung wird beendet...

C:\Windows\system32>

And install the Bootloader to the EFI Parition

bcdboot C:\Windows /s v: /f ALL

Reboot and Windows should start from the SSD.
Done 🙂

Set the Clock on a Dual-Boot-System with Windows

The Operating System gets the current time from the Hardware-Clock during boot.
The problem with that: Windows expects the hardware-clock to be in the time of the current timezone, while Linux (and every other OS) expects the time in UTC.

Now you have two choices:

  • tell Windows that the hardware-clock is in UTC, or
  • tell Linux that the hardware-clock is in localtime

Since having the hardware-clock in UTC is standard, i recommend to change the settings of Windows.
And this is how its done:

  1. Set the correct time in Linux and write it to the hardware-clock:
    #date -s HH:MM:SS
    #hwclock --systohc
  2. Boot Windows (now it should display the wrong time in Windows)
  3. type ‚regedit‘ in the Run-Prompt of the Start-Menu (or Alt-F2)
  4. go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\
  5. Create a new DWORD-item (right-click\New) and name it RealTimeIsUniversal
  6. Give it a hex value of ‚1‘
  7. restart

Done 🙂