0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【exFAT】RaspberryPiに接続したHDDの権限を変更できない場合の対処法

Last updated at Posted at 2025-01-11

結論

exFATでフォーマットしたHDDをRaspberryPiに接続した場合、chmodで権限を変更できない。
その場合、マウント時に所有者をユーザに設定すれば、権限が付与できる。

背景

RaspberryPiとHDDを使って自宅ファイルサーバを立てたが、ファイルが書き込めなかった。
ファイルサーバとして運用を始める前に、最初のデータをWindowsPCやmacPCからHDDに移動しておきたかったため、フォーマットをexFATにしていた。

# chmodでパーミッションを変更しようとしても何も変わらない(エラーは出力されない)
$ sudo chmod g+w /mnt/hdd

# chownで所有者を変更しようとすると、何かエラーが出てくる
$ sudo chown -R pi:pi /mnt/hdd
chown: changing ownership of '/mnt/hdd/System Volume Information/WPSettings.dat': Operation not permitted
chown: changing ownership of '/mnt/hdd/System Volume Information/IndexerVolumeGuid': Operation not permitted
chown: changing ownership of '/mnt/hdd/System Volume Information': Operation not permitted
chown: changing ownership of '/mnt/hdd': Operation not permittedsudo chown -R pi:pi /mnt/hdd
chown: changing ownership of '/mnt/hdd/System Volume Information/WPSettings.dat': Operation not permitted
chown: changing ownership of '/mnt/hdd/System Volume Information/IndexerVolumeGuid': Operation not permitted
chown: changing ownership of '/mnt/hdd/System Volume Information': Operation not permitted
chown: changing ownership of '/mnt/hdd': Operation not permitted

環境

RasberryPi:3B
OS:Raspberry Pi OS(64bit)
HDD:WESTERN DIGITAL WD80EAAZ-AJP 8TB

原因

RaspberryPiにexFAT形式のHDDを接続した際、デフォルトではrootユーザーのみがアクセス可能で、一般ユーザがアクセスできない。
理由として、exFATがchmodなどのUNIX系システムのパーミッション変更方法に対応していないかららしい。

解決方法

マウント時にHDDのディレクトリの所有者をユーザに設定すれば解決する。
一回はマウントできているが、パーミッションだけ変更できなかったという前提で進めていきます。

HDDのフォーマット確認

とりあえず本当にexFATか確認する。
以下のTYPETYPE="exfat"であることを確認する。

$ sudo blkid
/dev/sda2: LABEL="MyHDD" UUID="XXXX-XXXX" TYPE="exfat" PARTUUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

exFAT用のライブラリをインストール

$ sudo apt update
$ sudo apt install exfat-fuse -y

一度HDDをアンマウント

所有者を変更するには、マウントしなおす必要がある。

# mnt/hddにマウントしている場合。各自変えてください。
$ sudo umount /mnt/hdd

HDDに所有者の設定

piユーザがアクセスできるように設定する。

$ sudo mount -t exfat /dev/sda2 /mnt/hdd -o uid=pi,gid=pi,umask=0022

uid=pi:所有者を pi ユーザーに設定。
gid=pi:グループを pi グループに設定。
umask=0022:パーミッションを設定(所有者に読み書き、他は読み取り)。

まとめ

以上の手順で、exFAT形式のHDDをRaspberryPiのpiユーザがアクセスできるようになる。
sambaもネットワークも詳しくなくて、けっこう詰まったから備忘録として投稿します。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?