u-ryo's blog

various information for coding...

Hybrid MBR/GPT for Dual Booting MBR/UEFI

| Comments

BIOSブートとUEFIブートの両対応を求められました。

UEFIブートなので、GPT(GUID Partition Table)は必須です。 が、GPTだと旧来のMBRではないので、BIOSブートがこけます。 そこで、Hybridなるものがありますと。 これは、gdiskでしか作れません。 rで「recovery and transformation options (experts only)」に入って、 h(make hybrid MBR)で作ります。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
$ sudo gdisk /dev/sdb

GPT fdisk (gdisk) version 0.8.8

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

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdb: 7831552 sectors, 3.7 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3BF2DA63-FB2F-4616-ACE6-694968477678
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 7831518
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
    1            2048         5734399   2.7 GiB     0700
    2         5734400         7829503   1023.0 MiB  EF00

Command (? for help): r

Recovery/transformation command (? for help): p
Disk /dev/sdb: 7831552 sectors, 3.7 GiB
Logical sector size: 512 bytes
    1            2048         5734399   2.7 GiB     0700
    2         5734400         7829503   1023.0 MiB  EF00

Recovery/transformation command (? for help): o

Disk size is 7831552 sectors (3.7 GiB)
MBR disk identifier: 0x00000000
MBR partitions:

Number  Boot  Start Sector   End Sector   Status      Code
    1                     1      7831551   primary     0xEE

Recovery/transformation command (? for help): h

WARNING! Hybrid MBRs are flaky and dangerous! If you decide not to use one,
just hit the Enter key at the below prompt and your MBR partition table will
be untouched.

Type from one to three GPT partition numbers, separated by spaces, to be
Place EFI GPT (0xEE) partition first in MBR (good for GRUB)? (Y/N): n

Creating entry for GPT partition #1 (MBR partition #1)
Enter an MBR hex code (default 07):
Set the bootable flag? (Y/N): n

Creating entry for GPT partition #2 (MBR partition #2)
Enter an MBR hex code (default EF):
Set the bootable flag? (Y/N): y

Unused partition space(s) found. Use one to protect more partitions? (Y/N): y
Note: Default is 0xEE, but this may confuse Mac OS X.
Enter an MBR hex code (default EE):

Recovery/transformation command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.

Caution: More than one 0xEE MBR partition found. This can cause problems
in some OSes.
The operation has completed successfully.

$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.8

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

Found valid GPT with hybrid MBR; using GPT.

Command (? for help): q

その上で、grub-installします。 MBR用には、

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo mount /dev/sdb2 /mnt
sudo grub-install --force --no-floppy --boot-directory=/mnt/boot /dev/sdb
sudo vi /mnt/boot/grub/grub.cfg

set timeout=3
set default=0

menuentry "Run Ubuntu Live ISO" {
       set gfxpayload=keep
       loopback loop (hd0,gpt2)/airscope2.iso
       linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/airscope2.iso splash --- debian-installer/language=ja keyboard-configuration/layoutcode?=jp keyboard-configuration/modelcode?=jp109
       initrd (loop)/casper/initrd.lz
}

UEFI用には、

1
2
3
4
5
6
7
sudo mount /dev/sdb2 /mnt
sudo mkdir -p /mnt/EFI/BOOT/
grub-mkimage -d /usr/lib/grub/x86_64-efi -o /mnt/EFI/BOOT/BOOTx64.EFI -O x86_64-efi -p "" part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux multiboot efi_gop
sudo cp -rp /usr/lib/grub/x86_64-efi /mnt/EFI/BOOT/
sudo vi /mnt/EFI/BOOT/grub.cfg

configfile (hd0,GPT2)/boot/grub/grub.cfg

Secure Boot

| Comments

Linux (ubuntu)でSecure Bootを求められました。 ubuntuには、Linux-signed-imageとかgrub-efi-amd64-signedとかっていう パッケージがあるので、何か出来そうなんですけど、 じゃ具体的にどうやるの? というのは意外と書いてないので、苦労してます。

取り敢えず、grub-installで「--secure-boot」というオプションがあるので、

1
$ sudo grub-install --force --no-floppy --efi-directory=/mnt/ --target=x86_64-efi --uefi-secure-boot /dev/sdb

とすると、USBメモリには、/mnt/EFI/ubuntu/ の下にsignedなgrubx64.efiやshimx64.efiが入るんですが、 /EFI/ubuntu/... ではブート時に読み込まないので、 /EFI/BOOT/ にリネームし、 また、/EFI/BOOT/grubx64.efi(又はshimx64.efi) を/EFI/BOOT/BOOTX64.efi にリネームし、 /boot/grub/grub.cfg を、

1
2
3
4
5
6
7
8
9
set timeout=3
set default=0

menuentry "Run Ubuntu Live ISO" {
       set gfxpayload=keep
       loopback loop (hd0,gpt1)/airscope3.iso
       linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/airscope3.iso splash --- debian-installer/language=ja keyboard-configuration/layoutcode?=jp keyboard-configuration/modelcode?=jp109
       initrd (loop)/casper/initrd.lz
}

とすると、grubまでは立ち上がりました。 更にブートするには、loopbackモジュールが必要になり、 それはunsignedなので、そこで引っ掛かりますが、 仕組み上、signed grubでモジュールは使えない(使えてしまうとillegalなモジュールが入り込めてしまう)ので、

  1. loopbackモジュールを使わない
  2. loopbackモジュールを含めたgrubを自力で署名する

前者はUSBメモリをHDとして直接インストールすれば良さそうですが、 8GB以上の容量が必要になります。 現状手元にそんな容量のUSBメモリがありません。 後者は、かなり面倒そうです。Micro$osftに署名してもらうにはお金かかりそうですし、 自分で署名してそのキーをMOK?を使って云々という手法は、 まだ読み込んでません...

Parameters for FreeRDP

| Comments

某所にFreeRDPのbootable USBを作って納入したのですが、 「壁紙を変えたい」と言われました。 デフォルト「wallpaperはon」と書いてありますけれども、 明示的に「+wallpaper」としないと、効かないようです。

また、「画面が時々ちらつく」と言われました。 どうやら、頻繁にreconnectが生じているための様子。 パケットキャプチャすると、 2秒おきにTCP Keepaliveを出していて、その後、 クライアント側からTCP RST ACKを出しているようです。 なぜ? ともあれ、「+heartbeat」を指定すると、 頻繁なreconnectはおさまりました。 「-heartbeat」でも効果あったんですが、なぜ?

Too Many Open Files

| Comments

tomcat7が止まっていて、catalina.outを見ると、 Too many open filesと言われていました。

  • 現状の確認 $ ulimit -a
  • プロセス毎なので、$ cat /proc/プロセス番号/limits or $ cat /proc/`pgrep -f tomcat7`/limits
  • 現状幾つのfilesをopenしているか、は、$ sudo ls -l /proc/`pgrep -f tomcat7`/fd/|wc -l
  • 増やすには、/etc/init.d/tomcat7 でulimit -n 8192等と追記してrestart
  • $ cat /proc/プロセス番号/limitsで確認

Limitation of Koding

| Comments

Kodingにも限界はあるんですね。 無料ではVMが常時起動ではない、 というのはendurableなんですが、 workplaceが一つしか作れないとは。 cordovaでハイブリッドアプリ作ってみたかったんですけど、 続きはCloud9で頑張ってみます。