포고플러그에 데비안을 설치하는 것은 uboot 설치/설정이 곤란할 뿐 이외에는 특이한 점이 하나도 없다. Uboot 종류에 따라 다르겠지만, bodhi표 Oxnas용 uboot은 SATA, USB2.0 부팅을 지원하는데, 이 중 하나를 골라서 debian rootfs를 풀어주기만 하면 된다.


1. Debian rootfs 파일 준비

Debian rootfs는 아래 링크에서 받을 수 있고, bodhi Oxnas용 uboot 최신판(2015.10) 기준으로 아래 주의사항만 지켜서 부팅 디스크에 압축을 풀어주면 된다.

Debian rootfs 다운로드: Linux Kernel 4.4.79 Oxnas (OX820) Pogo V3 package and Debian rootfs
rootfs와 kernel을 꾸준히 업데이트 하고 있는데, 설치에 필요한 것은 rootfs이며, 일단 여기에 집중. 2017.08.02에 올라온 Debian-4.4.54-oxnas-tld-1-rootfs-bodhi.tar.bz2 부터 Debian 9 (Stretch)로 업데이트 되었다.

- rootfs 설치는 linux를 사용하며, root로 로그인해야 한다. sudo command로 만들면 안된다고 하는데, sudo -s 로 root shell로 전환해서 진행하는 것은 가능하더라.

참고로 Oxnas SOC의 CPU인 ARM11 MPCore은 내부적으로 버그가 있어서, 최신 버전 커널의 경우 아직 이에 대응한 패치가 완료되지 않은 듯 하다. 따라서 4.4.x 커널에 보안패치만 꾸준히 적용해서 배포하고 있다고..


2. fdisk로 파티션 만들기

배포 페이지의 설명에는 전체 디스크를 하나의 파티션으로 만들어야 하고, 파일 시스템은 EXT3 또는 EXT4, 디스크 라벨은 rootfs로 만들라고 되어 있다. Swap 파티션을 만들 수 없다는 이야기.. 정말일까 싶지만 Swap 파티션을 만들어보지는 않았다. 어차피 Swap이 필요하면 SD나 USB 2.0 보다는 USB 3.0에 만드는 것이 유리하니까.

$ sudo -s                                      (root shell로 전환)
[sudo] password for 일반사용자:
# fdisk /dev/sdb                               (장치명은 사정에 맞춰서 변경)

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): g                        (gpt 파티션 테이블 생성)
Created a new GPT disklabel (GUID: 6CE5410B-C2BB-486F-BDFF-F31269AF63D0).


Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-30031216, default 2048): 엔터 (반드시 기본값으로)
Last sector, +sectors or +size{K,M,G,T,P} (2048-30031216, default 30031216): +30027775
(이건 아래에 별도 설명)


Command (m for help): p
Disk /dev/sdb: 14.3 GiB, 15376000000 bytes, 30031250 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: gpt
Disk identifier: 6CE5410B-C2BB-486F-BDFF-F31269AF63D0

Device     Start      End  Sectors  Size Type
/dev/sdb1   2048 30029823 30027776 14.3G Linux filesystem

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

- gpt 파티션 테이블을 생성했으며, 구버전 uboot을 사용할 경우 dos 파티션을 만들어야한다. g 대신 o 명령으로..

- First sector와 last sector는 플래쉬 메모리의 alignment와 관련된 내용인데, 상세한 설명을 할 수가 없다. 요즘 버전의 fdisk, parted 등 리눅스용 파티션 프로그램은 알아서 alignment를 맞춰주는데, 여기서 핵심이 first sector를 파티션 프로그램이 추천하는 default값으로 넣어주는 것이다.

- Last sector 역시 alignment와 관련된 것인데, 아래와 같이 계산한다. 상기 fdisk 출력정보를 예시로 계산 과정도 함께 기록했으니 비교해보시라.

단계 1: {가용한 끝 sector - (first sector - 1)} / first sector = 계산 결과의 몫 (즉, 정수만 취함)
          { 30031216 - (2048 - 1) } / 2048 = 14662.680176 -> 14662
단계 2: 몫 x fist sector -1 = 결과값에 +를 붙여서 입력
          14662 x 2048 - 1 = 30027775 -> +3002775 입력
엄밀하게는 단계1의 분모와 단계 2의 sector값은 first sector의 번호와 의미가 같지는 않은데, 그냥 숫자값은 서로 일치하므로 그냥 first sector로 썼다.

상기 계산은 전 영역의 alignment를 완전히 맞추면서도, 부팅 디스크의 최대 용량을 박박 긁어서 사용하기 위한 것인데, 실은 좀 오바가 심하다. 아래와 같이 생성한 파티션이랑 고작 26MiB 더 사용할 수 있는 것 치고는 수고가 좀 많이 들어간다. 디스크의 용량이 크면 클수록 그 비율은 더 작아지니 더더욱 의미가 없어진다. 그러나 뭐 재미나잖아. ^^

# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): g
Created a new GPT disklabel (GUID: D9934F1B-C2A8-468C-AB15-0455A898A42E).

Command (m for help): p
Disk /dev/sdb: 14.3 GiB, 15376000000 bytes, 30031250 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: gpt
Disk identifier: D9934F1B-C2A8-468C-AB15-0455A898A42E

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-30031216, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-30031216, default 30031216): +14.3G

Created a new partition 1 of type 'Linux filesystem' and of size 14.3 GiB.

Command (m for help): p
Disk /dev/sdb: 14.3 GiB, 15376000000 bytes, 30031250 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: gpt
Disk identifier: D9934F1B-C2A8-468C-AB15-0455A898A42E

Device     Start      End  Sectors  Size Type
/dev/sdb1   2048 29976575 29974528 14.3G Linux filesystem

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.



3. 파일시스템 만들기 (포멧)

최신 uboot 기준으로 부팅용으로 EXT3, EXT4 파일 시스템을 지원한다. 디스크 라벨은 rootfs

# mkfs.ext4 -L rootfs -j /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
/dev/sdb1 contains a ext2 file system
        last mounted on /mnt/sdcard on Tue Aug  1 00:35:56 2017
Proceed anyway? (y,n)  y
Creating filesystem with 3746816 4k blocks and 938400 inodes
Filesystem UUID: c8bbb117-c716-40a5-8503-cfae9b9322c8
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

-L이 라벨을 지정하는 옵션이다. -j는 저널링 활성화



4. rootfs 전개

별 것 없다. 압축을 풀어주는 과정일 뿐..

# mkdir pogo
# mount /dev/sdb1 pogo
# cd pogo/
# tar -xvjf /압축파일위치/Debian-4.12.1-kirkwood-tld-1-rootfs-bodhi.tar.bz2

넉넉히 기다려준다.



5. etc/fstab 수정

방금 전개한 rootfs의 etc/fstab을 아래와 같이 수정한다. /etc/fstab이 아니다.

LABEL=rootfs    /               ext4    noatime,errors=remount-ro   0   1


이로써 rootfs 준비가 완료되었다. 마운트를 해제하고 부팅 디스크를 포고플러그에 끼운 후 부팅!



6. Debian 부팅 후 해야할 일

root 유저의 기본 비번은 root


- SSH key 재설정

# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

# rm /etc/ssh/ssh_host*
# ssh-keygen -A
ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519


- 부트 이미지 관리

앞으로 apt-get update 시 출력되는 메시지를 유심히 볼 필요가 있다. initramfs가 갱신될 경우 uInitrd 부트 이미지를 다시 만들어주어야 하기 때문이다. initramfs 업데이트 메시지는 아래 형태로 출력된다.

update-initramfs: Generating /boot/initrd.img-x.x.x-oxnas-tld-x


uInitrd 부트 이미지는 아래 명령으로 만들 수 있다.

# cd /boot
# mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initramfs-4.4.79-oxnas-tld-1 -d initrd.img-4.4.79-oxnas-tld-1 uInitrd

빨간색으로 표시된 커널 버전에 유의하자.



7. 참고할만한 Debian 기본 설정

- 리눅스 기본 보안: user 추가, sudoer 등록, root 비활성화, ssh root login 금지

- SSH 보안설정

- vi 에디터 방향키, 백스페이스 고치기

- Debian 고정ip, 호스트네임 설정

- 데비안 리포지토리 변경
  한국 미러로 바꾸면 apt-get update가 빠르다. /etc/apt/sources.list를 수정한다. 아래는 내가 쓰는 sources.list인데, 해외 미러와 소스 리포지토리를 주석으로 처리하고 아래 석줄을 추가해줬다. 하는 김에 백포트도 추가.

참고로 다음카카오 미러는 armel 디스토가 없어서 포고플러그에서 사용할 수 없다.

#deb http://ftp.us.debian.org/debian stretch main
#deb-src http://ftp.us.debian.org/debian stretch main

deb http://security.debian.org/ stretch/updates main contrib non-free
#deb-src  http://security.debian.org/ stretch/updates main contrib non-free

#deb http://http.debian.net/debian stretch-updates main contrib
#deb-src http://http.debian.net/debian stretch-updates main contrib

deb http://ftp.kr.debian.org/debian/ stretch main contrib non-free
deb http://ftp.kr.debian.org/debian/ stretch-backports main contrib non-free
deb http://ftp.kr.debian.org/debian/ stretch-updates main contrib non-free

- /run 파티션 메모리 부족 문제 해결 [현재 논의되고 있는 issue임]

systemd 서비스가 업데이트 될 때 systemctl daemon-reload 가 실행되는데, tmpfs로 마운트 되어있는 /run 의 용량이 부족해서 서비스 갱신을 못하고 서비스가 죽는 현상이 있다.

임시방편 1. apt-get upgrade 시에만 임시로 /run 파티션 용량 늘리기
귀찮은게 큰 단점

# mount -t tmpfs tmpfs /run -o remount,size=32M,nosuid,noexec,relatime,mode=755
# apt-get upgrade
# mount -t tmpfs tmpfs /run -o remount,size=13M,nosuid,noexec,relatime,mode=755

임시방편 2. 애초에 run 파티션 용량을 늘려서 잡는다. 가용램이 줄어드는 안타까움이 있다. 포고플러그는 램 5MB도 아쉽다. 아래 내용을 /etc/fstab에 추가

tmpfs /run tmpfs nosuid,noexec,size=18M,nr_inodes= 4096 0 0