1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FreeBSD をインストールしてみる(ZFS)

Posted at

FreeBSD 10.1 のインストール

某雑誌の影響で久しぶりに FreeBSD を,転がっていた NEC Express5800/S70 にインストールしてみる.おそらく Express5800/S70 は,いろんなところに転がっていると思う.もうすぐ,「10.2」がリリースされるけど気にしない:expressionless:

外部に接続していないので,セキュリティは気にしていません.

せっかくなので,ファイルシステムに ZFS で構築する.メモリ 4G しか積んでないけど…. インストールするのに,ここを参考にしました(ほぼ手順はそのままです >_<)

BootDisk

USB メモリからインストールするので,FreeBSD-10.1-RELEASE-amd64-memstick.img をダウンロードして,USB メモリにイメージを書き込む.

注意: BIOS の【Usb Legacy Support】を有効にしないと USB メモリからブートできないが,有効にすると PS/2 キーボードが誤動作する(環境によるのかな?).

インストール

適当にメモしたもの.

1 USB メモリからブート
2 【Welcom to FreeBSD】 1. Boot Multi User
3 【Welcom】 Install
4 【Keymap Selection】 Continue with default keymap
5 【Set Hostname】 ホスト名の入力
6 【Distribution Select】games,lib32,ports,src
7 【Partationing】 Shell

# gpart destroy ada0
# gpart create -s gpt ada0
# gpart show ada0
# gpart add -s 512k -t freebsd-boot -l boot0 ada0
# gpart add -a 4k -t freebsd-zfs -l disk0 ada0
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
# gpart set -a active ada0

# zpool create -o altroot=/mnt -m none -f zroot /dev/gpt/disk0
# zfs set atime=off zroot
# zfs set checksum=fletcher4 zroot
# zfs create -V 8g -o checksum=off zroot/swap0
# zfs set org.freebsd:swap=on zroot/swap0

# zfs create -o mountpoint=none zroot/ROOT
# zfs create -o mountpoint=/ zroot/ROOT/default
# zfs create -o mountpoint=/tmp -o setuid=off zroot/tmp

# zfs create -o mountpoint=/usr zroot/usr
# zfs create zroot/usr/home
# zfs create zroot/usr/local
# zfs create -o compression=lz4 -o setuid=off zroot/usr/ports
# zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
# zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages
# zfs create -o compression=lz4 -o exec=off -o setuid=off zroot/usr/src

# zfs create -o mountpoint=/var zroot/var
# zfs create -o compression=lz4 -o exec=off -o setuid=off zroot/var/crash
# zfs create -o compression=lz4 -o exec=off -o setuid=off zroot/var/log
# zfs create -o compression=lz4 -o atime=on zroot/var/mail
# zfs create -o compression=lz4 -o setuid=off zroot/var/tmp

# mkdir -p /mnt/boot/zfs
# zpool set cachefile=/mnt/boot/zfs/zpool.cache zroot
# zpool set bootfs=zroot/ROOT/default zroot
# exit

8 【Network Configuration】 ネットワークの設定
9 【Select local or UTC clock】 NO→Japan
10 【System Configuration】 変更なし
11 【Add User Accounts】 No (Group の設定ができないので,後からユーザを作成)
12 【Final Configuration】 Exit
13 【Manual Configration】 Yes

# echo 'zfs_load="YES"' >> /boot/loader.conf
# echo 'zfs_enable="YES"' >> /etc/rc.conf

# exit

14 【Complete】Reboot

設定

root でログインする.まぁ,root しかいないのだけど…

ユーザ設定

# pw groupadd Groupname -g GID
# adduser
# pw groupmod wheel -m Username

仮想コンソールを無効

# vi /etc/ttys
ttyv1 ~ ttyv8 の status を off に変更

メールの設定

# cd /etc/mail
# vi aliases
---
root: username
useaname: mailaddrss
---

# make aliases
# make
# vi hostname.cf
---
dnl DAEMON_OPTIONS(`Name=IPv6, Family=inet6, Modifiers=O')
---
# make cf

時刻同期

# grep ntpdate /usr/share/examples/etc/defaults/rc.conf >> /etc/rc.conf
# vi /etc/rc.conf
---
ntpdate_enable="YES"
ntpdate_flags="-b -4"
ntpdate_hosts="ntpserver"
---

# vi /etc/crontab
---
# ntpdate
0       12      *       *       *       root    /usr/sbin/ntpdate ntpserver > /dev/null 2>&1
---

SSH サーバの設定

公開鍵認証ができることを確認後,パスワード認証などを無効に

# vi /etc/ssh/sshd_config
---
Port xxxx
PermitRootLogin no
RSAAuthentication yes
PubkeyAuthentication yes
RhostsRSAAuthentication no
HostbasedAuthentication no
IgnoreRhosts yes
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
---

Port は,ssh の接続を 22 番 から xxxx に変更する.

pf(パケットフィルタ) の設定

# vi /etc/rc.conf
---
pf_enable="YES"
pflog_enable="YES"
---

# vi /etc/pf.conf
---
if = "em0"
ssh = "xxxx"

tcp_service = "{http,https}"
acceptables_ip = "{10.1.xx.xx, 10.1.xx.yy}"

# packet is silently dropped
set block-policy drop

# scrub incoming packets
scrub in all

# Allow Local Loop back
set skip on lo0

block in log  all
block out all

pass in quick on $if inet proto tcp from $acceptables_ip to any port $ssh modulate state flags S/SA
pass in quick on $if inet proto tcp all port $tcp_service modulate state flags S/SA

pass out quick on $if proto tcp all modulate state flags S/SA
pass out quick on $if proto {udp, icmp} all keep state
---

# pfctl -nf /etc/pf.conf
# service pf start
# service pflog start

acceptables_ip は,接続を許可する IP アドレス.

セキュリティパッチの適用

プロキシの設定

# setenv HTTP_PROXY "http://proxy:port"
# setenv HTTP_PROXY_AUTH "basic:*:username:password"

# freebsd-update fetch
# freebsd-update install

gunzip: (stdin): unexpected end of file と表示されて,うまくいかない場合は,/var/db/freebsd-update/files を削除しから

# freebsd-update fetch
# freebsd-update install

make.conf,src.conf

# vi /etc/make.conf
---
CPUTYPE?=prescott

KERNCONF=MyKernel

OPTIONS_UNSET=IPV6 X11
---

# vi /etc/src.conf
---
WITHOUT_INET6=yes
---

Kernel 再構築

# cd /usr/src/sys/amd64/conf
# vi MyKernel
---
include GENERIC
ident   MyKernel

必要な設定
---

# cd /usr/src
# make cleandir
# make cleandir (2 回必要 もしくは,chflags -R noschg /usr/obj/*)
# rm -rf /usr/obj
# make buildkernel
# make installkernel

Ctrl と Caps Lock の入れ替え

US キーボードを使用.

# cd /usr/share/syscons/keymaps
# cp us.iso.kbd us.isox.kbd
# vi us.isox.kbd
---
029 clock clock clock clock clock clock clock clock 0
058 lctrl lctrl lctrl lctrl lctrl lctrl lctrl lctrl 0
---

# kbdcontrol -l us.isox

# vi /etc/rc.conf
---
keymap="us,isox.kbd"
---

Caps Lock が必要なければ,【us.pc-ctrl.kbd】を使用する

Ports

Ports Collection の更新

初回のみ

# portsnap fetch
# portsnap extract

次回からは

# portsnap fetch
# portsnap update

もしくは

# portsnap fetch update

で更新する.

アプリケーションのインストール

Ports の管理に portmaster を入れる.

# cd /usr/ports/ports-mgmt/portmaster/
# make install
# make clean

sudo も入れて置く.

# cd /usr/ports/security/sudo
# make install
# make clean
# vi /usr/local/etc/sudoers.d/wheel
---
%wheel ALL=(ALL) ALL
---

少し前に流行っていたようなので,fish shell も入れる.
シェルの変更は,一般ユーザのみに….

# cd /usr/ports/shells/fish
# make install
# make clean
$ chsh -s /usr/local/bin/fish

tmux リモートから作業するので入れる.個人的には,screentmux は接続先で立ち上げるので.

切断されたセッションが復元されればいいので,Mosh(mobile shell) でもいいのだけ,接続先と接続元に両方にインストールしないといけないので,やめておく.

# cd /usr/ports/sysutils/tmux
# make install
# make clean

あとは,curlgit も入れて置く.

# portmaster /usr/ports/ftp/curl
# portmaster /usr/ports/devel/git

最低限入れるのは,これぐらいで, あとは必要に応じてインストールすればいいかな?

後は,USB の Wi-Fi アダプタを繋げて,無線 LAN のアクセスポイントと netatalk をいれて Time Machine サーバにでもする予定です.

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?