なんでもノート

t0m00m0tのノート。

VirtualBoxでLinuxコンソールのウィンドウを大きくする

目的

VirtualBoxのコンソールのウィンドウを大きくする。(そもそもターミナル経由でアクセスするので意味ないのでは?という疑問は置いといて・・・)

手順の流れ

  1. Guest Additionsのインストール
  2. GRUB2の解像度設定

Guest Additionsとは?

VirtualBoxには仮想マシンに直接インストールして使い勝手をよくする「Guest Additions」というツールが用意されている。VitualBox公式によるとデバイスドライバとアプリケーションで構成されてる模様。次のような機能あり。

  • Mouse pointer integration
  • Shared folders
  • Better video support
  • Seamless windows
  • Generic host/guest communication channels
  • Time synchronization
  • Shared clipboard
  • Automated logons (credentials passing)

Better video supportにLinuxのゲストOSのウィンドウサイズを変更できると書いてあった。

In addition, with Windows, Linux and Solaris guests, you can resize the virtual machine's window if the Guest Additions are installed. The video resolution in the guest will be automatically adjusted (as if you had manually entered an arbitrary resolution in the guest's display settings).

Guest Additionsをインストールする

Virtual Boxで仮想マシンを起動する。コンソールのメニューから[Device]-[Insert Guest Additions CD Image…]を選択。ISOイメージがCDドライブにセットされるのでマウント。

[root@cent01 ~]# mkdir /mnt/cdrom
[root@cent01 ~]# mount /dev/cdrom /mnt/cdrom

ISOの中身は次のような感じ。

[root@cent01 ~]# ls -l /mnt/cdrom
合計 52136
dr-xr-xr-x. 2 root root      480 1123 01:30 32Bit
dr-xr-xr-x. 2 root root      480 1123 01:30 64Bit
-r--r--r--. 1 root root      763 1029 00:31 AUTORUN.INF
dr-xr-xr-x. 2 root root     2508 1123 01:30 OS2
-r--r--r--. 1 root root      449 1123 01:30 TRANS.TBL
-r-xr-xr-x. 1 root root  7771583 1123 01:24 VBoxLinuxAdditions.run
-r--r--r--. 1 root root 17794048 1123 01:25 VBoxSolarisAdditions.pkg
-r-xr-xr-x. 1 root root 17000072 1123 01:29 VBoxWindowsAdditions-amd64.exe
-r-xr-xr-x. 1 root root 10533552 1123 01:25 VBoxWindowsAdditions-x86.exe
-r-xr-xr-x. 1 root root   268504 1123 01:23 VBoxWindowsAdditions.exe
-r-xr-xr-x. 1 root root     6384 1029 00:31 autorun.sh
dr-xr-xr-x. 2 root root      950 1123 01:30 cert
-r-xr-xr-x. 1 root root     4821 1029 00:31 runasroot.sh

次にVBoxLinuxAdditions.runを実行するが、bzip2、gcc、kernel-devがないと怒られる。

[root@cent01 ~]# sh /mnt/cdrom/VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.2 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
./install.sh: 行 371: bzip2: コマンドが見つかりません
tar: これは tar アーカイブではないようです
tar: 前のエラーにより失敗ステータスで終了します
./install.sh: 行 384: bzip2: コマンドが見つかりません
tar: これは tar アーカイブではないようです
tar: 前のエラーにより失敗ステータスで終了します
[root@cent01 ~]# sh /mnt/cdrom/VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.2 Guest Additions for Linux........
VirtualBox Guest Additions installer
This system appears to have a version of the VirtualBox Guest Additions
already installed.  If it is part of the operating system and kept up-to-date,
there is most likely no need to replace it.  If it is not up-to-date, you
should get a notification when you start the system.  If you wish to replace
it with this version, please do not continue with this installation now, but
instead remove the current version first, following the instructions for the
operating system.

If your system simply has the remains of a version of the Additions you could
not remove you should probably continue now, and these will be removed during
installation.

Do you wish to continue? [yes or no]
yes
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-693.el7.x86_64
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
    kernel-devel kernel-devel-3.10.0-693.el7.x86_64

なので必ずbzip2、gcc、kernel-devをインストールすること。kernel-devはバージョンまで指定しないとだめ。

[root@cent01 ~]# yum install bzip2
[root@cent01 ~]# yum install gcc
[root@cent01 ~]# yum install kernel-devel-3.10.0-693.el7.x86_64

これでやっとGuest Additionsをインストールできる。

[root@cent01 ~]# sh /mnt/cdrom/VBoxLinuxAdditions.run 
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.2 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 5.2.2 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
VirtualBox Guest Additions: Starting.

GRUB2の解像度を設定する。

GRUB2の設定ファイル/etc/default/grubを修正する。起動時のカーネルオプションに解像度の指定を追加する。カーネルオプションの意味は改めて調べよう。

GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet vga=771"

vgaのパラメータで「サイズ」「色数」を指定する。参考サイトの英語Wikipediaに説明あり。

手動設定を反映させて、再起動して終わり。

[root@cent01 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg 
[root@cent01 ~]# shutdown -r now

参考にしたサイト

VirtualBox 上に構築した CentOS の解像度を変える方法 Guest Additionsのインストール Chapter 4. Guest Additions