目次

「OS」一覧に戻る

WSLでGoogleDrvieを利用


WindowsでのWSL2の利用方法



方法1:Windows 側でマウント → WSL から参照

Google Drive for Desktopを使い、GドライブをWSL2 から /mnt/g/ として見る

sudo mount -t drvfs G: /mnt/g

常時マウント

方法1:/etc/fstabで、常時マウント

sudo vi /etc/fstab

## 以下を追加
G: /mnt/g drvfs defaults 0 0
sudo vi /etc/wsl.conf

##以下を追加
[automount]
enabled = true
mountFsTab = true

方法2:automount設定

sudo vi /etc/wsl.conf


###
[automount]
enabled = true
root = /mnt/
options = "metadata"
mountFsTab = true

/mnt/c、/mnt/g が自動マウントされる

方法3:.bashrcで保険

vi ~/.bashrc


if ! mount | grep -q "/mnt/g"; then
  sudo mount -t drvfs G: /mnt/g
fi


方法2:rclone + mount

sudo apt update
sudo apt install -y rclone fuse3
rclone config

n) New remote
name> gdrive
Storage> drive
client_id> (空でOK)
client_secret> (空でOK)
scope> 1 (Full access)
root_folder_id> (空)
service_account_file> (空)
Edit advanced config? n
Use auto config? y
sudo mkdir -p ~/gdrive

## マウント
rclone mount gdrive: ~/gdrive \
  --vfs-cache-mode writes \
  --dir-cache-time 1h \
  --poll-interval 1m \
  --allow-other
## アンマウント
fusermount3 -u ~/gdrive
systemd で常時マウント
sudo vi /etc/wsl.conf

[boot]
systemd=true
wsl --shutdown
sudo vi /etc/systemd/system/rclone-gdrive.service
[Unit]
Description=Rclone Mount Google Drive
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount gdrive: /home/<ユーザー名>/gdrive \
  --vfs-cache-mode writes \
  --allow-other
ExecStop=/bin/fusermount3 -u /home/<ユーザー名>/gdrive
Restart=always
User=<ユーザー名>

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reexec
sudo systemctl enable --now rclone-gdrive


WindowsでのWSL2の利用方法





「OS」一覧に戻る