Let's Note SZ6にFreeBSDをインストールする

Let's Note SZ6に入っているWindows 10 64bitの領域を縮小し、空き領域にFreeBSD 12を入れてデュアルブートするのが目的。

Windowsでの作業

Windowsアップデートとかしたくなるが、それはデュアルブートが成功してからにする。徒労に終る可能性がある。

リカバリーディスク

リカバリーディスク作成ユーティリティ」でリカバリーディスクを必ず作っておく。

高速スタートアップ解除

高速スタートアップを無効にする。コントロールパネル→電源オプション→電源ボタンの動作選択→高速スタートアップを有効にするのチェックを外す。「現在利用可能ではない設定を変更します」をクリックしないと外せない。
参考: http://www.eightforums.com/tutorials/6320-fast-startup-turn-off-windows-8-a.html

ecoモードにする

ecoモード(80%までしか充電しない; 電池の寿命が延びる)にする。

ディスクを縮小する

ディスクを縮小する。左下のWindowsアイコンのところで右クリック、「ディスクの管理」を選択。縮小する領域のサイズ(MB)を適当に選ぶ。思ったよりサイズが小さくできない場合は、いったんシステムの復元を無効化するとよい。

復元の無効化

システムのプロパティ→システムの保護、「保護設定」の「構成」→システム保護対象で「システムの保護を無効にする」を選択

終ったら元に戻しておく。

別のFreeBSDマシンでの作業

いまどきのメモリースティックイメージはUEFI対応なので、何も考えずにメモリースティックイメージを持ってくる。

 # dd if=Downloads/FreeBSD-12...-memstick.img of=/dev/da0 bs=1M conv=sync

などとして書き込み。

Let's Noteでの作業

USBメモリを差した状態で起動し、起動時にF2を押してファームウェア設定画面に入る。
セキュアブートを無効にしておく。デバイス指定でUSBメモリスティックを選択する。

するとインストーラが立ち上がるのでインストールを進める。パーティションを切るところで、ada0に

 freebsd-ufs 10GB /
 freebsd-ufs 52GB /usr
 freebsd-zfs 690GB (数字は適当)

を作成。終了前にshellが開けるので、そこで適当なUSBメモリに/boot/boot1.efiをコピーしておく。終ったらリブートする。Windowsが立ち上がる。

コマンドプロンプトを右クリックして管理者として実行する。

 > bcdedit.exe /copy {bootmgr} /d "FreeBSD"

得られたUUIDをコピーしておく。
EFIパーティションをマウント。

 > mountvol.exe f: /S

中を見てディレクトリ作成。

 > dir f:\
 > mkdir f:\EFI\FreeBSD

USBメモリを差す(ドライブレターD:とする)

 > copy d:\boot1.efi f:\EFI\FreeBSD\
 > bcdedit /set {得られたUUID} path \EFI\FreeBSD\boot1.efi
 > bcdedit /set {fwbootmgr} displayorder {得られたUUID} /addfirst

これでRebootするとFreeBSDが起動する。ファームウェア設定画面から直接Windows Boot Managerを選択したら、Windowsが起動する。

Windowsでの設定
FreeBSDでの設定

/etc/fstabに

 md /usr/obj mfs rw,async,-M,-s4g,noatime,late 0 0
 #md /usr/obj mfs rw,async,-M,-s10g,noatime,late 0 0

を追加。下側はmake buildworld時用。umount /usr/objをしたら、mdconfig -d -u 0を忘れないこと。

 # mount /usr/obj

/etc/groupのoperatorグループに自分のユーザ名を追加。

freebsd-zfsな領域を確認。

 # gpart show

ada0のカラムの番号9がfreebsd-zfsなので、ada0p9がdeviceであると分かる。

tankというプールを作成。

 # zpool create tank /dev/ada0p9

いくつかファイルシステム作成。

 # zfs create tank/home
 # zfs create tank/data
 # zfs create tank/ports
 # zfs create tank/ports-distfiles

ホームディレクトリ移動

 # mv /home/* /tank/home/
 # zfs set mountpoint=/home tank/home

プロパティ設定

 # zfs set atime=off tank

portsディレクトリ関係マウントポイント設定

 # zfs set mountpoint=/usr/ports tank/ports 
 # mkdir /usr/ports/distfiles
 # zfs set mountpoint=/usr/ports/distfiles tank/ports-distfiles

portsディレクトリを一応取得。

 # portsnap fetch
 # portsnap extract

主にインストールしたもの。pkg install hogeでインストールできる。

  • sudo
  • zsh
  • lv
  • xfce
  • xlockmore
  • firefox
  • xorg
  • emacs25
  • ja-fcitx-mozc
  • ja-mozc-el-emacs25
  • ja-mozc-server
  • ja-mozc-tool
  • unzip
  • rubygem-netcdf
  • rubygem-ruby-dcl
  • netcdf-fortran
  • a2ps
  • ja-a2ps
  • w3m
  • cdrtools
  • evince
  • ffmpeg
  • mplayer
  • gifsicle
  • gnupg
  • gnuplot
  • gv
  • inconsolata-ttf
  • ja-cannadic
  • ja-less
  • ja-nkf
  • lapack
  • lapack95
  • linux_base-c6
  • papersize-default-a4
  • psutils
  • rsync
  • git
  • ruby-rd-mode.el
  • rubygem-narray_miss
  • rubygem-numru-misc
  • rubygem-numru-units
  • sharutils
  • wget
  • xfce4-mixer
  • xfce4-netload-plugin
  • xfce4-print
  • xfce4-systemload-plugin
  • xfce4-wm-themes
  • gimp
  • asymptote
  • bind-tools
  • dvd+rw-tools
  • gmake
  • icons-tango
  • icons-tango-extras
  • ja-font-ipa
  • ja-font-ipa-uigothic
  • ja-font-ipaex
  • ja-font-migu
  • ja-font-mplus-ipa
  • ja-font-std
  • ja-font-vlgothic
  • rubygem-rdtool
  • smartmontools
  • xfce4-battery-plugin
  • xfce4-genmon-plugin
  • xf86-input-synaptics
  • xf86driproto
  • resourceproto

chshしてzshをログインシェルにしておく。

/usr/srcのチェックアウト。

 # cd /usr
 # rmdir src
 # svnlite co svn://svn0.us-west.FreeBSD.org/base/head /usr/src

/boot/loader.confを以下の内容で作成。

 sem_load="YES"
 coretemp_load="YES"

 # for bluetooth
 #ng_ubt_load="YES"

/etc/ttysの調整(ttyv5-v8までコメント)。

/etc/sysctl.confの内容を以下に設定。

 #hw.acpi.reset_video=1
 #hw.acpi.sleep_button_state=S3
 #hw.acpi.power_button_state=S3
 #hw.acpi.lid_switch_state=S3
 #hw.acpi.standby_state=S3
 debug.cpufreq.lowest=600
 hw.acpi.verbose=1

設定ファイルのコピーなど。

 /etc/wpa_supplicant.conf
 /etc/rc.conf
 /etc/X11/xorg.conf
 /etc/hosts
 /etc/make.conf
 /etc/mergemaster.rc
 /etc/periodic.conf
 /etc/portsnap.conf
 /etc/printcap
 /etc/rc.conf
 /etc/rc.local
 /etc/sysctl.conf

CPU負荷が低いときにCPU周波数を落すように設定できる. これはcpufreq(4)とpowerd(8)によって行われる. cpufreqデバイス入りカーネル(例えばGENERIC)を用意するか, cpufreq.koをロードして, /etc/rc.confに

 powerd_enable="YES"

と書いておく. /etc/rc.d/powerd startなどとすれば起動.

稼働するCPU周波数の最低値を指定するには, MHz単位でsysctl(8)によって

 debug.cpufreq.lowest=600

などと設定する. この場合は負荷が低いときには600MHzで駆動する(see cpufreq(4)).

デフォルトでは, 温度が閾値より高くなった場合にCPU周波数を落すことで冷却を試みる(passive cooling). その閾値を例えば摂氏75.0に設定したいときはsysctl(8)で

 hw.acpi.thermal.user_override=1
 hw.acpi.thermal.tz0._PSV=75.0C

と設定しておく. hw.acpi.thermal.user_overrideを1に設定しないと, 二行目の変数の値を初期値から変更できない. 詳しくはacpi_thermal(4)を参照.

X.org

pkgからxf86-video-scfbをインストールして、/etc/X11/xorg.confのDriverのところを"scfb"にする。

無線LAN

Intel Dual Band Wireless-AC 8265が搭載されている。

カーネルモジュールの読み込み設定など

if_iwmで動く。ただし、/boot/loader.confに書いてもうまくwlan0が生えない。
/etc/rc.confに

kld_list="if_iwm"

と書いておくとよい。

LinuxでIDLをコマンドラインから動かす

idlがインストールされているディレクトリにidl_setup.bashというのがあるので、bashを使っている場合はそれを読み込む。zshの人はそれを読み込んでもおそらく動くが、気持ち悪ければ適当にコピーする。


今回はライブラリとしてGitHub - wlandsman/IDLAstro: Astronomy related procedures in the commercial IDL languageCoyote IDL Program Librariesをインストールしておく。それぞれ${HOME}/local/idl 以下に置く。

test.shを以下のように用意する。

#!/bin/sh

LM_LICENSE_FILE=port@host
export LM_LICENSE_FILE

IDL_PATH=/usr/local/exelis/idl/lib:${HOME}/local/idl/IDLAstro/pro:${HOME}/local/idl/coyote
export IDL_PATH

idl -quiet test_compile.pro
idl -quiet -e "restore, 'test.sav' & test"

test_compile.proは以下のように用意する。

.compile test_lib.pro
.compile test.pro

save,/ROUTINES,'test','test_lib',FILENAME='test.sav'

exit

test_lib.proは

pro test_lib,xxx,...,zzz

...

return
end

みたいなやつである。

test.proは以下のような感じである。

pro test

...

test_lib,xxx,...,zzz

...

end

なお、IDLメモ 基本操作を大いに参考にした。特に、「IDLで実行可能なプログラムの種類」についての情報が役立った。

gitを使ったマージのメモ

gitで個人的に管理しているファイルを、他の人があるタイミングで持っていって、その編集結果をマージする、という作業をしたので、覚書としてメモ。

git log でマージ元を特定

$ git log

0e23211f702f84a5ecd7c0aa765760a21043f020 だった。

$ git checkout 0e23211f702f84a5ecd7c0aa765760a21043f020
$ git branch feature-foo 
$ git co feature-foo
$ mv ~/newfile file
$ git add file
$ git commit
$ git co master 

git logでfeature-fooのcommitを特定

$ git log feature-foo

f2c5783be1357e7fb3295304c91e391f42404042 だった。

$ git merge f2c5783be1357e7fb3295304c91e391f42404042


ブランチの削除

$ git branch -d feature-foo

push

$ git push

DocuPrint C5000 dをFreeBSDで使う(CUPS編)

DocuPrint C5000 dをFreeBSDで、CUPS経由で使うことを試みました。

https://www.fujixerox.co.jp/download/docuprint/c5000d/linux/
からrpmファイルを落して来る。
適当なディレクトリを作ってその中で伸長。

etc/cups/mimefx.convs
etc/cups/mimefx.types
それぞれを /usr/local/etc/cups/mime.{convs,types} に追記(コメントアウトされてるところは追記しなくてよいです)。

Linuxバイナリ usr/lib/cups/filter/{pdftopdffx,pdftopjlfx,pstopdffx} を動かせるように、適当にLinuxパッケージをインストール。

linux-c6-avahi-libs-0.6.25_2
linux-c6-cups-libs-1.4.2_4
linux-c6-dbus-libs-1.2.24_4
linux-c6-expat-2.0.1_2
linux-c6-fontconfig-2.8.0_1
linux-c6-gnutls-2.8.5_2
linux-c6-libgcrypt-1.4.5_3
linux-c6-libgpg-error-1.7_1
linux-c6-libtasn1-2.3_2
linux-c6-libxml2-2.7.6_5
linux-c6-nspr-4.10.8_2
linux-c6-nss-3.19.1
linux-c6-sqlite-3.6.20_3
linux-c6-xorg-libs-7.4_4
linux-libgtkembedmoz-0.0.20100806
linux_base-c6-6.7_1
linuxlibertine-g-20120116_1

このへんが入っていれば動いた(関係ないのも含まれる)。

Linuxバイナリは/compat/linux/usr/local/libexec/cups/filter/以下に配置して、/usr/local/libexec/cups/filter以下へシンボリックリンクをはる。

/usr/local/etc/cups/ppd/ 以下を一時的にでいいので、自分の権限にしておく。

ブラウザで http://localhost:631/ へアクセスし管理→プリンターの追加
URLはhttp://プリンタのIP/ipp/を指定。
PPDファイルはusr/share/cups/model/FujiXerox/fxlinuxprint.ppdを指定。

ウェブからぽちぽちとデフォルトプリンタに設定したりしておく。

$ lpr-cups test.ps
$ lpr-cups test.pdf

などとすると印刷できるので確認する。

IRubyをFreeBSDにインストール(まとめ)

  • pyzmq portsがあるが、libzmq4に依存している。libzmq4でipythonは動かないようなので、libzmq3に依存するように書き換えてインストールする。
  • ffi-rzmqを使う(そうしないでもうまくいく方法があるかもしれないが、、、、)


1. ports treeをアップデートしておく。
2. ports/net/py-pyzmq/MakefileのLIBDEPENDSの行

LIB_DEPENDS=    libzmq.so:${PORTSDIR}/net/libzmq4

LIB_DEPENDS=    libzmq.so:${PORTSDIR}/net/libzmq3

に書き換え

3. パッケージのインストール

$ sudo pkg install libzmq3 rubygem-mimemagic py27-qt4-gui py27-pexpect-3.3 py27-qt4-svg py27-pygments py27-Jinja2 py27-tornado py27-jsonschema

4. gemのインストール(ffi, ffi-rzmq-core, ffi-rzmqがインストールされる)

$ sudo gem install ffi-rzmq  

5. portsを使ってmake installする

$ cd /usr/ports/net/py-pyzmq
$ sudo make install
$ cd /usr/ports/devel/ipython
$ sudo make install

6. irubyのインストール

$ git clone https://github.com/domitry/iruby.git
$ cd iruby
$ git checkout compatibility_with_ffi_rzmq
$ gem build iruby.gemspec
$ sudo gem install iruby-0.2.7.gem

7. irubyの実行

$ iruby notebook

IRubyをインストールする(3)

どみとりさんに、 https://t.co/RkXFKqIDsQ を使えばうまくいくとおもうと教えてもらったので、インストールしてみた。過程を全部記録してないのだけど、最終的に以下のようなWarningが出る状態になった。下記は、ブラウザのウィンドウが新しくできるので、そこでファイルを選択した状態。gemに詳しくないのでよくわからない。Gemfileって個々のソフトウェアのディレクトリにあるやつかと思ってたが、your Gemfileとは、、、?

$ iruby notebook
Could not load bundler: Could not locate Gemfile or .bundle/ directory
[I 19:41:46.219 NotebookApp] Serving notebooks from local directory: /usr/home/murashin
[I 19:41:46.221 NotebookApp] 0 active kernels 
[I 19:41:46.221 NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[I 19:41:46.221 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

(process:1423): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
[W 19:42:13.826 NotebookApp] Notebook github/nyaplot/examples/notebook/Colors.ipynb is not trusted
[I 19:42:14.784 NotebookApp] Kernel started: 692e4e26-c7fd-4329-ade7-e1d9482b62cc
W, [2015-11-19T19:42:15.286186 #1427]  WARN -- : Could not load bundler: iruby is missing from Gemfile. This might not work.
Add `gem 'iruby'` to your Gemfile to fix it.
/usr/home/murashin/github/iruby/lib/iruby/command.rb:108:in `check_bundler'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:67:in `run_kernel'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:34:in `run'
/usr/home/murashin/github/iruby/bin/iruby:5:in `<main>'
W, [2015-11-19T19:42:15.846542 #1427]  WARN -- : Could not load PryBackend: undefined method `new' for Slop:Module
/usr/local/lib/ruby/gems/2.1/gems/pry-0.10.3/lib/pry/cli.rb:100:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.1/rubygems/core_ext/kernel_require.rb:54:in `require'
/usr/local/lib/ruby/site_ruby/2.1/rubygems/core_ext/kernel_require.rb:54:in `require'
/usr/local/lib/ruby/gems/2.1/gems/pry-0.10.3/lib/pry.rb:150:in `<top (required)>'
/usr/local/lib/ruby/site_ruby/2.1/rubygems/core_ext/kernel_require.rb:128:in `require'
/usr/local/lib/ruby/site_ruby/2.1/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
/usr/local/lib/ruby/site_ruby/2.1/rubygems/core_ext/kernel_require.rb:39:in `require'
/usr/home/murashin/github/iruby/lib/iruby/backend.rb:56:in `initialize'
/usr/home/murashin/github/iruby/lib/iruby/kernel.rb:28:in `new'
/usr/home/murashin/github/iruby/lib/iruby/kernel.rb:28:in `create_backend'
/usr/home/murashin/github/iruby/lib/iruby/kernel.rb:23:in `initialize'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:70:in `new'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:70:in `run_kernel'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:34:in `run'
/usr/home/murashin/github/iruby/bin/iruby:5:in `<main>'
Assertion failed: check () (src/msg.cpp:248)
[I 19:42:17.785 NotebookApp] KernelRestarter: restarting kernel (1/5)

bundlerがどうこういわれているので、いちおう調べてみたが、FreeBSDのpackageとして1.10.6が入っている様子。slopは4.2.0, pryは0.10.3。

(追記)slopが新しいとエラーがでるっぽかったので3.6.0を入れて4.2.0は消した。そしたらエラー内容が変わりました。WARNはWARNなんだから無視していいのかな。となると、Bad address (src/fq.cpp:91)というのがヒントなのかな。

$ iruby notebook    
Could not load bundler: Could not locate Gemfile or .bundle/ directory
[I 00:07:27.849 NotebookApp] Serving notebooks from local directory: /usr/home/murashin
[I 00:07:27.850 NotebookApp] 0 active kernels 
[I 00:07:27.850 NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[I 00:07:27.851 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

(process:2875): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
[I 00:07:36.904 NotebookApp] Creating new notebook in 
[I 00:07:38.011 NotebookApp] Kernel started: 51bc0b68-11c2-42a0-831c-613987334bc5
W, [2015-11-20T00:07:38.310974 #2879]  WARN -- : Could not load bundler: Could not locate Gemfile or .bundle/ directory
/usr/local/lib/ruby/gems/2.1/gems/bundler-1.10.6/lib/bundler.rb:198:in `rescue in root'
/usr/local/lib/ruby/gems/2.1/gems/bundler-1.10.6/lib/bundler.rb:194:in `root'
/usr/local/lib/ruby/gems/2.1/gems/bundler-1.10.6/lib/bundler.rb:106:in `bundle_path'
/usr/local/lib/ruby/gems/2.1/gems/bundler-1.10.6/lib/bundler.rb:425:in `configure_gem_home_and_path'
/usr/local/lib/ruby/gems/2.1/gems/bundler-1.10.6/lib/bundler.rb:92:in `configure'
/usr/local/lib/ruby/gems/2.1/gems/bundler-1.10.6/lib/bundler.rb:153:in `definition'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:109:in `check_bundler'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:67:in `run_kernel'
/usr/home/murashin/github/iruby/lib/iruby/command.rb:34:in `run'
/usr/home/murashin/github/iruby/bin/iruby:5:in `<main>'
Bad address (src/fq.cpp:91)

(追記その2)
どみとりさんに、libzmqのライブラリバージョンが違うのが原因でないか、3を使うとよい、と教えてもらったので、そのようにしたら動きました!

ノートであまりちゃんと記録をとらずにじたばたしたので、こんどはデスクトップマシンでインストール方法をちゃんとメモしてみたいですね。

nmatrixをインストールする

nmatrixをFreeBSDにインストールしようとしてつまづいた。

FreeBSDはclangを使っている、というのが問題である。nmatrixのreadmeによればexperimentalらしい。

まず、extconf.rbでRbConfig::CONFIG['CXX']を参照しているが、これはc++になっているはずで、実態はclang++である。しかし、extconf.rbではCXXがclang++でなければgccであると仮定している。この判定方法は改善の余地がありそうだ。

とりあえず、*まずは*自分さえよければいいので

elsif CONFIG['CXX'] == 'c++'
  $CPP_STANDARD = 'c++11'

と付け加えてしのぐ。

そうすると、なんだかうまくいくような感じにみえるが....

$ make                                    [~/github/nmatrix/ext/nmatrix:master]
compiling nmatrix.cpp
In file included from nmatrix.cpp:44:
In file included from ./data/data.h:45:
./data/ruby_object.h:116:10: error: conversion function cannot be redeclared
  inline operator uint64_t() const { RETURN_OBJ2NUM(NUM2ULONG)      }
         ^
./data/ruby_object.h:113:10: note: previous declaration is here
  inline operator VALUE() const { return rval; }
         ^
In file included from nmatrix.cpp:283:
./ruby_nmatrix.c:1102:11: warning: unused variable 'elem' [-Wunused-variable]
    void* elem = s->elements;
          ^
./ruby_nmatrix.c:2692:38: warning: comparison of unsigned expression >= 0 is
      always true [-Wtautological-compare]
      if (rb_ary_entry(begin_end, 0) >= 0)
          ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
./ruby_nmatrix.c:2696:38: warning: comparison of unsigned expression >= 0 is
      always true [-Wtautological-compare]
      if (rb_ary_entry(begin_end, 1) >= 0)
          ~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~
3 warnings and 1 error generated.
*** Error code 1

Stop.
make: stopped in /usr/home/murashin/github/nmatrix/ext/nmatrix
zsh: exit 1     make

というわけで、エラーが出てコンパイルできない。

C++はよくしらないが、operator uint64_t()で型キャストしたときの振舞を定義、というか、オーバーロードしたというべきか、しているようだ。

もしかして、VALUEっていう型とuint64_tって同じ型なのでは? と思って調べてみた。VALUEがuintptr_tという型なのは分かった。

uintptr_tは__uintptr_tであり、__uint64_tはuint64_tで、__uint64_tは__uintptr_tだ!
あーっ。。。。。

こういうときどうするんでしょうか?

(追記) VALUEの型キャストを定義しているところをコメントアウトしたらコンパイル通りました。なんだよ要らないのかよ!