NAS化
Sambaを導入してNAS化する。
ただし、現在以下のようなマウント状態なので、以前のように/mnt/disk1にマウントしたパーティションだけをNASで使うようするため、パーティション変更から始める。
その方が使用量の確認がしやすいから、というのが一番の理由。
KUROBOX-PRO:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 239758888 1037776 226542016 1% /
udev 10240 0 10240 0% /dev
tmpfs 12560 116 12444 1% /run
/dev/sda2 239758888 1037776 226542016 1% /
tmpfs 5120 0 5120 0% /run/lock
tmpfs 98220 0 98220 0% /run/shm
/dev/sda1 233191 12534 208216 6% /boot
パーティション分割
/dev/sda2の240GBほどのルート領域を20GBに変更して残りを/dev/sdxとして/mnt/disk1にマウントするようにしたいが、玄箱PROに接続したままの状態ではパーティション変更が難しいのでいったん玄箱PROから物理的に外して別環境で作業する。
今回使ったのはGParted。
Linux環境が手元になかったのでGParted Live CD/USB/HD/PXE Bootable ImageをダウンロードしてDVDに焼き、このDVDでブートして作業した。キャプチャとか取っていないので詳細は割愛。
外したHDDはUSBで接続できる変換ケーブルを使用
(作業前)
root@debian:/mnt# fdisk /debv/sda
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007d432
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 499712 487663615 243581952 83 Linux
/dev/sda3 487665662 488396799 365569 5 Extended
/dev/sda5 487665664 488396799 365568 82 Linux swap / Solaris
Command (m for help): q
(作業後)
KUROBOX-PRO:~# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007d432
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 499712 42442751 20971520 83 Linux
/dev/sda3 487665662 488396799 365569 5 Extended
/dev/sda4 42442752 487663615 222610432 83 Linux
/dev/sda5 487665664 488396799 365568 82 Linux swap / Solaris
Partition table entries are not in disk order
Command (m for help): q
/dev/sda4が新しく切り出したNAS用の領域、これを/mnt/disk1にマウントすれば以前と同じように使える。
自動的にマウントされるようにfstabに追記しておく
KUROBOX-PRO:~# vi /etc/fstab
/dev/sda4 /mnt/disk1 ext4 defaults 1 1
Samba導入
まずはSambaをインストール
KUROBOX-PRO:~# apt-get install samba
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
dbus libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdbus-1-3
libfile-copy-recursive-perl libsystemd-login0 libtalloc2 libtdb1 libwbclient0 samba-common
samba-common-bin tdb-tools update-inetd
Suggested packages:
dbus-x11 cups-common openbsd-inetd inet-superserver smbldap-tools ldb-tools ctdb
The following NEW packages will be installed:
dbus libavahi-client3 libavahi-common-data libavahi-common3 libcups2 libdbus-1-3
libfile-copy-recursive-perl libsystemd-login0 libtalloc2 libtdb1 libwbclient0 samba samba-common
samba-common-bin tdb-tools update-inetd
0 upgraded, 16 newly installed, 0 to remove and 0 not upgraded.
Need to get 7,495 kB of archives.
After this operation, 40.3 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://ftp.jp.debian.org/debian/ wheezy/main libavahi-common-data armel 0.6.31-2 [136 kB]
Get:2 http://ftp.jp.debian.org/debian/ wheezy/main libavahi-common3 armel 0.6.31-2 [54.5 kB]
Get:3 http://security.debian.org/ wheezy/updates/main libdbus-1-3 armel 1.6.8-1+deb7u6 [155 kB]
Get:4 http://ftp.jp.debian.org/debian/ wheezy/main libavahi-client3 armel 0.6.31-2 [55.5 kB]
Get:5 http://ftp.jp.debian.org/debian/ wheezy/main libtalloc2 armel 2.0.7+git20120207-1 [22.4 kB]
Get:6 http://security.debian.org/ wheezy/updates/main libcups2 armel 1.5.3-5+deb7u5 [241 kB]
Get:7 http://ftp.jp.debian.org/debian/ wheezy/main libtdb1 armel 1.2.10-2 [36.9 kB]
Get:8 http://ftp.jp.debian.org/debian/ wheezy/main libfile-copy-recursive-perl all 0.38-1 [20.6 kB]
Get:9 http://ftp.jp.debian.org/debian/ wheezy/main update-inetd all 4.43 [21.8 kB]
Get:10 http://ftp.jp.debian.org/debian/ wheezy/main libsystemd-login0 armel 44-11+deb7u4 [28.5 kB]
Get:11 http://ftp.jp.debian.org/debian/ wheezy/main tdb-tools armel 1.2.10-2 [27.7 kB]
Get:12 http://security.debian.org/ wheezy/updates/main libwbclient0 armel 2:3.6.6-6+deb7u5 [92.2 kB]
Get:13 http://security.debian.org/ wheezy/updates/main samba-common all 2:3.6.6-6+deb7u5 [214 kB]
Get:14 http://security.debian.org/ wheezy/updates/main samba armel 2:3.6.6-6+deb7u5 [3,325 kB]
Get:15 http://security.debian.org/ wheezy/updates/main samba-common-bin armel 2:3.6.6-6+deb7u5 [2,707 kB]
Get:16 http://security.debian.org/ wheezy/updates/main dbus armel 1.6.8-1+deb7u6 [357 kB]
Fetched 7,495 kB in 9s (767 kB/s)
Preconfiguring packages ...
Selecting previously unselected package libavahi-common-data:armel.
(Reading database ... 24887 files and directories currently installed.)
Unpacking libavahi-common-data:armel (from .../libavahi-common-data_0.6.31-2_armel.deb) ...
Selecting previously unselected package libavahi-common3:armel.
Unpacking libavahi-common3:armel (from .../libavahi-common3_0.6.31-2_armel.deb) ...
Selecting previously unselected package libdbus-1-3:armel.
Unpacking libdbus-1-3:armel (from .../libdbus-1-3_1.6.8-1+deb7u6_armel.deb) ...
Selecting previously unselected package libavahi-client3:armel.
Unpacking libavahi-client3:armel (from .../libavahi-client3_0.6.31-2_armel.deb) ...
Selecting previously unselected package libcups2:armel.
Unpacking libcups2:armel (from .../libcups2_1.5.3-5+deb7u5_armel.deb) ...
Selecting previously unselected package libtalloc2:armel.
Unpacking libtalloc2:armel (from .../libtalloc2_2.0.7+git20120207-1_armel.deb) ...
Selecting previously unselected package libtdb1:armel.
Unpacking libtdb1:armel (from .../libtdb1_1.2.10-2_armel.deb) ...
Selecting previously unselected package libwbclient0:armel.
Unpacking libwbclient0:armel (from .../libwbclient0_2%3a3.6.6-6+deb7u5_armel.deb) ...
Selecting previously unselected package samba-common.
Unpacking samba-common (from .../samba-common_2%3a3.6.6-6+deb7u5_all.deb) ...
Selecting previously unselected package libfile-copy-recursive-perl.
Unpacking libfile-copy-recursive-perl (from .../libfile-copy-recursive-perl_0.38-1_all.deb) ...
Selecting previously unselected package update-inetd.
Unpacking update-inetd (from .../update-inetd_4.43_all.deb) ...
Selecting previously unselected package samba.
Unpacking samba (from .../samba_2%3a3.6.6-6+deb7u5_armel.deb) ...
Selecting previously unselected package samba-common-bin.
Unpacking samba-common-bin (from .../samba-common-bin_2%3a3.6.6-6+deb7u5_armel.deb) ...
Selecting previously unselected package libsystemd-login0:armel.
Unpacking libsystemd-login0:armel (from .../libsystemd-login0_44-11+deb7u4_armel.deb) ...
Selecting previously unselected package dbus.
Unpacking dbus (from .../dbus_1.6.8-1+deb7u6_armel.deb) ...
Selecting previously unselected package tdb-tools.
Unpacking tdb-tools (from .../tdb-tools_1.2.10-2_armel.deb) ...
Processing triggers for man-db ...
Setting up libavahi-common-data:armel (0.6.31-2) ...
Setting up libavahi-common3:armel (0.6.31-2) ...
Setting up libdbus-1-3:armel (1.6.8-1+deb7u6) ...
Setting up libavahi-client3:armel (0.6.31-2) ...
Setting up libcups2:armel (1.5.3-5+deb7u5) ...
Setting up libtalloc2:armel (2.0.7+git20120207-1) ...
Setting up libtdb1:armel (1.2.10-2) ...
Setting up libwbclient0:armel (2:3.6.6-6+deb7u5) ...
Setting up samba-common (2:3.6.6-6+deb7u5) ...
Creating config file /etc/samba/smb.conf with new version
Setting up libfile-copy-recursive-perl (0.38-1) ...
Setting up update-inetd (4.43) ...
Setting up samba (2:3.6.6-6+deb7u5) ...
Generating /etc/default/samba...
Adding group `sambashare' (GID 106) ...
Done.
update-alternatives: using /usr/bin/smbstatus.samba3 to provide /usr/bin/smbstatus (smbstatus) in auto mode
Starting Samba daemons: nmbd smbd.
Setting up samba-common-bin (2:3.6.6-6+deb7u5) ...
update-alternatives: using /usr/bin/nmblookup.samba3 to provide /usr/bin/nmblookup (nmblookup) in auto mode
update-alternatives: using /usr/bin/net.samba3 to provide /usr/bin/net (net) in auto mode
update-alternatives: using /usr/bin/testparm.samba3 to provide /usr/bin/testparm (testparm) in auto mode
Setting up libsystemd-login0:armel (44-11+deb7u4) ...
Setting up dbus (1.6.8-1+deb7u6) ...
Starting system message bus: dbus.
Setting up tdb-tools (1.2.10-2) ...
update-alternatives: using /usr/bin/tdbbackup.tdbtools to provide /usr/bin/tdbbackup (tdbbackup) in auto mode
KUROBOX-PRO:~#
デフォルトの設定と見比べて別途smb.confを作成する
KUROBOX-PRO:~# cat /etc/samba/smb.conf
KUROBOX-PRO:~# mv /etc/samba/smb.conf /etc/samba/smb.conf_
KUROBOX-PRO:~# vi /etc/samba/smb.conf
#
# smb.conf
#
[global]
# Default Settings
workgroup = WORKGROUP
server string = %h server
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
panic action = /usr/share/samba/panic-action %d
encrypt passwords = true
passdb backend = tdbsam
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user
# Custom Settings
unix charset = UTF-8
dos charset = CP932
netbios name = KUROBOX-PRO
guest account = nobody
null passwords = yes
[printers]
# Default Settings
comment = All Printers
browseable = no
path = /var/spool/samba
printable = yes
guest ok = no
read only = yes
create mask = 0700
[print$]
# Default Settings
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
read only = yes
guest ok = no
[homes]
# Default Settings
comment = Home Directories
browseable = no
read only = yes
create mask = 0700
directory mask = 0700
valid users = %S
[share]
comment = KURO-BOX Local Drive.
path = /mnt/disk1/share
guest ok = yes
writable = yes
[share0]
comment = BUFFALO RAID0(192.168.3.30) Remote Drive.
path = /mnt/disk1/share0
guest ok = yes
writable = yes
[share1]
comment = NASNE(192.168.3.20) Remote Drive.
path = /mnt/disk1/share1
guest ok = yes
writable = yes
動作確認
KUROBOX-PRO:~# /etc/init.d/samba restart
Stopping Samba daemons: nmbd smbd.
Starting Samba daemons: nmbd smbd.
KUROBOX-PRO:~# mount -t cifs //192.168.3.50/share /mnt/nfs -o user=guest
KUROBOX-PRO:~#
OK
ちゃんとマウントされた
KUROBOX-PRO:~# touch /mnt/nfs/test.txt
KUROBOX-PRO:~# echo "aaa" >> /mnt/nfs/test.txt
KUROBOX-PRO:~# ls -l /mnt/nfs/test.txt
-rw-r--r-- 1 nobody nogroup 4 Mar 13 17:43 /mnt/nfs/test.txt
KUROBOX-PRO:~# cat /mnt/nfs/test.txt
aaa
guest接続するとnobodyでアクセスできることがわかった。
最終更新:2015年03月12日 09:13