루프 디바이스
리눅스의 많은 시스템의 정보, 혹은 디바이스 등은 파일로의 연동이 되어 있다. 이를테면 /dev
아래엔 실제 컴퓨터에 연결된 하드웨어들이 파일로 연결되어 있는 것을 확인할 수 있다. 프로세스(/proc
)의 정보 또한 마찬가지로 파일로 되어 있다. 이는 실제 어떤 자원을 파일로서 논리화한 것인데, 그렇다면 파일을 어떤 장치로 논리화할 수는 없을까?
루프 디바이스의 간략한 설명
man loop
로 man페이지를 확인하면 다음과 같은 문구를 확인할 수 있다.
The loop device is a block device that maps its data blocks not to a physical device such as a hard disk or optical disk drive, but to the blocks of a regular file in a filesystem or to another block device. This can be useful for example to provide a block device for a filesystem image stored in a file, so that it can be mounted with the mount(8) command….
그러니까 간단히 이야기하면 루프 디바이스는 블록 디바이스이긴 한데 이게 디스크 등의 실제 장치는 아니고, 파일시스템 안의 파일과 다른 블록 스토리지의 맵핑을 위해 사용한다는 정도로 이해해 두면 되겠다. 이름이 왜 loop
인가 하면 리눅스에서의 실제 파일 개념이 한번 더 돌아왔기 때문이다. 장치가 파일로 변환되었는데, 파일이 다시 장치로 변환된 그런 느낌으로다가 이해하면 될 것 같다.
시스템에서 사용중인 루프 디바이스
명령어 losetup
을 사용하면 현재 시스템에서 어떤 루프 디바이스가 사용중인지를 알 수 있다.
$ losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop1 0 0 1 1 /var/lib/snapd/snaps/core_6673.snap 0 512
/dev/loop2 0 0 1 1 /var/lib/snapd/snaps/core_6405.snap 0 512
/dev/loop0 0 0 1 1 /var/lib/snapd/snaps/core_6531.snap 0 512
/dev/loop3 0 0 1 1 /var/lib/snapd/snaps/fceux-gui_3.snap 0 512
시스템에서는 루프 디바이스 4개를 사용중이다. BACK-FILE, device backing file이 가리키는 파일을 한번 확인해 보자.
$ ls -la /var/lib/snapd/snaps/
합계 333344
drwxr-xr-x 3 root root 4096 3월 29 05:02 .
drwxr-xr-x 19 root root 4096 4월 26 14:52 ..
-rw------- 2 root root 95416320 3월 6 18:20 core_6405.snap
-rw------- 1 root root 95522816 3월 13 04:58 core_6531.snap
-rw------- 1 root root 93581312 3월 29 05:02 core_6673.snap
-rw------- 2 root root 56795136 3월 6 18:21 fceux-gui_3.snap
drwxr-xr-x 2 root root 4096 12월 1 2017 partial
그리고 루프백의 결과로 생긴 블록 디바이스는 fdisk를 통해서 또 확인할 수 있다.
$ sudo fdisk -l
Disk /dev/loop0: 91.1 MiB, 95522816 bytes, 186568 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
Disk /dev/loop1: 89.3 MiB, 93581312 bytes, 182776 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
Disk /dev/loop2: 91 MiB, 95416320 bytes, 186360 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
Disk /dev/loop3: 54.2 MiB, 56795136 bytes, 110928 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
...
링크
- blog: dd를 이용한 디스크 백업하기
- wiki: 파일 마운트