Ubuntu 16.04 を VMware にインストール

Ubuntu 16.04 LTS を VMware にインストールしたメモ

# 所感

1. 普通に ```apt-get update``` すると起動時にエラーが出る（無視できるものかも）
1. 普通にインストールしただけでは共有フォルダ機能が動かない
    1. 昔からトラブル多い機能だけど、ちょっとお粗末

# 環境

1. Mac OS X 10.11.5 (英語)
2. VMware Fusion 8.1.1
3. ubuntu-16.04-server-amd64.iso

# 手順

1. VMware の File メニューから New
    1.  Install from disc or image を選んで Continue
![Screen Shot 2016-07-23 at 09.08.21.png](https://qiita-image-store.s3.amazonaws.com/0/131106/64ba0b64-ed10-4dfa-8eb1-15b3cc103104.png)

2. ISO を選択
![Screen Shot 2016-07-23 at 09.09.32.png](https://qiita-image-store.s3.amazonaws.com/0/131106/87a4c08e-2032-d32d-5045-9762799a76f2.png)

3. Use Easy Install は OFF にする
![Screen Shot 2016-07-23 at 09.21.04.png](https://qiita-image-store.s3.amazonaws.com/0/131106/981c3fb9-a683-be85-03df-0c48d21e8e17.png)

  1. 毎回デフォルトで ON にするのホントに止めてほしい
    1. Ubuntu 16.04 では Easy Install ちゃんと動いたが、最近でも CentOS でインストーラーが止まってたことがあった
        1. 入社数年目だけど VMware 慣れてない人が結構な時間を無駄にしてた
            1. その人自体のスキルレベル云々という話もあるけど
            2. そもそも OS インストーラー程度の細部を隠そうという Microsoft 的な余計なお世話が開発者にとっては邪魔
            3. 大量に VM を作る時に手順を省略するには [kickstart](https://gist.github.com/abrahamrhoffman/6dae37d7bb533ae50ccb) 使えば良い ([マニュアル](https://www.centos.org/docs/5/html/5.2/Installation_Guide/s1-kickstart2-file.html))

4. Customize Settings でネットワークを Bridged へ変更し、 Printer, Sound Card, Camera などサーバーに不要なデバイスを削除する
![Screen Shot 2016-07-23 at 09.31.29.png](https://qiita-image-store.s3.amazonaws.com/0/131106/c6a5f7dd-e736-002d-f868-adade8550b5e.png)

  1. 一旦セーブする必要がある
![Screen Shot 2016-07-23 at 09.32.28.png](https://qiita-image-store.s3.amazonaws.com/0/131106/bdc80f3b-b300-8e43-c70f-6064bd424bef.png)

  2. Settings 画面
![Screen Shot 2016-07-23 at 09.33.16.png](https://qiita-image-store.s3.amazonaws.com/0/131106/f25ad433-8d1a-e622-84fd-017b24901a65.png)

  3. ホストや別マシンから ssh や http アクセスできるように Network Adapter 画面でデフォルトの ```Share with my Mac``` (NAT) から Bridged Networking へ変更
![Screen Shot 2016-07-26 at 09.39.20.png](https://qiita-image-store.s3.amazonaws.com/0/131106/65610406-90d6-9b11-7bb2-1e48c28480da.png)
        1. NAT の Port Forwarding でも実現できるけれど[パッチを適用しないとならないらしい](http://blogs.vmware.com/teamfusion/2016/01/workaround-of-nat-port-forwarding-issue-in-fusion-8-1.html)（[8.1.1 で修正された](http://blogs.vmware.com/teamfusion/2016/04/fusion-8-1-1-available-now.html) とアナウンスされたが治ってない？）

  3. Remove Printer Port
![Screen Shot 2016-07-23 at 09.38.52.png](https://qiita-image-store.s3.amazonaws.com/0/131106/60f4cc3f-3897-b829-e5c4-9148676fe6f8.png)

  4. Remove Sound Card
![Screen Shot 2016-07-23 at 09.38.13.png](https://qiita-image-store.s3.amazonaws.com/0/131106/2f430dd7-b74f-9015-b0b7-e63b23177e1d.png)

  5. Remove Camera
![Screen Shot 2016-07-23 at 09.40.43.png](https://qiita-image-store.s3.amazonaws.com/0/131106/5fa8b1dc-db45-1a69-c623-c065ea1cf594.png)

  6. Advanced で Power Options の Shut Down を Power Off (hard) に変更
![Screen Shot 2016-07-23 at 09.46.21.png](https://qiita-image-store.s3.amazonaws.com/0/131106/2d62bd39-5311-1704-cedf-a9e95c7799c1.png)

      1. 最近の VMware Fusion では Virtual Machine メニューを開いて Option キーを押さないとPower Off ができなくなった
      1. Shut Down は OS 内部からできるし Power Off は Snapshot に戻る時に使いたい

6. VM を起動
![Screen Shot 2016-07-23 at 09.51.28.png](https://qiita-image-store.s3.amazonaws.com/0/131106/6689d0cb-64d3-e67d-3d2a-4acd00e1b6b6.png)

7. Language は English のまま
![Screen Shot 2016-07-23 at 09.51.49.png](https://qiita-image-store.s3.amazonaws.com/0/131106/2ac1d7fd-7672-4507-cb41-4b474231bea3.png)

  1. エラーメッセージなど English の方が Google し易い

8. Install Ubuntu Server
![Screen Shot 2016-07-23 at 09.52.15.png](https://qiita-image-store.s3.amazonaws.com/0/131106/1ff486bb-beda-57cc-7150-d096dfca38a6.png)

9. 再度言語を聞かれるので English のまま
![Screen Shot 2016-07-23 at 09.54.03.png](https://qiita-image-store.s3.amazonaws.com/0/131106/dbf3350a-eb62-c5d8-ef30-2dd33b786b6c.png)

10. Region を United States から Japan に変更 (other -> Asia -> Japan)
![Screen Shot 2016-07-23 at 09.55.29.png](https://qiita-image-store.s3.amazonaws.com/0/131106/9175cb34-9a7c-111a-9292-c70c2a5e4e29.png)

11. Locale も英語のまま
![Screen Shot 2016-07-23 at 09.56.59.png](https://qiita-image-store.s3.amazonaws.com/0/131106/aba3c2fd-4fd9-c2bd-9741-65dbc9dde9b6.png)

12. キーボードは Japanese に変更しないと記号が打ちにくい
![Screen Shot 2016-07-23 at 09.57.38.png](https://qiita-image-store.s3.amazonaws.com/0/131106/5959cd1b-427d-41af-f839-da7e6d71e1cd.png)
![Screen Shot 2016-07-23 at 09.58.16.png](https://qiita-image-store.s3.amazonaws.com/0/131106/b0774793-dd5a-5f5f-9b11-189f2b4f23c3.png)
![Screen Shot 2016-07-23 at 09.59.33.png](https://qiita-image-store.s3.amazonaws.com/0/131106/c7663645-13f5-6475-99d5-5ecab9e13a32.png)

13. ここでデバイスやネットワーク情報が自動検出される
![Screen Shot 2016-07-23 at 09.59.54.png](https://qiita-image-store.s3.amazonaws.com/0/131106/e308fb69-7f66-49d3-26c1-3989aac2f20a.png)

14. ホスト名を設定
![Screen Shot 2016-07-23 at 10.01.23.png](https://qiita-image-store.s3.amazonaws.com/0/131106/a1e683aa-2e38-b3ae-8bb8-6041d8190af8.png)

15. ユーザ姓名、アカウント名、パスワードを設定
![Screen Shot 2016-07-23 at 10.02.20.png](https://qiita-image-store.s3.amazonaws.com/0/131106/57e67e4d-1e5f-976b-00c6-cdde472ed697.png)
![Screen Shot 2016-07-23 at 10.05.41.png](https://qiita-image-store.s3.amazonaws.com/0/131106/81ceb263-868c-c825-5600-88262194a77d.png)
![Screen Shot 2016-07-23 at 10.08.25.png](https://qiita-image-store.s3.amazonaws.com/0/131106/63a54e3f-2da7-f698-084a-d343cd30ab8c.png)
![Screen Shot 2016-07-23 at 10.08.51.png](https://qiita-image-store.s3.amazonaws.com/0/131106/aca0e39b-fbf5-a060-75b1-0af763cbfffe.png)

16. ホームディレクトリの暗号化はしない（デフォルト）
![Screen Shot 2016-07-23 at 10.10.33.png](https://qiita-image-store.s3.amazonaws.com/0/131106/b37072b2-444f-e150-ae43-522902cf2e79.png)

17. 正しいタイムゾーンが自動的に検出された
![Screen Shot 2016-07-23 at 10.12.36.png](https://qiita-image-store.s3.amazonaws.com/0/131106/f75acbb4-b28d-a619-7e11-8c3afd756347.png)

18. LVM を使わないように変更
![Screen Shot 2016-07-23 at 11.10.56.png](https://qiita-image-store.s3.amazonaws.com/0/131106/8a942cde-69e3-fd41-0beb-c4ecb8367d07.png)

  1. 仮にこの VM を ESXi に持ってったとしても [LVM なしでリサイズできる](http://serverfault.com/a/633021)らしいし
  2. 構成がシンプルになる

19. ディスクを選択
![Screen Shot 2016-07-23 at 11.11.41.png](https://qiita-image-store.s3.amazonaws.com/0/131106/c6cc1ba9-5aea-40b0-3ae3-adce20accabe.png)

20. 大きなパーティション1個とスワップ用のパーティションができるので Yes
![Screen Shot 2016-07-23 at 11.13.37.png](https://qiita-image-store.s3.amazonaws.com/0/131106/eead9c6d-666b-9441-a693-23b4a5dbd292.png)

  1. No を選ぶとパーティション設定を調整できる

21. 今回の環境ではプロキシは不要
![Screen Shot 2016-07-23 at 11.18.01.png](https://qiita-image-store.s3.amazonaws.com/0/131106/07d23c57-4ed4-d851-285d-5969f073e84f.png)

22. 自動更新はしない（デフォルト）
![Screen Shot 2016-07-23 at 11.19.35.png](https://qiita-image-store.s3.amazonaws.com/0/131106/b3617714-8d9d-18bc-41b8-cbb92cc07139.png)

23. [standard system utilities](http://askubuntu.com/a/770403) がデフォルトで選択されている。 OpenSSH Server を追加選択（矢印とスペースキーを使う）
![Screen Shot 2016-07-26 at 09.59.07.png](https://qiita-image-store.s3.amazonaws.com/0/131106/e06b9c06-9de7-1963-edc4-9340d4e8b88a.png)
    1. Server 用 ISO なんだから、デフォルトで ssh サーバーはインストールして欲しかった。

24. ブートローダーを MBR へインストール（デフォルト）
![Screen Shot 2016-07-23 at 11.24.08.png](https://qiita-image-store.s3.amazonaws.com/0/131106/df382f84-db14-b196-7251-2cabd89403b5.png)

25. インストール完了
![Screen Shot 2016-07-23 at 11.26.02.png](https://qiita-image-store.s3.amazonaws.com/0/131106/7bb5da51-f44e-c99e-ffbe-f607673f5d47.png)

  1. 自動的に再起動するが、再起動後に素早く Power Off してスナップショットを取りたい

25. 起動画面
![Screen Shot 2016-07-23 at 22.28.58.png](https://qiita-image-store.s3.amazonaws.com/0/131106/9ceadc0d-8f80-abf4-ff8c-b0ad7cbf0ca8.png)

26. バージョン情報
![Screen Shot 2016-07-23 at 22.30.03.png](https://qiita-image-store.s3.amazonaws.com/0/131106/c3a215eb-7c82-c52b-937f-ce89fd6cfa84.png)
    1. root ではログインできない

27. パッケージを更新（依存関係が変化しているものも含めて）

		$ sudo apt-get dist-upgrade

    1. Mac から ssh 経由で実行すると Locale の選択画面が出てきてデフォルトの UTF8 を選択すると以下のエラーが出る

			locale: Cannot set LC_CTYPE to default locale: No such file or directory
			locale: Cannot set LC_ALL to default locale: No such file or directory

        1. これは Mac の LC_CTYPE 環境変数が ```UTF-8``` だが Linux 側ではその名前の locale が存在しないため（ ```en_US.UTF-8``` なら存在する）
        2. 接続元 (Mac) の LC_CTYPE を接続先 (Linux) へ設定しないようにする
            1. /etc/ssh/sshd_config 内の ```AcceptEnv LANG LC_*``` をコメントアウトして ssh サーバーを再起動、 ssh 再接続してから ```apt-get``` を実行

					$ sudo systemctl restart ssh

        3. VMware 画面で実行すると、そもそも Locale の選択画面が出てこない

28. パッケージ更新後の起動時のエラー ```[FAILED] Failed to start LXD - container startup/shutdown``` を回避
    1. [一度 root で lxd を再起動してやれば良い](http://askubuntu.com/questions/783363/ubuntu-server-16-04-wont-boot-after-installation-fail-to-start-lxd)

			$ sudo service lxd restart

29. ```dmesg``` で確認出来る起動時のエラー ```piix4_smbus 0000:00:007.3: SMBus Host controller not enabled!``` を回避
    1. [Ubuntu が使おうとしている CPU の機能を VMware が提供していない](https://whitehatty.com/2012/09/30/vmware-fusion-5-fix-ubuntu-linux-12-04-host-smbus-controller-not-enabled/)
        1. ```$ sudo cp -p /etc/modprobe.d/blacklist.conf /etc/modprobe.d/blacklist.conf.dist```
        2. ```$ sudo vi /etc/modprobe.d/blacklist.conf```
        3. 以下を追加

				blacklist i2c-piix4

        4. 再起動

30. VMware Tools をアップデート
  1. open-vm-tools がインストール済みなのに Enable Shared Folders を ON にするとエラー
![Screen Shot 2016-07-24 at 00.02.10.png](https://qiita-image-store.s3.amazonaws.com/0/131106/5752c191-271d-abd4-dade-b7af187c7358.png)
![Screen Shot 2016-07-24 at 00.01.46.png](https://qiita-image-store.s3.amazonaws.com/0/131106/11f3c7bb-cf08-30bf-4517-fa3921ba9ff2.png)

			$ vmware-toolbox-cmd -v
			10.0.7.52125 (build-3227872)

  2. [VMware のドキュメント](http://partnerweb.vmware.com/GOSIG/Ubuntu_16_04_LTS.html)に従って vmhgfs ドライバーをインストールしても改善しなかった (VMwareTools-10.0.6-3595377)

      1. VMware の Virtual Machine メニューから Reinstall VMware Tools を選び Install ボタンを押してから

				$ sudo mount /dev/cdrom /media/cdrom
				$ tar xzf /media/cdrom/VMwareTools-10.0.6-3595377.tar.gz
				$ sudo vmware-tools-distrib/vmware-install.pl

      1. 全てのデフォルト値を受け入れる
      2. このステップを飛ばすと自動マウントされない
      3. インストール済みの ```open-vm-tools``` を上書きはしないらしい

  3. [github の open-vm-tools から最新の vmhgfs カーネルモジュールをビルドしてインストール](https://gist.github.com/ChaosData/78c4be897eb3e1acc73ebd87c0fbf07d)（ただし open-vm-tools-desktop はインストールしない）

			$ sudo apt-get install git build-essential autoconf libtool
			$ sudo apt-get install libmspack-dev libglib2.0-dev libprocps4-dev libdumbnet-dev
			$ git clone https://github.com/vmware/open-vm-tools.git
			$ cd open-vm-tools/open-vm-tools/
			$ git log -n 1
			commit 4b745c70aaeaab4adb35fd682a3e60fc7a315ec9
			Author: Ravindra Kumar <ravindrakumar@vmware.com>
			Date:   Wed Jun 15 13:14:07 2016 -0700
			
			    Added details about open-vm-tools-desktop
			
			$ autoreconf -i
			$ ./configure --without-x --without-pam --without-ssl --without-icu
			$ make MODULES=vmhgfs
			$ sudo insmod modules/linux/vmhgfs/vmhgfs.ko
			$ reboot

    1. これで共有フォルダが /mnt/hgfs に自動マウントされる

# 参考: vmware-install.pl の出力
```
$ sudo vmware-tools-distrib/vmware-install.pl
The installer has detected an existing installation of open-vm-tools on this 
system and will not attempt to remove and replace these user-space 
applications. It is recommended to use the open-vm-tools packages provided by 
the operating system. If you do not want to use the existing installation of 
open-vm-tools and attempt to install VMware Tools, you must uninstall the 
open-vm-tools packages and re-run this installer.
The packages that need to be removed are:
open-vm-tools
The installer will next check if there are any missing kernel drivers. Type yes
if you want to do this, otherwise type no [yes] 

Creating a new VMware Tools installer database using the tar4 format.

Installing VMware Tools.

In which directory do you want to install the binary files? 
[/usr/bin] 

What is the directory that contains the init directories (rc0.d/ to rc6.d/)? 
[/etc] 

What is the directory that contains the init scripts? 
[/etc/init.d] 

In which directory do you want to install the daemon files? 
[/usr/sbin] 

In which directory do you want to install the library files? 
[/usr/lib/vmware-tools] 

The path "/usr/lib/vmware-tools" does not exist currently. This program is 
going to create it, including needed parent directories. Is this what you want?
[yes] 

In which directory do you want to install the documentation files? 
[/usr/share/doc/vmware-tools] 

The path "/usr/share/doc/vmware-tools" does not exist currently. This program 
is going to create it, including needed parent directories. Is this what you 
want? [yes] 

The installation of VMware Tools 10.0.6 build-3595377 for Linux completed 
successfully. You can decide to remove this software from your system at any 
time by invoking the following command: "/usr/bin/vmware-uninstall-tools.pl".

Before running VMware Tools for the first time, you need to configure it by 
invoking the following command: "/usr/bin/vmware-config-tools.pl". Do you want 
this program to invoke the command for you now? [yes] 

The file /usr/bin/vmware-hgfsclient that this program was about to install 
already exists.  Overwrite? [no] 

The file /usr/bin/vmhgfs-fuse that this program was about to install already 
exists.  Overwrite? [no] 

The file /sbin/mount.vmhgfs that this program was about to install already 
exists.  Overwrite? [no] 

Initializing...


Making sure services for VMware Tools are stopped.

Stopping VMware Tools services in the virtual machine:
   VMware User Agent (vmware-user):                                    done
   Unmounting HGFS shares:                                             done
   Guest filesystem driver:                                            done
Stopping Thinprint services in the virtual machine:
   Stopping Virtual Printing daemon:                                   done


update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
insserv: Service cups has to be enabled to start service vmware-tools-thinprint
insserv: exiting now!
update-rc.d: error: insserv rejected the script header
WARNING: The installer initially used the 'udpate-rc.d' to setup the 
vmware-tools service.  That command cannot be found.  Please re-install the 
'sysv-rc' package.  This script will now attempt to manually setup the 
vmware-tools service.The module vmci has already been installed on this system by another installer 
or package and will not be modified by this installer.

The module vsock has already been installed on this system by another installer
or package and will not be modified by this installer.

The module vmxnet3 has already been installed on this system by another 
installer or package and will not be modified by this installer.

The module pvscsi has already been installed on this system by another 
installer or package and will not be modified by this installer.

The module vmmemctl has already been installed on this system by another 
installer or package and will not be modified by this installer.

The VMware Host-Guest Filesystem allows for shared folders between the host OS 
and the guest OS in a Fusion or Workstation virtual environment.  Do you wish 
to enable this feature? [yes] 

The vmxnet driver is no longer supported on kernels 3.3 and greater. Please 
upgrade to a newer virtual NIC. (e.g., vmxnet3 or e1000e)

VMware automatic kernel modules enables automatic building and installation of
VMware kernel modules at boot that are not already present. This feature can
be enabled/disabled by re-running vmware-config-tools.pl.

Would you like to enable VMware automatic kernel modules?
[no] 

Creating a new initrd boot image for the kernel.
update-initramfs: Generating /boot/initrd.img-4.4.0-31-generic
W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
   Checking acpi hot plug                                              done
Starting VMware Tools services in the virtual machine:
   Switching to guest configuration:                                   done
   Guest filesystem driver:                                            done
   Mounting HGFS shares:                                               done
   Starting Virtual Printing daemon:                                   done
The configuration of VMware Tools 10.0.6 build-3595377 for Linux for this 
running kernel completed successfully.

Enjoy,

--the VMware team

Found VMware Tools CDROM mounted at /media/cdrom. Ejecting device /dev/sr0 ...
```