LoginSignup
2
3

More than 3 years have passed since last update.

VirtualBox6.1.16で、CentOS Streamにアップデートした際の共有フォルダのエラー解消について

Posted at

TL;DR

  • VirtualBox6.1.16を使用して、CentOS8 -> CentOS Stream release 8にアップデートした際に、共有フォルダが動作しなかったので、その解消方法を記載します。
  • Guest Additionsのゲスト側のソースを一部修正して対応します。
  • Guest AdditionsのBugなので、VirtualBoxの後続のバージョンで解消すると思われます。

前提

  • VirtualBox6.1.16を使用した、CentOS8が既にある想定です。また共有フォルダを使用している前提です。
  • vagrant2.2.14を使用しています。

手順概要

  • CentOS Stream release 8にアップデート → 再起動時に共有フォルダのエラーに気付く → Guest Additions再インストール(失敗) → ソース修正 → Guest Additions再々インストール(成功) の流れでやっていきます。 ※実際には簡略化可能です
  • 下記手順のコマンド入力は、すべてroot権限想定です。sudoが望ましいですが、記事を書くのはrootが楽なので。。。sudo利用の場合は、適宜読み替え願います。

手順詳細

1. CentOS Stream release 8にアップデート

https://www.centos.org/centos-stream/
より、以下コマンドでアップデートします。

dnf install centos-release-stream
dnf swap centos-{linux,stream}-repos
dnf distro-sync

※dnf distro-syncは、環境によって dnf distro-sync --nobest とかの場合もあり

2. 1.が正常終了した後に、ゲストOS再起動

ゲストOS再起動を行うと、起動時に、以下エラーメッセージが表示される場合があります。
vboxsf が見つからないと言っています。

   (途中省略)
==> default: Mounting shared folders...
    default: /vagrant => C:/XXXXXX/YYYYYY/ZZZZZZ
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o dmode=777,fmode=666,uid=1000,gid=1000 vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

3. Guest Additions再インストール

この手のエラーは、ホスト側とゲスト側でGuest Additionsのバージョン違いで発生することが多く、Guest Additionsを再インストールすることで直ったりしますね。
今回ホスト側は、2020年12月時点で最新のVirtualBoxですので、Guest側を疑います。
CentOS Stream release 8が起動している状態で、Guest Additionsを再インストールします。
以下コマンドで、Guest AdditionsのCDイメージをマウントし、再インストールを実行します。

mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom/
/mnt/cdrom/VBoxLinuxAdditions.run

4. 3.が正常終了した後に、ゲストOS再起動

ゲストOS再起動を行うと、起動時に以下エラーメッセージが表示されます。直ってません。。。

   (途中省略)
==> default: Mounting shared folders...
    default: /vagrant => C:/XXXXXX/YYYYYY/ZZZZZZ
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o dmode=777,fmode=666,uid=1000,gid=1000 vagrant /vagrant

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

ここで、/var/log/vboxadd-setup.logを確認すると、ありました。エラーの箇所が。どうやらvfsmod.cの568行目でエラーとなっているようです。

/var/log/vboxadd-setup.log
(途中省略)
(cat /dev/null;   echo kernel//tmp/vbox.0/vboxsf.ko;) > /tmp/vbox.0/modules.order
  gcc -Wp,-MD,/tmp/vbox.0/.vfsmod.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/8/include -I./arch/x86/include -I./arch/x86/include/generated   -I./include/drm-backport -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -DCC_HAVE_ASM_GOTO -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_AVX512=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -DCONFIG_TPAUSE=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-int-in-bool-context -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -Wdeclaration-after-statement -Wno-pointer-sign -Wno-stringop-truncation -fno-strict-overflow -fno-merge-all-constants -fmerge-constants -fno-stack-check -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -fmacro-prefix-map=./= -Wno-packed-not-aligned -Wno-declaration-after-statement -fno-pie -include /tmp/vbox.0//include/VBox/VBoxGuestMangling.h -fshort-wchar -I./include -I/tmp/vbox.0/ -I/tmp/vbox.0/include -I/tmp/vbox.0/r0drv/linux -D__KERNEL__ -DMODULE -DRT_WITHOUT_PRAGMA_ONCE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DVBOX_WITH_HGCM -DIN_MODULE -DIN_GUEST -DIN_GUEST_R0 -DRT_NO_EXPORT_SYMBOL -DVBOX_WITH_64_BITS_GUESTS -DRT_ARCH_AMD64  -DMODULE  -DKBUILD_BASENAME='"vfsmod"' -DKBUILD_MODNAME='"vboxsf"' -c -o /tmp/vbox.0/.tmp_vfsmod.o /tmp/vbox.0/vfsmod.c
/tmp/vbox.0/vfsmod.c: 関数 ‘vbsf_read_super_aux’ 内:
/tmp/vbox.0/vfsmod.c:568:17: エラー: ‘MS_REMOUNT’ undeclared (first use in this function); did you mean ‘DT_RELCOUNT’?
     if (flags & MS_REMOUNT) {
                 ^~~~~~~~~~
                 DT_RELCOUNT
/tmp/vbox.0/vfsmod.c:568:17: 備考: 未宣言の識別子は出現した各関数内で一回のみ報告されます
make[2]: *** [scripts/Makefile.build:316: /tmp/vbox.0/vfsmod.o] エラー 1
make[1]: *** [Makefile:1545: _module_/tmp/vbox.0] Error 2
make: *** [/tmp/vbox.0/Makefile-footer.gmk:117: vboxsf] Error 2
Could not find the X.Org or XFree86 Window System, skipping.

5. ソースコード修正

詳細は、https://www.virtualbox.org/ticket/20091 にありますとおり、バージョン条件判定誤りです。

vim /opt/VBoxGuestAdditions-6.1.16/src/vboxguest-6.1.16/vboxsf/vfsmod.c

にて、48行目の内容を、

vfsmod.c
#if RTLNX_VER_MIN(5,0,0)

↓ 以下のように修正し保存ます。

vfsmod.c
#if RTLNX_VER_MIN(5,0,0) || RTLNX_RHEL_MIN(8,4)

上記作業完了後、ゲストOS再起動を行います。

6. ゲストOS再起動

3回目のゲストOS再起動です。

   (途中省略)
    default: /vagrant => C:/XXXXXX/YYYYYY/ZZZZZZ
==> default: Detected mount owner ID within mount options. (uid: 1000 guestpath: /vagrant)
==> default: Detected mount group ID within mount options. (gid: 1000 guestpath: /vagrant)

正常に動きました。やったね!:grinning:
ゲストOSにSSHして/vagrant の中身を見てみると、共有フォルダが動作していることが確認できるかと思います。

余談

  • vagrantの出力でエラーに気づき、dmesg,syslogを確認したのちに、/var/log/vboxadd-setup.logでエラー原因の詳細が分かり、Google検索してhttps://www.virtualbox.org/ticket/20091 に辿り着きました。 /var/log/vboxadd-setup.logの内容に気づくまで少し時間を使ったので、その辺りが反省点ですね。
2
3
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
2
3