[Errata] Windows upgrade to 1703 broke grub

What happened?

After windows upgrading itself to release 1703 aka. the creator update, Grub bootloader can no longer start and says error: unknown filesystem and dropped in to grub rescue shell. Windows boots up fine from firmware memu.

TL; DR

Manually doing hexediting just taught me another valuable lesson: @Windows has the worst upgrade handling.

— @cth451 July 28, 2017

  1. Prepare a USB linux live environment.
  2. Find the correct partition number, it might have been changed during upgrade.
  3. Look for grubx64.efi in your EFI system partition and use a hex editor to open it
  4. Search for /boot/grub and notice the (,gptN) where N is your original partition number for linux OS.
  5. Change N to the new parition number, save the file and reboot.

Analysis

Before upgrade, my partition scheme was:

  • sda1 fat32: EFI system parition
  • sda2 ext4: Archlinux root filesystem
  • sda4 ntfs: Windows drive C
  • sda3 ext4: AOSC OS root filesystem

Partition numbers were not exactly in physical order of data, for I shrinked Archlinux to make room for Windows installation. However after upgrade, it became:

  • sda1 fat32: EFI system parition
  • sda2 ext4: Archlinux root filesystem
  • sda3: Windows drive C
  • sda4: Windows recovery environment
  • sda5: AOSC OS root filesystem

So what did windows do down there? It shrinked drive C and made a little recovery partition, then re-sorted the partition numbers. However grub bootloader looks for partitions by partition number. It tried parition 3 (which was a valid linux filesystem), but it’s an ntfs now.

This partition number is hardcoded into the bootloader efi image, so we need to manually hexedit it.

Time-based One Time Password Algorithm

Follow the algorithm

As implemented in Google Authenticator app, you’ll need:

  • A shared secret key K, which is base32 encoded
  • a specific time period since UNIX epoch T

I’ll use K = GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ and T = 1450235092 (which is Wed, 16 Dec 2015 11:04:52 CST) for example. In the Google Authenticator App, both K and T are passed to TOTP as hexadecimal values (or byte arrays).

Since K is a base32 encoded string, we’ll decode it to byte format. Password changes every 30 seconds, T should be divided by 30, tuncated to integer and converted to hex and padded to 16 hexadecimal digits.

Continue reading Time-based One Time Password Algorithm

Systemd Timers小结

分析

Linux上的守护进程cron能够根据配置好的crontab定时地执行某一个动作,现在用上systemd了想要找一个替代品,于是找到了timertimer和其他的配置单元结构差不多,只是有一个[Timer]段,在这里可以定义它的行为。基本的写法是Name=Value。

作为一个timer必须要有

[Install]
WantedBy=timers.target

[Unit] Description=Value

这个字段允许添加对配置单元的描述

[Timer] Unit=Value

用于指定该timer触发时要启动的配置单元,如果不写的话,example.timer触发时会执行同名的example.service

[Timer] 绝对触发时间

OnCalendar=Value可以指定在系统时钟的某一特定时刻触发timer。懒的话可以直接使用hourlymonthly这样的词语,也可以输入DAY YYYY-MM-DD HH:MM:SS。比如hourly*:00:00等价,Wed *:00:00就是每个星期三隔一个小时触发一次。 Continue reading Systemd Timers小结

[Updated Aug 10, 2015]正确的调教wine容器和Evernote

Environment

  • 启用了multilib的最新Archlinux 64-bit
    # pacman -Syu
  • 带有monogecko的Wine 1.7.x
    # pacman -S wine wine_gecko wine-mono mono
  • winetricks,干吗的不用说也明白
    # pacman -S winetricks
  • 顺手的下载器和浏览器
    我的是wgetgoogle-chrome
  • 可能一定会用到梯子和proxychains-ng,自行准备,下载字体要用

Preparation

  1. Evernote官方下载安装包
    $ wget -O "Evernote-Install.exe" "https://evernote.com/download/get.php?file=Win"
    ……我可没说一定要用wget,圣战请移步
  2. 开新的wine容器,名称为evernote
    $ env WINEPREFIX="$HOME/.local/share/wineprefixes/evernote" winecfg

    Wine-Initializing-PREFIX
    图1:wine容器正在初始化
  3. 调整wine设定

Installation

  1. 开始安装到指定容器
    $ env WINEPREFIX="$HOME/.local/share/wineprefixes/evernote" wine Evernote-Install.exe

    就像在Windows里那样,一路下一步
    图4:就像在Windows里那样,一路下一步

    重要!不要更变默认安装配置,不然会给后期的更新和查错带来麻烦!

  2. 安装gnutls库
    重要!没有这个东西Evernote根本不能访问笔记存储服务器!
    # pacman -S lib32-gnutls
  3. winetricks中安装msxml3 msxml5 msxml6
    $ winetricks

    在winetricks中选择Evernote所在的容器
    图5:在winetricks中选择Evernote所在的容器
    选择安装DLL组件
    图6:选择安装DLL组件
    安装msxml3 msxml4 msxml5,它们是印象笔记正常读取笔记需要的支持文件
    图7:安装msxml3 msxml4 msxml5,它们是印象笔记正常读取笔记需要的支持文件,按照提示操作,完成后会回到图6
  4. winetricks中安装富文本控件
    winetricks中的富文本控件,需要他们来正确显示笔记格式
    图8:winetricks中的富文本控件,需要他们来正确显示笔记格式
  5. winetricks中的中文字体配置
    配置字体,以防中文字符全是豆腐
    图9:图6中的界面选择第二项配置字体,以防中文字符全是豆腐,如果不需要日文和韩文字符,后两个可以不选

Done! Happy taking notes!

安装及配置完成!
图10:安装及配置完成!
Evernote的托盘图标和windows上的体验差不多
图11:Evernote的托盘图标和windows上的体验差不多
Evernote已经正常运作,现在正在同步我在云端的笔记
图12:Evernote已经正常运作,现在正在同步我在云端的笔记

Post-installation tweaks

开机启动

虽然wine能够处理大多数让windows程序跑起来的工作,但是wine仍然是一个容器,不足以上升到系统层面,因此你并不能强求印象笔记在你登陆时自行启动。
The Linux Way:使用Gnome高级设置gnome-tweak-tool,使用pacman -S gnome-tweak-tool以安装,在自启菜单中找到Evernote的启动器并添加相应启动项。

 更新

就和安装一个新的一样,重复准备步骤1和安装步骤1即可,Winetricks无需再次配置。

Known Caveats

Evernote-in-wine-bugs

1:笔记本分类错误,在试图更改已经存在的笔记的所属笔记本时会发生错误并且崩溃。
解决方案:not yet

2:图片不能自动缩放到适合大小。
解决方案:错误信息提示需要libjpeg.so.8,即使已经安装64位的libjpeg-turbo,32位的Evernote并不能正确加载,安装lib32-libjpeg-turbo以解决问题

[Update Aug 10, 2015]

疑似无法启动的可以尝试安装AUR里的log4cplus