외장 FS 마운트 후 du 조심
외장 파일시스템 마운트 후 du 돌리면 umount 막힘. 조심.
외장 FS 마운트 후 du 조심
3TB NTFS disk 마운트.
ls랑 du -sh /mnt/tmp_check_3tb 같이 돌림.
du가 ImageNet 데이터셋 (수백만 개 파일, NTFS-3G) 훑기 시작. 개느림.
umount 시도하니 "target is busy" 에러. du 아직 돌고 있었음. wtf.
왜 이랬냐면:
du는 모든 파일 traverse 함.
큰 외장 FS (NTFS/HFS+ FUSE)에선 stat 하나하나가 비쌈.
ls (빠름)랑 du -sh (언바운드) 같이 돌려서 문제 숨겨짐.
umount 실패는 du가 디렉토리 fd 잡고 있어서.
다음엔 이렇게: 모르는 디스크 마운트해서 내용만 볼 때:
ls -la /mnt/[마운트포인트]
ls /mnt/[마운트포인트] | head
- 최상위만 확인.
du -sh는 웬만하면 건너뜀. 크기 필요하면df -h(superblock에서 바로 가져옴, 빠름) 쓰지du쓰지 마.du꼭 필요하면timeout걸어.
timeout 10 du -sh /mnt/[마운트포인트]/[하위폴더]
umount 전에 누가 잡고 있는지 확인.
fuser -vm /mnt/[마운트포인트]
lsof +D /mnt/[마운트포인트]
- 잡고 있는 프로세스 있으면 죽임.
여기서 배울 것
- du는 외장 FS에서 느림. 특히 작은 파일 많을 때.
- ls와 du를 한 번에 돌리지 마. du는 예상보다 오래 걸릴 수 있음.
- 크기 확인은 df -h가 빠름. superblock 정보 활용.
- timeout으로 du 시간 제한 걸기. 무한정 기다리지 않음.
- umount 전 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.