Jetson의 저장공간은 늘 부족하다.
뭔가 좀 해보려고 하면 기본적으로 제공되는 emmc의 크기가 아쉽다.
docker로 환경을 구축하고 개발, 배포하는 일은 너무 편하다.
특히 빌드하는데 시간이 오래 걸리는 환경을 배포하는 경우엔 docker image로 만들어 두는게 당연하다.
하지만 docker image도 용량을 차지하지 않는 것은 아니다.
그럼 Jetson emmc version에서 큰 용량의 docker image를 실행하는 것은 불가능한 것인가?
일단은 SD 카드 또는 nvme drive를 써야한다.
SD 카드로 부팅한다.
docker의 저장공간만 sd 카드로 옮긴다.
-> 여기선 2번 방법을 사용하기로 한다.
아래에 나올 장치명이 mmcblk1이 아니라 mmcblk0로 잘못 입력한다면 emmc를 모두 날려버릴 수 있으니 오타 주의
이제 docker 저장위치를 SD card로 옮기기로 하였으니 Jetson과 SD card는 한 몸이 될 준비가 필요하다.
부팅된 jetson에 sd card를 삽입한 뒤 확인해야 할 것들.
장치 파일 확인.
$ ls /dev/mmcblk1
/dev/mmcblk1
마운트 되었는 지 여부 확인.
$ mount | grep mmcblk1
아무것도 안보이면 3번으로...
뭔가 보이면 umount 해야함.
$ mount | grep mmcblk1
/dev/mmcblk1p1 on /media type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
$ umount /dev/mmcblk1p1
파티션 설정
$ sudo fdisk /dev/mmcblk1
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
Command (m for help): p
Disk /dev/mmcblk1: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 2048 2000000 1997953 975.6M 83 Linux
/dev/mmcblk1p2 2000896 62333951 60333056 28.8G 83 Linux
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 has been deleted.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): d
No partition is defined yet!
Could not delete partition 366771676161
Command (m for help):
Command (m for help): p
Disk /dev/mmcblk1: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-62333951, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-62333951, default 62333951):
Created a new partition 1 of type 'Linux' and of size 29.7 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
make ext4 filesystem
$ sudo mkfs.ext4 /dev/mmcblk1p1
[sudo] password for nvidia:
mke2fs 1.44.1 (24-Mar-2018)
Discarding device blocks: done
Creating filesystem with 7791488 4k blocks and 1949696 inodes
Filesystem UUID: e3f17439-5c06-4068-8f32-b739a3dc6f58
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
sd card에 ext4 format까지 되었으면 이제 sd card를 재부팅해도 마운트 하기 위해 fstab을 수정한다.
sudo vim /etc/fstab으로 열어서
맨 아래 /dev/mmcblk1p1 으로 시작하는 줄 추가
# /etc/fstab: static file system information.
#
# These are the filesystems that are always mounted on boot, you can
# override any of these by copying the appropriate line from this file into
# /etc/fstab and tweaking it as you see fit. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/root / ext4 defaults 0 1
/dev/mmcblk1p1 /mnt/mmcblk1p1 ext4 defaults 0 1
mount
$ sudo mount -a
# 아래 명령으로 마운트 여부 확인
$ mount | grep mmcblk1
/dev/mmcblk1p1 on /mnt/mmcblk1p1 type ext4 (rw,relatime,data=ordered)
이제 저장 장치 쪽은 준비가 완료 됐다.
nvidia에서 제공하는 rootfs에는 docker의 버전이 오래되어 업그레이드가 필요하다.
docker release note
20.10.17(2022. 07. 기준 최신 버전)
$ docker --version
Docker version 20.10.7, build 20.10.7-0ubuntu5~18.04.3
# 20.10.7은 docker-compose가 내장되어 있지 않은 옛날 버전
install docker
위 링크를 참조했음.
add usermod
$ sudo usermod -aG docker $USER
$ su $USER
uninstall old version
$ sudo apt-get remove -y docker docker-engine docker.io containerd runc
setup repository
$ sudo apt-get update
$ sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
install docker engine
$ sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
check docker version
$ docker --version
Docker version 20.10.17, build 100c701
docker runtime이 사용하는 공간을 sd card로 모두 옮긴다.
$ sudo systemctl stop docker.socket docker.service
$ sudo mkdir -p /mnt/mmcblk1p1/var/lib/
$ sudo mv /var/lib/docker /mnt/mmcblk1p1/var/lib/
$ sudo ln -s /mnt/mmcblk1p1/var/lib/docker /var/lib/docker
$ sudo systemctl start docker.socket docker.service
이제 모든 docker 와 관련된 저장 공간은 sd card로 옮겨졌다.
사용중인 용량 확인
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p1 14G 6.0G 7.1G 46% /
none 1.7G 0 1.7G 0% /dev
tmpfs 2.0G 40K 2.0G 1% /dev/shm
tmpfs 2.0G 21M 2.0G 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mmcblk1p1 30G 45M 28G 1% /mnt/mmcblk1p1
tmpfs 396M 108K 396M 1% /run/user/1000
docker pull redis
$ docker pull redis
Using default tag: latest
latest: Pulling from library/redis
60197a4c18d4: Pull complete
649d52ef4fd9: Pull complete
15708d2d5b0f: Pull complete
7563f50a936f: Pull complete
9f69cdd1652c: Pull complete
33cf3eea7301: Pull complete
Digest: sha256:5af4e5835cee995c3350b9bf4dc7062662e56ea007ce2ab5e5b4e36d5464ada6
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
용량 재확인
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mmcblk0p1 14G 6.0G 7.1G 46% /
none 1.7G 0 1.7G 0% /dev
tmpfs 2.0G 40K 2.0G 1% /dev/shm
tmpfs 2.0G 21M 2.0G 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mmcblk1p1 30G 163M 28G 1% /mnt/mmcblk1p1
tmpfs 396M 108K 396M 1% /run/user/1000