# Create the virtiofsd directory if it doesn't exist if (not -d $virtiofsd_dir) { print"Creating directory: $virtiofsd_dir\n"; mkdir$virtiofsd_dirordie"Failed to create $virtiofsd_dir: $!"; }
# TODO: Have removal logic. Probably need to glob the systemd directory for matching files. for (@{$associations{$vmid}}) { # my $share_id = $_ =~ s/^\///r =~ s/\//_/gr; my$share_id = $_ =~ m/.*\/([^\/]+)/ ? $1 : ''; # only last folder from path my$unit_name = 'virtiofsd-' . $vmid . '-' . $share_id; my$unit_file = '/etc/systemd/system/' . $unit_name . '@.service'; print"attempting to install unit $unit_name...\n"; if (not -d $virtiofsd_dir) { print"ERROR: $virtiofsd_dir does not exist!\n"; } else { print"DIRECTORY DOES EXIST!\n"; }
qm set <vmid> --hookscript local:snippets/virtiofs_hook.pl
启动虚拟机
qm start <vmid>
虚拟机内挂载
脚本默认会使用 <vmid>-<目录名称> 的组合创建 tag,使用该 tag 即可在虚拟机内完成挂载。
mount -t virtiofs <vmid>-<目录命令> /mnt
例如给 100 虚拟机共享了 /mnt/video 目录,则使用该命令挂载。
mount -t virtiofs 100-video /mnt
Tip
第一次启动挂载的时候会提醒 superblock 错误。
mount: /srv/cephfs-mounts/download: wrong fs type, bad option, bad superblock on mnt_pve_cephfs_multimedia, missing codepage or helper program, or other error. dmesg(1) may have more information after failed mount system call.