unison 사용 (feat. gemini)

Unison은 로컬 디렉토리와 다른 로컬 디렉토리, 또는 로컬 디렉토리와 원격 디렉토리 간에 파일을 양방향으로 동기화하는 데 사용되는 강력한 도구이다.

  • rsync가 단방향 동기화에 강점이 있다면,
  • Unison은 양쪽의 변경 사항을 모두 감지하여
  • 충돌을 해결하고 일관성을 유지하는 데 특화되어 있다.

Unison을 사용하는 방법은 크게 CLI(명령줄 인터페이스) 방식과 GUI(그래픽 사용자 인터페이스) 방식이 있다.


Unison 설치

대부분의 리눅스 배포판에서 패키지 관리자를 통해 Unison을 설치할 수 있다.

  • Ubuntu/Debian:

    1
    2
    sudo apt update
    sudo apt install unison unison-gtk
    • unison-gtk는 GUI 버전
  • Fedora/CentOS/RHEL:

    1
    sudo dnf install unison unison-gui
    • unison-gui는 GUI 버전
  • macOS (Homebrew):

    1
    brew install unison
    • macos에서 GUI 버전은 따로 설치 할 수 있다 (예: brew install --cask unison).
  • Windows:

    • Unison 공식 웹사이트에서 설치 파일을 다운로드하여 설치할 수 있다. 일반적으로 unison.exeunison-gtk.exe 파일이 제공된다.

Unison 사용 시 고려사항 및 팁:

중요: 동기화하려는 양쪽 시스템(로컬 및 원격)에 동일한 버전의 Unison이 설치되어 있어야 한다. 버전이 다르면 오류가 발생할 수 있다.

  • 동일한 버전: 동기화하려는 양쪽 시스템의 Unison 버전이 반드시 같아야 한다.
  • SSH 키 인증: 원격 동기화 시 매번 비밀번호를 입력하는 번거로움을 줄이려면 SSH 키 기반 인증을 설정하는 것이 좋다.
  • 충돌 관리: Unison은 파일 내용이 양쪽에서 동시에 변경될 때 “충돌(conflict)”을 감지되고 이 경우 사용자가 수동으로 어떤 버전을 유지할지 결정해야 한다. --prefer 옵션을 사용하면 충돌 시 특정 방향을 자동으로 선호할 수 있지만, 데이터 손실 위험이 있으므로 주의해야 한다.
  • 백업: 중요한 데이터를 동기화하기 전에 항상 백업을 해두는 것이 좋다.
  • ~/.unison 디렉토리: Unison은 이 디렉토리에 동기화 상태, 프로필 파일, 로그 등을 저장한다. 문제가 발생하면 이 디렉토리의 내용을 확인하거나 삭제하여 초기화할 수 있다.
  • 성능: 대량의 파일을 처음 동기화할 때는 시간이 오래 걸릴 수 있지만, 이후에는 변경된 부분만 동기화하므로 빠르게 처리된다.

CLI (명령줄 인터페이스)로 Unison 사용하기

CLI 방식은 스크립트 작성이나 자동화에 유용합니다.

기본 사용법:

명령 형식:

unison 명령으로 특정 폴더를 지정해 동기화 할 수 있다.

1
unison [옵션] [root1] [root2]

또는 Unison은 “프로필”이라는 개념을 사용하여 동기화 설정을 저장하고 관리한다. 프로필을 사용하면 복잡한 옵션을 매번 입력할 필요 없이 간단하게 동기화를 실행할 수 있다.

1
unison [프로필_이름] [옵션]

예시 1: 로컬 디렉토리 간 동기화

두 개의 로컬 디렉토리 ~/dir1~/dir2를 동기화한다고 가정해 보자.

  1. 첫 번째 동기화 (프로필 생성):

    1
    unison ~/dir1 ~/dir2

    이 명령을 처음 실행하면 Unison은 두 디렉토리를 비교하고 어떤 파일이 어디에 있는지, 어떤 변경 사항이 있는지 알려줍니다. 그리고 “Save this configuration as default for roots?”와 같은 질문을 할 것입니다. y를 입력하여 프로필을 저장하는 것이 좋습니다. 기본 프로필 이름은 default가 됩니다.

  2. 질문 및 응답:

    • Unison은 각 파일에 대해 어떤 작업을 수행할지 묻습니다 (->는 왼쪽에서 오른쪽으로, <-는 오른쪽에서 왼쪽으로, ==는 동일함, ?는 충돌).
    • 대부분의 경우 y를 입력하여 제안된 작업을 수락하거나, n을 입력하여 건너뛸 수 있습니다.
    • 충돌이 발생하면 Unison은 어떤 버전을 유지할지 선택하라고 묻습니다.
  3. 이후 동기화 (프로필 사용):

    1
    unison default

    또는 단순히:

    1
    unison

    (default 프로필이 있다면 자동으로 로드됩니다.)
    Unison은 이전 동기화 이후의 변경 사항만 감지하여 빠르고 효율적으로 동기화합니다.

예시 2: 로컬과 원격 디렉토리 간 동기화 (SSH 사용)

로컬 ~/local_dir과 원격 서버 user@remote_host:/remote_dir를 동기화한다고 가정해 봅시다.

  1. 첫 번째 동기화 (프로필 생성):

    1
    unison ~/local_dir ssh://user@remote_host//remote_dir
    • ssh://user@remote_host/: 원격 호스트에 SSH로 연결하겠다는 의미입니다.
    • //remote_dir: 원격 경로입니다. /가 두 개입니다. 이는 원격 루트 디렉토리부터의 절대 경로임을 나타냅니다.
  2. SSH 비밀번호 입력: SSH 연결을 위해 비밀번호를 입력하라는 메시지가 나타날 수 있습니다. SSH 키 기반 인증을 설정해두면 편리합니다.

  3. 질문 및 응답: 로컬 동기화와 마찬가지로 Unison이 각 파일에 대해 묻습니다.

  4. 이후 동기화:
    default 프로필로 저장했다면:

    1
    unison

중요한 옵션:

  • -batch 또는 -auto: 충돌이 없으면 사용자 입력 없이 자동으로 동기화를 진행합니다. 스크립트에서 유용합니다.
  • -auto -force [root]: 특정 루트(예: root1)의 파일을 다른 루트에 강제로 덮어씌웁니다. 충돌 시 유용할 수 있지만, 주의해서 사용해야 합니다.
  • -ignore [패턴]: 특정 파일이나 디렉토리를 동기화에서 제외합니다. (예: -ignore "Thumbs.db" 또는 -ignore "*/.git/*")
  • -prefer [root]: 충돌이 발생했을 때 특정 루트의 버전을 선호합니다. (예: -prefer newer는 더 최근에 수정된 파일을 선호).
  • -silent: 터미널 출력을 최소화합니다.
  • -perms 0: 파일 권한 동기화를 비활성화합니다. (Windows와 Linux/macOS 간 동기화 시 유용)
  • -times: 파일 수정 시간을 동기화합니다. (기본적으로 활성화되어 있지만, 명시적으로 지정할 수 있습니다.)

프로필 파일 직접 생성 및 편집

Unison은 프로필을 $HOME/.unison 디렉토리에 .prf 확장자를 가진 파일로 저장합니다. 예를 들어, my_sync.prf라는 프로필을 만들고 싶다면:

1
2
3
4
5
6
7
8
9
10
# ~/.unison/my_sync.prf 파일 내용
root = /home/사용자이름/dir1
root = ssh://user@remote_host//remote_dir

# 예시 옵션
ignore = Path Thumbs.db
ignore = Name *~
ignore = Name *.bak
prefer = newer
batch = true

이렇게 프로필 파일을 만든 후에는 다음과 같이 동기화를 실행할 수 있습니다:

1
unison my_sync

사용

Unison은 두 디렉토리의 내용을 비교하고, 어떤 파일이 어느 쪽에만 있거나 변경되었는지 보여줍니다.

1
unison ~/my_wsl_project /mnt/e/WindowsProjects/MyProject

실해을 하면 “Save this configuration as default for roots?” 와 같은 질문이 나오면 y를 입력하여 프로필을 저장하는 것이 좋습니다. 이렇게 하면 다음부터는 단순히 unison 또는 unison default로 실행할 수 있습니다.

  • 각 파일에 대해 -> (왼쪽에서 오른쪽으로 복사), <- (오른쪽에서 왼쪽으로 복사), ? (충돌) 등의 제안이 표시됩니다. y를 눌러 수락하거나, n을 눌러 건너뛸 수 있습니다.

ssh 사용

Unison 프로필에서 SSH 키 파일을 사용하는 방법은 SSH 클라이언트 설정과 Unison 프로필 설정을 함께 이용하는 것입니다.

Unison이 SSH 키 파일을 자동으로 인식하고 사용하여 원격

로컬에서 원격 서버에 ssh-key 를 생성해 공개키를 ssh 키 공유를 위해 복사한다

1
ssh-keygen -t rsa -b 4096

원격 서버에 로컬 공개키를 복사한다.

1
ssh-copy-id user@remote_host

~/.ssh/config 에 호스트별 키 파일을 지정한다.

~/.ssh/config 파일을 열거나 새로 생성하고 다음 내용을 추가합니다:

1
2
3
4
5
6
Host myremoteserver             # 이 부분은 원하는 별칭 (Alias)
HostName 192.168.1.100 # 원격 서버의 실제 IP 주소 또는 도메인
User remoteuser # 원격 서버에 로그인할 사용자 이름
Port 22 # SSH 포트 (기본은 22, 변경했다면 여기에 입력)
IdentityFile ~/.ssh/id_rsa # 사용할 개인 키 파일의 경로
IdentitiesOnly yes # 명시된 IdentityFile만 사용하도록 강제

unison 프로파일에 ssh host 를 사용해서 설정한다.

1
2
3
4
5
6
7
8
9
10
11
12
# 로컬 디렉토리
root = /home/youruser/local_project

# 원격 WSL2 디렉토리 (myremoteserver는 ~/.ssh/config에 설정한 별칭)
root = ssh://myremoteserver//mnt/e/remote_data

# 선택적 Unison 옵션
batch = true
prefer = newer
ignore = Path .git
ignore = Name Thumbs.db
perms = 0 # Windows 드라이브 동기화 시 권한 문제 방지를 위해 유용

Rsync에서 update, delete 사용

폴더 동기화 하기

여기도 확인.

https://www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories

rsync 로 source 와 local folder 를 동기화 하고자 한다.

이런 상황을 destination 에 동기화해서 적용하는 것이다.

  1. --dry-run : 전송 전에 전송할 목록을 확인한다.

  2. --update : “”

목차

  1. 전체 동기화
  2. local 기준 동기화
  3. checksum 사용



1. 전체 동기화

  1. source 모든 파일
  2. source 새 파일 추가
  3. source 수정한 파일
  4. source 삭제된 파일

source 모든 파일

source 폴더는 다음 같다.

1
2
3
source:~/$ mkdir tst
source:~/$ cd test/
source:~/test$ touch a.txt b.txt
1
2
3
4
5
6
~$ rsync -avzh --dry-run /source/ /local/
receiving incremental file list
./
a.txt
b.txt

동기화를 실행한다.

1
2
3
4
5
6
7
8
~$(3.11.7)qkboo:~$ rsync -avzh --update --delete --e 'ssh -p 2020' qkboo@220.121.133.119:~/Q
kboo/test/ test/
receiving incremental file list
deleting c.txt
./

sent 51 bytes received 96 bytes 294.00 bytes/sec
total size is 0 speedup is 0.00

source 새 파일 추가

qkboo@homebook:~/Qkboo/test$ touch c.txt

source 파일 수정 상황

1
qkboo@homebook:~/Qkboo/test$ vi c.txt

source 폴더에 삭제 발생

1
qkboo@homebook:~/Qkboo/test$ rm c.txt

dry-run 을 실행해 확인하면 --update --delete 를 사용하면 로컬 파일이 삭제 된다.

1
2
3
4
5
6
7
~$ rsync -avzh --dry-run --update --delete --e 'ssh -p 2020' qkboo@220.121.133.119:~/Qkboo/test/ test/
receiving incremental file list
deleting c.txt
./

sent 51 bytes received 96 bytes 294.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)

동기화를 실행한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
~$(3.11.7)qkboo:~$ rsync -avzh --update --delete --e 'ssh -p 2020' qkboo@220.121.133.119:~/Q
kboo/test/ test/
receiving incremental file list
deleting c.txt
./

sent 51 bytes received 96 bytes 294.00 bytes/sec
total size is 0 speedup is 0.00

(3.11.7)qkboo:~$ ll test/
total 8
drwxrwxr-x 2 qkboo qkboo 4096 Jul 20 09:37 ./
drwxr-xr-x 39 qkboo qkboo 4096 Jul 20 09:34 ../
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 a.txt
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 b.txt

로컬에서 작업이 발생하는 경우

rsync 시 source/ 와 source/* 의 결과 차이가 발생한다.

로컬에 새 파일이 생기는 경우

source 와 destination 폴더 동기화 된 상태에서 destination 폴더에 새 파일이 추가된다.

1
2
3
4
5
6
7
(3.11.7)qkboo:~$ touch test/local.txt; ll test/
total 8
drwxrwxr-x 2 qkboo qkboo 4096 Jul 20 09:59 ./
drwxr-xr-x 39 qkboo qkboo 4096 Jul 20 09:34 ../
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 a.txt
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 b.txt
-rw-r--r-- 1 qkboo qkboo 0 Jul 20 09:59 local.txt

source 폴더에 / 구분자만 사용해서 확인해 본다.

dry-run 을 실행해 확인하면 --update --delete 를 사용하면 로컬 파일이 삭제 된다.

1
2
3
4
5
6
7
8
(3.11.7)qkboo:~$ rsync -avzh --update --delete --dry-run --e 'ssh -p 2020' qkboo@220.121.1
33.119:~/Qkboo/test/ test/
receiving incremental file list
deleting local.txt
./

sent 51 bytes received 96 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)

--ignore-existing 도 삭제가 발생한다.

1
2
3
4
5
6
7
~$ rsync -avzh --update --delete --ignore-existing --dry-run --e 'ssh -p 2020' qkboo@220.121.133.119:~/Qkboo/test/ test/
receiving incremental file list
deleting local.txt
./

sent 51 bytes received 96 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)

--update 만 사용하면 로컬에 변경있는 파일은 무시된다.

1
2
3
4
5
6
7
~$ rsync -avzh --update --dry-run --e 'ssh -p 2020' qkboo@220.121.133.119:~/
Qkboo/test/ test/
receiving incremental file list
./

sent 51 bytes received 96 bytes 294.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)

source/* 로 사용하면 --update --delete 를 사용해도 로컬 파일이 무시된다.

1
2
3
4
5
6
7
8
(3.11.7)qkboo:~$ rsync -avzh --update --delete --dry-run --e 'ssh -p 2020' qkboo@220.121.1
33.119:~/Qkboo/test/ test/
receiving incremental file list
deleting local.txt
./

sent 51 bytes received 96 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)

source 와 local 모두 새 파일 생기면

1
source/ $ touch d.txt

source/* 로 사용하면 --update --delete 로 새 파일을 받는다.

1
2
3
4
5
6
(3.11.7)qkboo:~$ rsync -avzh --update --delete --dry-run --e 'ssh -p 2020' qkboo@220.121.133.119:~/Qkboo/test/* test/
receiving incremental file list
d.txt

sent 51 bytes received 96 bytes 294.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)

local 에도 새 파일이 생기면

1
local/ $ touch test/local2.txt

source/* 로 사용하고 --update --delete 로 새 파일을 받고 로컬은 유지된다.

1
2
3
4
5
6
local:~/ $ rsync -avzh --update --delete --dry-run --e 'ssh -p 2020' qkboo@220.121.133.119:~/Qkboo/test/* test/
receiving incremental file list
d.txt

sent 51 bytes received 96 bytes 98.00 bytes/sec
total size is 0 speedup is 0.00 (DRY RUN)
ll test/
1
2
3
4
5
6
7
8
total 8
drwxrwxr-x 2 qkboo qkboo 4096 Jul 20 10:46 ./
drwxr-xr-x 39 qkboo qkboo 4096 Jul 20 09:34 ../
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 a.txt
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 b.txt
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 10:40 d.txt
-rw-r--r-- 1 qkboo qkboo 0 Jul 20 09:59 local.txt
-rw-r--r-- 1 qkboo qkboo 0 Jul 20 10:43 local2.txt

정리

전체 동기화 후 source,local 모두 변경이 발생

  1. local 기준으로 동기화 하려면 srouce/* 를 꼭 사용한다.
  2. 혹은 local 기준으로 동기화시 --update 만 사용한다.

source 기준으로 동기화 하려면

  1. source 기준으로 동기화 하려면 srouce/ 로 사용한다.


---

[참고] source 와 local 의 같은 파일 동시 수정되면?

양쪽 모두 파일 내용의 갱신이 발생하는 이런 경우는 가능하면 VCS 도구를 사용하자!!!

다음 같이 동기화 한 상태에서 a.txt 를 source 와 local 에서 모두 수정한다면?

ll test/
1
2
3
4
5
6
7
8
total 8
drwxrwxr-x 2 qkboo qkboo 4096 Jul 20 10:46 ./
drwxr-xr-x 39 qkboo qkboo 4096 Jul 20 09:34 ../
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 a.txt
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 09:16 b.txt
-rw-rw-r-- 1 qkboo qkboo 0 Jul 20 10:40 d.txt
-rw-r--r-- 1 qkboo qkboo 0 Jul 20 09:59 local.txt
-rw-r--r-- 1 qkboo qkboo 0 Jul 20 10:43 local2.txt

source/a.txt 에는 ‘AAA’ 문자열이 추가했고, local/a.txt 는 ‘local’ 단어로 변경했다.

단, 다음 같이 비슷한 시간대에 수정한 양쪽의 파일에는 변화가 없다.

source 의 a.txt 파일

1
2
3
$ ls -l a.txt
total 4
-rw-rw-r-- 1 qkboo qkboo 4 Jul 20 10:49 a.txt

local 의 a.txt 파일

1
2
$ ls -l a.txt
-rw-rw-r-- 1 qkboo qkboo 6 Jul 20 10:49 a.txt

변화가 없다.

1
2
3
4
5
~$ rsync -avzh --update --delete --dry-run --e 'ssh -p 2020' qkboo@220.121.133.119:~/Qkboo/test/* test/
receiving incremental file list

sent 44 bytes received 98 bytes 94.67 bytes/sec
total size is 4 speedup is 0.03 (DRY RUN)

시간과 Byte 변화가 있으면 다음 같이 갱신을 수행한다.

1
2
3
4
5
6
7
~$
local:~$ rsync -avzh --update --delete --dry-run source/test/* local/test/
receiving incremental file list
a.txt

sent 51 bytes received 100 bytes 302.00 bytes/sec
total size is 228 speedup is 1.51 (DRY RUN)

source/a.txt 에 Byte 변화가 좀 커지면 동기화가 수행된다.

qkboo@homebook:~/Qkboo/test$ ls -l a.txt
-rw-rw-r– 1 qkboo qkboo 16 Jul 20 10:56 a.txt

source/a.txt 가 local에 동기화가 되고 로컬은 source/a.txt로 교체된다.

1
2
3
4
5
6
7
~$
(3.11.7)qkboo:~$ rsync -avzh --update --delete --dry-run --e 'ssh -p 2020' qkboo@220.121.133.119:~/Qkboo/test/* test/
receiving incremental file list
a.txt

sent 51 bytes received 100 bytes 100.67 bytes/sec
total size is 16 speedup is 0.11 (DRY RUN)

양쪽 모두 갱신이 발생하는 이런 경우는 가능하면 VCS 도구를 사용하자!!!

3. checksum 사용

1
2
3
~$
local:~$ rsync -avzh --update --delete --checksum --dry-run source/test/* local/test/
receiving incremental file list

Cheat Linux System

Linux 에서 짬짬히 자주 쓰이는 명령을 설정을 정리.

  1. Disk
    • GRUB, fsck, dd
  2. System 설정
  3. rsync

비슷한 문서:

Disk

GRUB 복구

우분투 부트로더인 GRUB가 잘못되어 복구하려면 해당 배포본의 Live CD, Live USb 등으로 부팅해서 ‘Try Ubuntu’ 에서 터미널을 통해 복구 절차를 시작한다.

https://askubuntu.com/questions/88384/how-can-i-repair-grub-how-to-get-ubuntu-back-after-installing-windows

https://help.ubuntu.com/community/Grub2

https://wiki.ubuntu.com/Grub2#Recover

fsck

fsck(for file system consistency check) 명령은 파일 시스템을 조사하여 손상된 파일을 출력해 주며 사용자에게 그것을 복구할 것인지를 질의

fsck 수행은 시스템마다 약간의 차이가 있지만 대부분 다음과 같은 5개 항목에 대하여 검사

  • Blocks and sizes, Pathname, Connectivity, Reference count, Free List

1
$ sudo fsck –t ext2 /dev/hdb

Attempt to repair damaged blocks

1
$ sudo fsck –a

Repair damaged blocks interactively

1
$ sudo fsck -r <drive>

force

Forcing the check

You can also force fsck at boot time by passing fsck.mode=force, as a kernel parameter. This will check every filesystem you have on the machine.

/forcefsck

Create a file called forcefsck:

1
# touch /forcefsck

Now, reboot the system:

1
# reboot

Frce fsck on next boot using shutdown command (may not work on many modern distros)

The -F option force fsck on reboot, login as root and type the following command to reboot and run fsck:

1
# shutdown -rF now

링크

Changing the check frequency

By default, fsck checks a filesystem every 30 boots (counted individually for each partition). To change the frequency of checking, run:

1
$ sudo tune2fs -c 20 /dev/sda1

exFAT

리눅스테어 외부 USB 디스크를 exFAT로 포맷하고 사용한다면, exfat-fuseexfat-utils를 설치해 준다.

1
$ sudo apt install exfat-fuse exfat-utils

그리고 대부분 최신 리눅스 데스크탑은 USB 디스크를 더블클릭하면 자동마운트 해준다.

터미널에서는

1
2
3
$ sudo mkdir /media/my_usb
$ sudo mount -t exfat /dev/sdb1 /media/my_usb
$ sudo umount /dev/sdb1

참조

  1. https://wiki.archlinux.org/index.php/fsck

dd

블록 크기

디스크에 데이터를 쓸려면 디스크의 기본 블록 크기인 512B 보다 큰게 좋다. 또한 쓰기 속도를 증가시키기 위해서 디스크의 물리적 지형에 맞는 크기를 사용하는 것이 좋다. fdisk 같은 유틸리티로 정보를 확인할 수 있고 혹은 sysfs 정보를 확인할 수 있다.

1
2
3
4
5
6
/sys/block/sdX/size
/sys/block/sdX/queue/physical_block_size
/sys/block/sdX/queue/logical_block_size
/sys/block/sdX/sdXY/alignment_offset
/sys/block/sdX/sdXY/start
/sys/block/sdX/sdXY/size

디스크 지우기

dd에 데이터를 쓸려면 디스크의 기본 블록 크기인 512B 보다 커야 한다. 또한 쓰기 속도를 증가시키기 위해서 디스크의 물리적 지형에 맞는 크기를 사용하는 것이 좋다.

1
$ sudo dd bs=8k if=/dev/urandom of=/dev/rdisk2

fdisk 정보로 확인

1
2
3
4
5
6
7
8
9
10
11
$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 59.6 GiB, 64021856256 bytes, 125042688 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: 441CD64A-70D1-4A40-ACA8-05CAB62C5C89

Device Start End Sectors Size Type
/dev/sdb1 2048 8390655 8388608 4G Linux swap
/dev/sdb2 8390656 125042654 116651999 55.6G Linux LVM

fdisk 결과의 Sector size는 전체 용량과 섹터 크기를 계산하면 논릭적인 섹터의 크기를 확인할 수 있다.

1
2
echo $((64021856256/125042688))
512

Sector size (logical/physical): 512 bytes / 512 bytes 에서 물리 크기를 확인할 수 있다.

성능

dd 를 사용해서 1024 바이트를 1000000 블록에 걸쳐 쓰기를 수행한다 - 1GB

1
$ time sudo dd bs=1024 count=1000000 if=/dev/zero of=1GB_file

dd 를 사용해서 1GB 크기 파일을 1024 바이트씩 읽기를 한다.

1
$ time sudo dd bs=1024 if=1GB_file of=/dev/null

Verbose output

Sending an INFO signal to a running dd process makes it print I/O statistics to standard error and then resume copying. In the example below, dd is run in the background to copy 10 million blocks. The kill command makes it output intermediate I/O statistics, and when dd completes normally or is killed by the SIGINT signal, it outputs the final statistics.

1
2
3
4
5
6
7
8
$ dd if=/dev/zero of=/dev/null count=10MB & pid=$!
$ kill -s INFO $pid; wait $pid
3385223+0 records in
3385223+0 records out
1733234176 bytes (1.7 GB) copied, 6.42173 seconds, 270 MB/s
10000000+0 records in
10000000+0 records out
5120000000 bytes (5.1 GB) copied, 18.913 seconds, 271 MB/s

On systems lacking the INFO signal dd responds to the USR1 signal instead, unless the POSIXLY_CORRECT environment variable is set.

You can also try the status=progress option:

1
2
3
4
5
6
[~]$ dd if=/dev/zero of=/dev/null count=10MB status=progress
4708234752 bytes (4.7 GB, 4.4 GiB) copied, 4 s, 1.2 GB/s
10000000+0 records in
10000000+0 records out
5120000000 bytes (5.1 GB, 4.8 GiB) copied, 4.3516 s, 1.2 GB/s
[~]$
참조

System 설정

Time zone

1
$ sudo dpkg-reconfigure tzdata

Keyboard

Capslock과 Control key 교체하기

키맵 이용해서 다음 명령:

1
$setxkbmap -layout us -option ctrl:nocaps
1
2
3
sudo vi /etc/default/keyboard

XKBOPTIONS="ctrl:nocaps"
1
sudo dpkg-reconfigure keyboard-configuration

Terminal Reset

실수로 바이너리 파일을 cat 하거나 하여 글자들이 깨질때.. 터미널 리셋하는 방법

1
2
3
4
5
$ reset
$ tput sgr0
$ setterm -reset
$ setterm -initialize
$ Ctrl + V, Ctrl + O

System Info

1
2
3
cat /etc/os-release     # Raspbian
uname -a
cat /etc/issue

Hardware Info

1
2
3
4
5
6
lscpu
lshw
lspci
lsusb
lsblk // block devices
lspcmcia
1
cat /proc/cpuinfo

BIOS안의 시스템 정보

1
# dmidecode

memory

1
$ free -m

Architecture

1
$cat /etc/issue

Ubuntu 에서

1
$subo lsb_release -a
1
2
$ dpkg --print-architecture      //
armhf
1
2
3
4
5
6
$ uname -a
i686, i386은 32bit, x86_64는 64bit. armv7은 32bit, armv8은 64bit
$ uname -m // machine inf

$ uname -i // hw platform
$ uname -p // processor
1
$ arch // uname -m 과 동일

32bit 64bit 체크

1
$ getconf LONG_BIT // 시스템 구성 질의
1
2
3
4
5
$ file /bin/ls
ELF 32-bit LSB executable, ARM, EABI5 version 1 ..
ARM
arm 7 is 32 bit.
ARMv8-A, October 2011, 64-bit address space and 64-bit arithmetic 지원
1
2
3
4
5
$ uname -m // machine inf
i686 // 32bit
x86_64 // 64bit
armv7l // 32bit
armv8 // 64bit

rsync

http://www.joinc.co.kr/w/Site/Tip/Rsync

rsync -avzh source destination
-a : 심볼릭 링크, 속성, 퍼미션, 소유권 등 보존
-v : 자세한 정보출력
-z : 전송시 압축
-r : 하위디렉토리포함
-e ssh : ssh를 이용한 rsync 동기화
–stats : 결과출력

기본 옵션

1
rsync -av source/ destination/

include와 exclude

이 옵션을 이용해서 대상 파일을 추가하거나 제외 할 수 있다.

1
$ rsync -avz  --exclude 'data' id@192.168.56.101:/home/backups ./

별표(*)도 사용할 수 있다.

1
$ rsync -avz  --exclude '*.cache' id@192.168.56.101:/home/backups ./

증분 백업

수정/변경된 내용만 동기화한다.

rsync -avzh moniwiki/ /tmp/backups/
-h, –human-readable : output numbers in a human-readable format
-u : –update update only (don’t overwrite newer files)
–delete : 서버동기화후 원본에서 파일이 삭제되면 백업에서도 파일을 삭제
–remove-source-files :

1
2
$ rsync -av /home/ /backup/home/ # 원본 증분 백업
$ rsync -av --delete /home/ /backup/home/ #원본 증분 백업, 원본 파일 삭제시 사본에서도 삭제

동기화 옵션

delete 옵션

목적지에 파일이나 디렉토리가 존재할 경우 삭제하고 싶을 때 --delete 옵션을 사용한다.

1
rsync -avz --delete id@192.168.56.101:/home/backups ./

원본 삭제 옵션

--remove-source-files를 이용하면, 전송이 끝난 후 원본파일을 삭제한다.

1
$rsync --remove-source-files -zvh backup.tar /tmp/backups/

ssh 통한 백업

rsync 에는 ssh 를 이용하여 원격서버에 접속하여 동기화를 하는 기능이 있습니다.

1
rsync -azrtv --delete --stats -e "ssh -i /root/.ssh/개인키" 원본서버계정@원본서버주소:원본경로/ /백업경로/

find와 결합

1
find . -type f -mtime -3  | rsync -avz --files-from=- /soucepc /data/backup

faillog

/var/log/faillog 는 계정의 로그인 실폐 횟수 정보를 바이너리 파일로 저장한다. 다음 C struct 구조의 정보가 바이너리로 저장되고 있다:

1
2
3
4
5
6
7
struct    faillog {
short fail_cnt;
short fail_max;
char fail_line[12];
time_t fail_time;
long fail_locktime;
};

직접 읽을 수 없기 때문에 faillog 명령을 사용한다.

1
2
3
4
5
6
$ faillog -u pi        # pi 계정
$ faillog -a
Login Failures Maximum Latest On

root 0 0 01/01/70 00:00:00 +0000
daemon 0 0 01/01/70 00:00:00 +0000

최근 3일의 로그인 실패를 찾으려면 :

1
$ faillog -t 3 -u pi

vnc server

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-14-04

http://www.whatwant.com/840

1
$ sudo apt-get install gnome-panel tightvncserver

첫 실행을 해서 기본 Config 등의 구성을 하도록 하면 되는데, sudo 없이 계정 권한으로 실행하여도 된다. 계정 권한으로 실행을 하면 해당 계정으로 환경 설정을 한다.

1
$ vncserver

실행할 때에 해상도를 미리 정해줘야 한다.

1
$ vncserver -geometry 1024x768

기본 창 관리자 변경

기본 생성된 xstartup 파일에는 내가 원하는 대로 환경 설정이 되어 있지 않다. 가장 먼저 실행된 vnc4server를 종료부터 하고 xstartup 파일을 수정하자.

1
2
3
4
$ vncserver -kill :1
$ cp ~/.vnc/xstartup ~/.vnc/xstartup.old

$ nano ~/.vnc/xstartup