---
slug: "raspberry-pi-pico-rp2040-mac-os-sonoma-copy-input-output-error"
title: "Raspberry PI Pico や RP2040 に Mac OS Sonoma でファイルをコピーすると Input/output error になる場合"
description: "Mac OS Sononoma で、Rasberry PI Pico や RP2040 を載せてるマイコンボードの開発をしようとして、\nファイルを RP2040 にコピーした時に、Input/output error や Error code -36 となる場合の解消方法です。"
url: "https://www.ytyng.com/blog/raspberry-pi-pico-rp2040-mac-os-sonoma-copy-input-output-error"
publish_date: "2023-11-21T02:51:56Z"
created: "2023-11-21T02:51:56Z"
updated: "2026-02-27T02:28:22.450Z"
categories: ["Python", "Raspberry-Pi"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250615/da9db4a85b794f2684642edf4fe5a3af.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/296/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/296/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/296/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/296/featured-music-296-2.mp3", "https://media.ytyng.net/ytyng-blog/296/featured-music-296-3.mp3"]
lang: "ja"
---

# Raspberry PI Pico や RP2040 に Mac OS Sonoma でファイルをコピーすると Input/output error になる場合

# 問題
Mac OS Sononoma で、 Rasberry PI Pico や RP2040 を載せてるマイコンボードの開発をしようとして、
ファイルを RP2040 にコピーした時に、

```
cp: code.py: could not copy extended attributes to /Volumes/CIRCUITPY/code.py: Input/output error
```
となって 0バイトでコピーされる。(中身がコピーされていない)

また、Finder でドラッグアンドドロップした場合は

```
The Finder can’t complete the operation because some data in “” can’t be read or written.
(Error code -36)
```

のエラーダイアログが表示される。

![画像](https://media.ytyng.com/20231120/8d15e80161bc4c3d87b1c48be6f19188.png)


# 解決方法
ボリュームを synchronous でマウントしなおせば良い。

以下のスクリプトでマウントしなおしができる

```shell
#!/usr/bin/env zsh

m=$(mount | grep /Volumes/CIRCUITPY | grep synchronous)

if [ ! "$m" ]; then
  devname=$(df | grep CIRCUITPY | cut -d" " -f1)
  sudo umount /Volumes/CIRCUITPY
  sudo mkdir /Volumes/CIRCUITPY
  sleep 2
  sudo mount -v -o sync -t msdos $devname /Volumes/CIRCUITPY
fi
```

# 参考情報

[OSError: [Errno 5] Input/output: macOS Sonoma is delaying writes on small filesystems · Issue #8449 · adafruit/circuitpython](https://github.com/adafruit/circuitpython/issues/8449)

# 原因
Sonoma では、ファイルのコピーをする際、まず仮想ファイルを作って、ファイルシステムへのページアウトがトリガーされる。
非同期でマウントされている場合、FAT とメタデータへの更新はフラッシュされるまで遅延されるため、0バイトファイルとなる。

8MB以下、FAT16、uf2、Python ファイルの書き込み の条件下で問題となる。

https://github.com/adafruit/circuitpython/issues/8449#issuecomment-1745372269


# 私の解決策

下記のようなデプロイスクリプトを作りました。

## remount.sh

```shell
#!/usr/bin/env zsh

ret=$(mount | grep /Volumes/CIRCUITPY | grep synchronous)

if [ ! "$ret" ]; then
  devname=$(df | grep CIRCUITPY | cut -d" " -f1)
  sudo umount /Volumes/CIRCUITPY
  sudo mkdir /Volumes/CIRCUITPY
  sleep 2
  sudo mount -v -o sync -t msdos $devname /Volumes/CIRCUITPY
fi
```


## deploy.sh
```shell
#!/usr/bin/env zsh

cd $(dirname $0)

# Sonoma以降、ファイルのコピーで Input/output error になる問題の対応
./remount.sh

files=(
  file_1.py
  file_2.py
)

for file in $files; do
  echo $file
  cp $file /Volumes/CIRCUITPY/
done

# ゴミファイルを消す
dot_clean /Volumes/CIRCUITPY
ls -lhatr /Volumes/CIRCUITPY
```
