2014年6月22日日曜日

OpenBSD live USB (USBメモリの上でopenbsd走るよ)

最初にちょっと特殊な openbsdのインストールの話を書きます。
その後 ありきたりにUSBへのインストールに話を戻しますので初めての方はしばらくの辛抱をしてください。

 USBメモリの上の openbsdか puppyかを  openBSDのGRUBで 立ち上げる手法です。
最初にopenbsdをUSBにいれ その後fat32のパーティションをlinuxで作り、そこにpuppyのファイルを起きます。

this is a technique to launch  puppy or openbsd on the USB memory by OpenBSD's GRUB .
first i install openbsd into USB ,and create the partition of  fat32  by linux ,and then put  put the file of puppy there(fat32).

まず 状況ですが USBメモリはopenbsd上では sd1で認識されてます。
USB memory is recognized by sd1 on openbsd .


# fdisk sd1
Disk: sd1       geometry: 3840/255/63 [61702144 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 0C    652 213  10 -   3840 199   7 [    10487808:    51214336 ]  
 1: 00      0   0   0 -      0   0   0 [           0:           0 ] unused    
 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused    
*3: A6      0  32  33 -    652 213   9 [        2048:    10485760 ] OpenBSD

 で Win95 FAT32L  にpuppyのファイルをおいてます。
I have put the file of puppy in Win95 FAT32L.
  

USBから立ち上げたOpenBSDに
pkg_add grub で grubをいれます。
openbsdにもgrubがなんとあるのです。

In OpenBSD that was launched from the USB    I install  grub by  pkg_add grub. there is grub also openbsd.

そして
  cat /grub/menu.lst  
 default 0
 timeout 10

 title OpenBSD in USB
 root (hd0,3)
 chainloader +1

 title Puppy571 in USB
 root (hd0,0)
 kernel /p571/vmlinuz
 initrd /p571/initrd.gz
 boot

 title slacko in USB
 root (hd0,0)
 kernel /slc/vmlinuz
 initrd /slc/initrd.gz
 boot


と hd0 に気をつけてください。

そして 
grub-instal  /dev/sd1c
をして 完成です。

つまり USBは  openbsdでは sd1 ですが、
         (HDDは sd0 ) 
grub ローダーが USBの sd1に入ってる成でしょうか、

grub では hd0に入れ替わってますねえ~



ただし、openbsdをいれてから あとでFATのpartitionを追加したので

# dsiklabel sd1 では FATが見えません!

# disklabel sd1                                                               
# /dev/rsd1c:
type: SCSI
disk: SCSI disk
label: Transcend 32GB 
duid: 82ec76de45b5ee83
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 255
sectors/cylinder: 16065
cylinders: 3840
total sectors: 61702144
boundstart: 2048
boundend: 10487808
drivedata: 0

16 partitions:
#                size           offset  fstype [fsize bsize  cpg]
  a:          9985760           502048  4.2BSD   2048 16384    1 # /
  b:           500000             2048    swap                   # none
  c:         61702144                0  unused                  




NEXT is nomal  openbsd insttall on USB memory .  this is easy .
ここから 普通のUSBメモリーへのopenbsdの話になります。



openbsdを USBメモリにインストールしてdhcpd と firewall(未確認)とを動かす

あとで知ったのだが、
http://www.openbsd.org/faq/faq14.html#flashmemLive
にすでに書かれていた。
It is very easy to create a bootable USB flash (or other!) drive that can be used as a "live" OpenBSD system without installing OpenBSD on the local hard disk of a machine.
とね。
またここにあるのだが、 別にPCのBIOSが USBメモリをしてなくっても大丈夫
自分の場合はHDDに仕込んだdebianのgrubを使って 
OpenBSDを usd HDD 起動させている・



eeBSD8.0 とか linux系であれば ご存知のunetbootin-linux-608.binでlive USBがつくれますが、 openbsdは これでは無理でした。



まず パソコンのCDドライブに openbsd5.5のCD(cd55.isoでつくったもの)をいれ  かつUSB メモリも差し込み パソコンの電源をいれます。そして普通にUSBに インストールをするのですが、インストール先はsd2です。これをsd1にしてしまうと パソコンのハードディスクは 消されてしまうのでくれぐれも注意をしてください。

そうするとUSBメモリスチックから openbsdが 立ち上がります。
動くと感動です。
I insert  both  'openbsd5.5 CD(made with cd55.iso)'  and USB memory  stck , and then  ' well known install process' begin from CD.q
OpenBSD install place is sd2  namely USB .
if this is set to sd1 ,  hard disk of a personal computer  will be completely erased .
Be careful.
Openbsd rises From only USB memory stick .
Good!  Good!  Good!
全体的な状況は  The general situation is next picture .

internet
|
|wireless
|
internet address
wimax (uroad-aero) dhcpd & DNS
192.168.100.254
|
|wireless
|
rum0(wifi USB) wimax published192,168.100.X
openbsd5.5 PC firewall &dhpcd
bge0(wired LAN) fixed address192.168.11.1
|
|LAN cable
|
eth0(wired LAN)openbsd published192,168.11.X
mint linux PC

です。


openbsd5.5で 
dhcpdを動かし mint linuxにアドレスを割り当て
さらに 
openbsd5.5でパケットフィルターpfでファイアウォールを動かし
mint linuxがinternetへ出れるようにします。


By openbsd5.5 , I wont to work dhcpd, so  assign an address to mint linux .
Furthermore I   wont to work packet filter pf in openbsd5.5 , then mint linux can go to internet.

なぜこうしたのかというと、 有線LAN環境を持ってないと
無線LANだけではOS導入の際に苦しいことがおおくなります。
インストール時は無線ドライバーははいってないですよね。

When I was asked  the reason  , I do not have wired internet  LAN environment.
Many OS instllation is  hard  in case of  wireless LAN only .
For example ubuntu linu  ,  wifi   driver is not ready  at the time of the installation.


まず openbsdを USB メモリ からたちあげます。

First of all,  insert USB memory then  openbsd come comes up ant usual openbsd system work .  

openbsdをDHCPDサーバーとしてはたらかす
openbsd as DHCPD

wirelessでつなぐために
To tie openbsd and internet  with wireless  namely wifi ,
I look at http://tobysoft.net/wiki/index.php?OpenBSD%2FDHCP%B4%D8%CF%A2%A4%CE%C0%DF%C4%EA

cat /etc/hostname.rum0
ーーーーーーーーーーー
dhcp nwid URoad-662EA0 wpakey 0460001



 手動で動かしたいときは
 wifi.bat として
              ifconfig rum0 down
              ifconfig rum0 nwid "URoad-662EA0" wpakey "04600071" up
              dhclient rum0


これ以降は 実はmintからopenbsdに sshで入ってから作業します。
コピー&ペーストが使えて楽です。
  
ssh -l hatahata 192.168.100.X
(mintも wifiが入ってるので uroadaeroが mintに 勝手にアドレスを割り当てます。 それがこの192.168.100.Xアドレスです)
で openbsdに mintから入ってます。
Since this time I enters openbsd from mint  with ssh.
Copy & paste can be used and it .
ssh -l hatahata 192.168.100.X
(Because uroadaero allocates the address  for mint.  This is 192.168.100.X address. )
I enters  openbsd from mint by ssh , and  by the right of root I rewrite many file .


1)pkg_addをするために
/root/.profile の最後に
export PKG_PATH=http://ftp.jaist.ac.jp/pub/OpenBSD/5.5/packages/i386/
をつける
add this line to /root/.profile , so pkg_add can be done .


2)dhcpdは有線のbge0で動かすので
cat /etc/hostname.bge0  
----------------------------------
inet 192.168.11.1 255.255.255.0 NONE
 と固定アドレスをあて



3)cat /etc/dhcpd.interfaces
---------------------------------                                                
bge0


4)cat /etc/dhcpd.conf                                                        
---------------------------------------------------------------

option  domain-name-servers 192.168.100.254  ;
subnet 192.168.11.0 netmask 255.255.255.0 {
        option routers 192.168.11.1;
        range 192.168.11.10 192.168.11.11;

}

192.168.100.254はwifiルーターのアドレス



  5)http://www.openbsd.org/faq/faq6.html#DHCPserver をみて
 echo 'dhcpd_flags=""' >>/etc/rc.conf.local

すると openbsd で
# ps -ax | grep dhcp
 21743 ??  Is      0:00.00 /usr/sbin/dhcpd
10115 p0  S+      0:00.00 grep dhcp
 とうごいてる。

  そしてたしかに dhcpクライアント(mint)も
  ifconfig -a
eth0      Link encap:イーサネット  ハードウェアアドレス 00:23:8b:82:4f:19
          inetアドレス:192.168.11.10  ブロードキャスト:192.168.11.255  マスク:255.255.255.0
          inet6アドレス: fe80::223:8bff:fe82:4f19/64 範囲:リンク
          UP BROADCAST RUNNING MULTICAST  MTU:1500  メトリック:1
          RXパケット:274 エラー:0 損失:0 オーバラン:0 フレーム:0
          TXパケット:596 エラー:0 損失:0 オーバラン:0 キャリア:0
          衝突(Collisions):0 TXキュー長:1000
          RXバイト:36817 (36.8 KB)  TXバイト:68328 (68.3 KB)
          割り込み:16
とアドレスをopenbsdからもらってる。



6) つぎは PF パケットフィルターです。

それにはまず

# vi /etc/sysctl.conf
...
net.inet.ip.forwarding=1


http://www.openbsd.org/faq/pf/example1.html#allrules の egrepに惑わされましたが、 openBSD misc mailing list からの たくさんの助言でできました。



cat /etc/pf.conf
# macros
int_if="bge0"
ext_if="rum0"

tcp_services="{ 22, 113 }"
icmp_types="echoreq"

# options
set block-policy return
set loginterface egress
set skip on lo

# FTP Proxy rules
anchor "ftp-proxy/*"
pass in quick on $int_if inet proto tcp to any port ftp divert-to 127.0.0.1 port 8021

# match rules
match out on $ext_if inet from !($ext_if:network) to any nat-to ($ext_if:0)
#()にてアドレスになる。  


 # filter rules
block in log
pass out quick

antispoof quick for { lo $int_if }

pass in on egress inet proto tcp from any to (egress) \
    port $tcp_services
pass in inet proto icmp all icmp-type $icmp_types
pass in on $int_if


pfctl -ss
all tcp 192.168.11.1:22 <- 192.168.11.10:34071       ESTABLISHED:ESTABLISHED
all udp 192.168.11.255:631 <- 192.168.11.10:631       NO_TRAFFIC:SINGLE



pfctl -sr
anchor "ftp-proxy/*" all
pass in quick on bge0 inet proto tcp from any to any port = 21 flags
S/SA divert-to 127.0.0.1 port 8021
match out on rum0 inet from ! (rum0:network) to any nat-to (rum0:0)
block return in log all
pass out quick all flags S/SA
block drop in quick on ! lo inet6 from ::1 to any
block drop in quick on ! lo inet from 127.0.0.0/8 to any
block drop in quick inet from 127.0.0.1 to any
block drop in quick on ! bge0 inet from 192.168.11.0/24 to any
block drop in quick inet from 192.168.11.1 to any
block drop in quick inet6 from ::1 to any
block drop in quick on lo0 inet6 from fe80::1 to any
block drop in quick on bge0 inet6 from fe80::21e:c9ff:fe05:78fc to any
pass in on egress inet proto tcp from any to (egress) port = 22 flags S/SA
pass in on egress inet proto tcp from any to (egress) port = 113 flags S/SA
pass in inet proto icmp all icmp-type echoreq
pass in on bge0 all flags S/SA




puppy linux (dhcp client)
-------------------------------------------
fconfig -a
eth0      Link encap:Ethernet  HWaddr 00:00:39:E3:38:99
          inet addr:192.168.11.10  Bcast:192.168.11.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1711 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1990 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1103913 (1.0 MiB)  TX bytes:313349 (306.0 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


cat /etc/resolv.conf
# Generated by dhcpcd for interface eth0
nameserver 192.168.100.254


ping www.openbsd.org
PING www.openbsd.org (129.128.5.194): 56 data bytes
64 bytes from 129.128.5.194: seq=0 ttl=227 time=311.753 ms
64 bytes from 129.128.5.194: seq=1 ttl=227 time=312.358 ms
^C
--- www.openbsd.org ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 311.753/312.055/312.358 ms



route -e
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.11.0    *               255.255.255.0   U         0 0          0 eth0
169.254.0.0     *               255.255.0.0     U         0 0          0 eth0
127.0.0.0       *               255.0.0.0       U         0 0          0 lo
default         192.168.11.1    0.0.0.0         UG        0 0          0 eth0



それにしても ローカルネットワークからデフォルトルートとして指定されているインタフェースであるegressインタフェースを通るところでNATを行う と書かれているので 信じてしまいました。 これが失敗の原因。 


1)pfctl -f  /etc/pf.conf
をしてルールをロードします。
これで pfctl -sr をすると 以下が出力されます。  
pfctl -s  state (pfctl -ss) もnatを見るにはいい。

         
2)vi で行番号を表示は
 :set nu


結局USBメモリに firefox , anthyをいれました。
http://openbsd-akita.blogspot.jp/2014/06/openbsd-dhcpdpffirewall.html
を見てください。
これでも
$ df
Filesystem  512-blocks      Used     Avail Capacity  Mounted on
/dev/sd1a      2057756     87964   1866908        4%    /
/dev/sd1k     26039612    166256  24571376     1%    /home
/dev/sd1d      4074524        20   3870780           0%    /tmp
/dev/sd1f      4122108    690312   3225692      18%    /usr
/dev/sd1g      2057756    367104   1587768     19%    /usr/X11R6
/dev/sd1h      8917948   1441560   7030492    17%    /usr/local
/dev/sd1j      4122108         4   3916000             0%    /usr/obj
/dev/sd1i      3018236         4   2867324             0%    /usr/src
/dev/sd1e      6387260     16980   6050920        0%    /var
と余裕がありますね。



しかし段々2Gではきつくなってきます。
それで 32Gを買いました。
openbsd miscに投稿したのですが

1) openbsdのfdiskはつかいにくいので linuxでします。
use linux (because openbsd fdisk is hard to use)
by fdisk , make /dev/sdb4  Id:a6

2) 「openbsdのinstallboot」命令がうまくいかないので 以下で回避します。
 インストール用のOPENBSD5.5 i386 CDを linuxマシンにさし
これでbootして最短のインストールをおこないます。
これで回避します。   
then use  'openbsd5.5 install CD disk' for <<installboot>>
on  installing   OpenBSD
        use  OpenBSD area  <- 1)
        mount point /  (because original USB has a and b only)
        install  bsd,  bsd.rd,   base55 only

3)それから コピー元のUSBをさきに openbsdの走ってるマシンamd64にさします。
その後 コピー先のUSBをさします。 
すると dmesgにて 元がsd0 先がsd1と認識されてます。 
then openbsd runninng machine,

# mkdir /mnt0
# mkdir /mnt1

# mount /dev/sd0a /mnt0  <- / partition
# mount /dev/sd1a /mnt   <- / partition

# (cd /mnt0; tar cvpf - .)|(cd /mnt1 ; tar xpf -)
#umount /mnt0 => cannot
#umount /mnt1 => cannot

so halt openbsd machine ,

4)then goto linux machine

fdisk /dev/sdb

  make bootable flag on sdb4
最初に bootable flagをつえとけばよかったと思われる。
  ( if 1) has this proceidure , this may be needless )

---
this method is perhaps effective to smaller USB clone , or
USB to Hard disk clone and so so .





2014年6月21日土曜日

やさしい OpenBSD インストール , DHCPDサーバー

全体的な状況は

internet
|
|電波
|

uroad-aero
192.168.100.254
|
|電波
|
run0

openbsd5.7のパソコン
です。



1) run0 は、 buffaroの WLI-UC-GNMで
1000円以下です。



2)CDからインストールします。
インストール先はUSBでも ハードディスクでもどちらもおなじです。




動画も用意しました。 
  http://aoiyuma.mydns.jp/k2.html  
5分位です。




3)この時
LANな時は DHCP にしましょう。
自分のようにwifiな時は  SSIDと パスワードを聞かれますので
いれましょう。


4)swapは 2G以上にします。 自分は3Gにしてます。
すると 驚くほど早くなります。
a と b だけで充分です。


また jp106を確実に使えるようにxdmをインストールしておきます。


5) インストールし 再起動したら
suして、 
 export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/5.7/packages/i386

と打ち込みます。


6)それから

2017/12/3 現在は
/etc/installurl を                         
https://ftp.jaist.ac.jp/pub/OpenBSD
とします。



pkg_add  nano  lftp jvim

をいれます。


それから
cp /usr/local/share/examples/jwm/system.jwmrc /home/a-usr/ .jwmrc

して



 /home/a-usr/.xinitrc
  
export GTK_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
export QT_IM_MODULE=ibus

/usr/local/bin/ibus-daemon -d -x -r
jwm

とします。


また
/etc/rc.conf.local   を
# xdm_flags=
ntpd_flags=
とます。


すると startx で jmw  (ジョー ウィンドウ マネージャー)
が はじまります。
これが 軽量で使いやすい。



ほら、入力状態が表示されてるでしょう。



 7)                   

  1. どんなパッケージがあるか知るために

    lftp   ftp://ftp.openbsd.org/pub/OpenBSD/5.7/packages/i386 > ls >pkg57.txt

    しておくと
     pkg57.txt をみれば分かります。
  2. 日本語フォント と 日本語入力 と firefox をいれます。
    pkg_add   ja-mplus-ttf  
    ibus-anthy  firefox

    前述の.xinitrcで すでに日本語入力ははじまってます。
    が 、 ibus-setup をして環境を設定します。
    以上で 普通のインストはあっさり終了
    日本語が仕え ネットサーフィンができます。
  3. 詳しくは 以下もありますが以下は流しても構わない


     pkg_add ibus  anthy ibus-anthyすると
     To make IBus work when X is started add the following lines to
    ~/.xinitrc or ~/.xsession:

        export GTK_IM_MODULE="ibus"
        export QT_IM_MODULE="ibus"
        export XMODIFIERS="@im=ibus"
        /usr/local/bin/ibus-daemon -d -x -r
    To use IBus within xterm(1) the character locale needs to be UTF-8.
    For example to set it to US English in UTF-8 mode, also add:

        export LC_CTYPE=en_US.UTF-8
    Finally, to display characters correctly make sure to use a Unicode
    (ISO-10646-1) font.



    pkg_add firefox firefox-i18n-jaすると
     To configure Firefox for your language, go to add-ons language
    management (Tools->Add-ons->Languages), click 'activate' on your
    installed language, type "about:config" in the URL-bar and edit
    "general.useragent.locale" (e.g. fr-FR  ja-JP; default is en-US), then
    restart Firefox.






  4. 後は 備忘録

  5. # mount-loop.bat   
    -------
                                                                                                       
    vnconfig /dev/vnd1c lupu-528JP.iso
    mount  /dev/vnd1c  /mnt-loop





    # mount-cd.bat  
    -----------------                                                                                                      
    mount_cd9660 /dev/cd0c /mnt





    #  /etc/httpd.conf  (openBSD謹製の場合)
    ------------------                                                       
    ext_addr="192.168.11.1"

    server "www.protoc.org" {
            listen on $ext_addr port 80
            root "/htdocs/5.7"
    }



wifiを手動で起動するには
 wifi.bat
------------------------------- 
      ifconfig   run0 down
      ifconfig   run0 nwid "URoad-007" wpakey "007" up
      dhclient run0







ユーザーの .profile に                                                   
export LANG=ja_JP.UTF-8

を付け加えるとsshで 入ったときの日本語の文字化けを防ぎます。




xfceのターミナルは日本語の表示ができます。




DHCPDサーバーとして



dhcpdは有線のem0で動かすので
/etc/hostname.em0は   
inet 192.168.1.1 255.255.255.0 NONE
と固定アドレスをあて


/etc/dhcpd.interfaces
em0



/etc/dhcpd.conf 
#option  domain-name "my.domain";
option  domain-name-servers 192.168.100.254;
subnet 192.168.1.0 netmask 255.255.255.0 {
       option routers 192.168.1.1;
        range 192.168.1.32 192.168.1.127;
}


http://www.openbsd.org/faq/faq6.html#DHCPserver をみて
 echo 'dhcpd_flags=""' >>/etc/rc.conf.local






openbsdに最初からそなわているftpdです。

それから anonymous はユーザーがftpです。

ftpだけのユーザーのシェルは /usr/bin/false です。


 ユーザーを /etc/ftpchroot  に記載しないと ftp接続できないです。
つまり 3種類あります。
こまかな配慮です。






grub4dosで
# menu.lst produced by grub4dosconfig-v1.9.1
color white/blue black/cyan white/black cyan/black
#splashimage=/splash.xpm
timeout 10
default 0


title OpenBSD
      chainloader (hd0,3)+1
      rootnoverify (hd0,3)
      boot

title ARCH
  root (hd0,1)
  kernel /boot/vmlinuz-linux root=/dev/sda2 ro
  initrd /boot/initramfs-linux.img

title Puppy precise 5.7.1JP (sda2/p571)
  uuid ded5652f-6c4f-45f2-bfe4-4d92b2c5caa0
  kernel /p571/vmlinuz   psubdir=p571 pmedia=atahd pfix=fsck
  initrd /p571/initrd.gz


title Porteus-3.1 32bit (sda1/boot)
  uuid 68687144-dca8-4657-a887-75d88a131dd8
  kernel    /boot/syslinux/vmlinuz changes=/porteus timezone=Asia/Tokyo kmap=jp,us
  initrd /boot/syslinux/initrd.xz


以上です。