結論
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か確認する。
以下のTYPE
がTYPE="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もネットワークも詳しくなくて、けっこう詰まったから備忘録として投稿します。