前回のエントリでかなり雑にやっていたけど、その部分をそのままにしておくとかなり毎回めんどくさい点をもう少し追記します。
毎回modprobe
をしないために
再起動などをするとカーネルモジュールがロードされずデバイスの認識が外れた状態で起動するので、起動時に自動的にモジュールがロードされるようにします。
/etc/local
にmodprobeの設定を追加します。以下のようにファイルを開き
~ $ sudo vi /etc/rc.local
下記を
/sbin/modprobe usbserial vendor=0x2019 product=0xab27
追加します。
↓オリジナル
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi exit 0
↓修正後(追記後)
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi #ここに追加 /sbin/modprobe usbserial vendor=0x2019 product=0xab27 exit 0
これで再起動すると自動的にカーネルモジュールがロードされ、/dev/ttyUSB?デバイスも生成されます。
生成された/dev/ttyUSB
を一般ユーザから使用する。
前回のエントリではめんどくさかったのでデバイス側のグループをsudo chgrp root /dev/ttyUSB0
でrootに変更していました。
しかし、この方法ではmodprobeによってデバイスが生成された後にしか設定ができません。つまり毎回設定する必要があります。
モデム認識後に/dev/ttyUSB?はdialoutグループのパーミッションなるので逆にこのデバイスを使用するユーザーをdialoutに所属させることにします。
~ $ sudo addgroup pi dialout
piとなっている部分が所属させるユーザ名になります。設定が終わったら以下のコマンドでユーザの所属しているグループを確認します。
~ $ id uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),101(input),108(netdev),997(gpio),998(i2c),999(spi)
以上の設定で起動してすぐにモデムが使用できる状態になります。