ノートPCのVirtualBox上にDebian環境を作る
やりたいこと
- ホストOSはWindows,ゲストOSはDebian,仮想化にはVirtualBoxを使用
- インターネットにはNATで接続
- DebianにはGUI環境をインストールせず,常にPuTTYを通じて使用する
- DebianのファイルをSambaを使ってWindowsと共有する
やったこと
- VMのネットワークの設定
インターネットにはNATで接続したいので,アダプタ 1 にはNATを割り当てます.さらに,ポートフォワーディングの設定でホストポート2222からゲストポート22へのポートフォワードの設定を追加します (IPの欄は空).また,ホスト-ゲスト間の通信のためにアダプタ 2 にホストオンリーアダプタを割り当てます. - Debianのインストール
普通にインストールします.途中にどのアダプタでインターネットに接続するかを聞かれるので,最初のアダプタを選びます. - IPアドレスの設定など
/etc/network/interfaces を以下のように編集します.# The loopback network interface auto lo iface lo inet loopback # The primary network interface (NAT) auto eth0 allow-hotplug eth0 iface eth0 inet dhcp # The secondary network interface (Host-only) auto eth1 iface eth1 inet static address 192.168.56.102 netmask 255.255.255.0
次にネットワークを再起動します.sudo /etc/init.d/networking restart
- Samba の設定
まず apt で Samba をインストールします.インストール中にWORKGROUPを聞かれるので,WindowsのWORKGROUPと同じものを指定します.sudo apt-get install samba
/etc/samba/smb.conf を編集します.diff はこんなかんじ.--- a/samba/smb.conf +++ b/samba/smb.conf @@ -114,7 +114,7 @@ # This boolean parameter controls whether Samba attempts to sync the Unix # password with the SMB password when the encrypted SMB password in the # passdb is changed. - unix password sync = yes + unix password sync = no # For Unix password sync to work on a Debian GNU/Linux system, the following # parameters must be set (thanks to Ian Kahan < for @@ -239,15 +239,15 @@ # By default, the home directories are exported read-only. Change the # next parameter to 'no' if you want to be able to write to them. - read only = yes + read only = no # File creation mask is set to 0700 for security reasons. If you want to # create files with group=rw permissions, set next parameter to 0775. - create mask = 0700 + create mask = 0644 # Directory creation mask is set to 0700 for security reasons. If you want to # create dirs. with group=rw permissions, set next parameter to 0775. - directory mask = 0700 + directory mask = 0755 # By default, \\server\username shares can be connected to by anyone # with access to the samba server.
Samba のアカウントを作ります.sudo smbpasswd -a nojima
最後に Samba を再起動します.sudo /etc/init.d/samba restart
Windows側のエクスプローラのアドレス欄に\\192.168.56.102
と打ち込んでアクセスできれば成功です. - Windows の hosts ファイルの書き換え
毎回VMのIPアドレスを打ち込むのは面倒なので,hostsに名前を登録しておきます. C:\Windows\System32\drivers\etc\hosts に以下の行を追加します.(debian-vmのところはVMの名前)192.168.56.102 debian-vm
書き換えに管理者権限が必要だったりするので,管理者権限でメモ帳などを実行し,そこから編集するとよいです.
ポートフォワードについて
PuTTYでVMにアクセスする際にはポートフォワードを用いてアクセスする方が便利です.(つまり localhost の 2222 番ポートにアクセスする) 直接VMにアクセスすると,ノートPCをスリープさせた時に接続が切れてしまいますが,何故かポートフォワードを使ってアクセスすると接続が切れません.どうして接続が切れないのかよくわかりませんが,とりあえず便利です.