외장 파일시스템 마운트 후 du 조심
외장 파일시스템 마운트 후 du는 umount를 방해할 수 있으니 주의해야 함.
외장 파일시스템 마운트 후 du 조심해야 함. 3TB NTFS 마운트 후 ls와 du -sh를 같이 돌렸는데, du가 수백만 개 파일 스캔하느라 엄청 느려짐. umount 시도하니 'target is busy' 에러 발생! du가 계속 돌고 있어서 생긴 문제였음.
문제점:
* du는 모든 파일을 탐색, 외장 파일시스템(NTFS/HFS+ via FUSE)에선 각 stat 호출이 비쌈.
* ls와 du를 묶어 쓰면 du의 긴 실행 시간이 가려짐.
해결책:
* 간단 확인:
bash
ls -la /mnt/x
ls /mnt/x | head
* 용량 확인: df -h (즉시 결과) 사용. du는 피하자.
* du 필요 시:
bash
timeout 10 du -sh /mnt/x/subdir
* umount 전:
bash
fuser -vm /mnt/x
lsof +D /mnt/x
위 명령으로 프로세스 확인 후 종료.
여기서 배울 것
- `du`는 외장 파일시스템에서 매우 느릴 수 있으니 주의해야 함.
- `df -h`로 파일시스템 전체 용량 및 사용량을 즉시 확인하는 것이 좋음.
- `timeout` 명령으로 `du` 같은 오래 걸리는 작업의 실행 시간을 제한할 수 있음.
- `fuser`나 `lsof`로 마운트 포인트를 사용 중인 프로세스를 찾아 종료할 수 있음.
원본 파일 보기 (.claude/memory/du_on_foreign_fs_before_unmount.md)
---
name: Don't run du on a freshly mounted foreign filesystem before unmount
description: Running du on a large NTFS/HFS+ mount can take minutes and block the subsequent umount
date: 2026-04-18
tags: [linux, storage, unix]
---
## What happened
To inspect a newly mounted 3TB NTFS disk, ran `ls` and `du -sh /mnt/tmp_check_3tb` in the same command. The `du` began walking an imagenet training dataset (millions of small files over NTFS via ntfs-3g — very slow). When trying to `umount` afterwards, got "target is busy" because `du` was still running in the same pipeline.
## Root cause
`du` traverses every file. On a huge foreign-filesystem mount (NTFS/HFS+ via FUSE) each stat is costly. Bundling `ls` (fast) with `du -sh` (potentially unbounded) into one inspection command hid the cost. The unmount failure was a symptom of the still-running traversal holding an open directory fd.
## Next time
When mounting an unknown disk just to peek at contents:
- Use `ls -la /mnt/x` and `ls /mnt/x | head` to enumerate top-level.
- Skip `du -sh` unless size is actually needed. If needed, use `df -h` (instant, from superblock) not `du`.
- If `du` is required for subdirectory size, time-box it: `timeout 10 du -sh /mnt/x/subdir`.
- Before `umount`, check `fuser -vm /mnt/x` or `lsof +D /mnt/x` and kill any stragglers.