Raspberry Pi_Kor_15.1.3 device의 mount


Published Book on Amazon


All of IOT

Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1

All of IOT

Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사

물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)

최신 라즈베리파이(Raspberry Pi)로 시작하는 사

물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


15.1.3  device mount

 

15.1.3.1    mount 의미

 

Linux 시스템에서는 시스템에서 사용되는 모든 파일이 root (/)를 최상위로 하는 하나의 큰 tree 형태인 파일 계층구조에 소속되도록 되어 있다. 이러한 파일들은 하나의 계층구조에 있는 것처럼 보이지만, 실제로는 여러 가지의 device에 흩어져 있는 것일 수도 있다.

 

디스크에 대해 partition이 만들어지고, format을 통해 partition에 특정 filesystem 유형이 지정되면, 해당 disk device는 자료 처리를 위한 기본적인 준비가 된 상태이다. 하지만 이런 device를 실제로 사용하기 위해서는 이 device file system Linux의 전체 file tree에 연결해야 한다.

 

mount 명령은 device에 있는 file system을 전체의 큰 file tree에서 추가한다. 이와는 반대로 umount 명령은 전체 file tree에 붙어 있는 device file system을 분리한다.    

 

15.1.3.2    mount directory 생성

 

device file system Linux의 전체 file tree에 추가하기 위해서는 먼저 disk device file system을 연결할 directory를 생성해서 mount point를 만들어 주어야 한다.

 

새로 mount되는 device는 통상 "/media" directory 밑에 추가된다. 사용자가 원하면 다른 곳을 사용할 수도 있다. device의 종류에 따라 적절한 이름을 부여하여 directory를 만든다.

 

sudo mkdir   /media/directory


 

15.1.3.3    mount directory에 대한 권한 조정

 

새로 mount 되는 directory에 대해서는 필요하면 권한을 조정해야 한다. "chown" 명령을 사용하면 디렉터리의 소유자를 다른 사용자로 바꿀 수 있다

 

sudo chown R <userid> <directory>

 

"촣게" 명령을 사용하면 그룹에 속한 모든 사용자가 디렉터리를 액세스 할 수 있다.

 

sudo chgrp R <group> <directory>

 

"chmod" 명령을 사용하면 사용자에게 디렉터리에 "읽기", "쓰기", "실행" 권한을 부여할 수 있다. 다음은 소유 그룹에 "쓰기" 권한을 부여한 사례이다.

 

sduo chmod R g+w  <directory>

 

 


 

15.1.3.4    "mount" 명령 - device에 대한 directory 지정

 

Linux disk device에서 실제로 자료를 읽거나 쓸 때는 Linux 파일시스템의 특정 directory를 통하여 처리하는데, disk device file system directory에 지정하는 작업을 "mount"라고 한다

  

[명령 형식]

mount      [ options ]  [ -t type ]  <device>    <file-directory>

 

[명령 개요]

    특정 disk device file system을 시스템의 전체 file system의 특정 directory에 지정한다.

    user 권한    -- super user. 

 

[상세 설명]

"mount" 명령은 kernel에게 지정된 type device에 있는 filesystem을 지정된 directory에 연결하라는 지시를 한다. device filesystem mount되어 있는 동안 device에 지정된 directory는 그 device filesystem에 대해서 root의 역할을 한다.

 

일반적인 disk device에는 "/dev/sda1"와 같이 partition에 해당하는 device file name을 지정하지만, device형태에 따라 다른 방식을 사용할 수도 있다. 보통의 block device에 대해서는 "-L" 이나 "-U" option을 사용하여 partition에 대한 LABEL이나 UUID을 지정하여 원하는 device를 지정할 수도 있다.

 

directory 또는 device 중에서 하나만 지정하면, "mount" 명령은 directory와 일치하는 label name을 가진 device 또는 device label name과 일치하는 directoy가 있는지를 검색하게 되고, 그것이 없으면 "/etc/fstab" 파일에서 필요한 설정이 있는지를 찾아서 처리한다.

                                     

기본적으로 mount device file system Linux 시스템 운영중인 동안만 유효하며, 새로 booting하면 새롭게 mount를 해주어야 한다.

 

[주요 option]

-h, --help

Print a help message.

-l

Add  the  labels in the mount output. Mount must have permission

to read the disk device (e.g. be suid root) for  this  to  work.

One  can  set  such  a  label  for  ext2, ext3 or ext4 using the e2label(8) utility, or for XFS using xfs_admin(8), or for reiserfs using reiserfstune(8).

-a, --all

Mount all filesystems (of the given types) mentioned in fstab.

-L label

Mount the partition that has the specified label.

-U uuid

 

Mount the partition that has the specified uuid. These two options require the file /proc/partitions (present since Linux 2.1.116) to exist.

-t, --types vfstype

The argument following the -t is used to indicate the filesystem type.

-M, --move

Move a subtree to some other place. See above.

-w, --rw

Mount the filesystem read/write. This is the default. A synonym is -o rw.

 

[사용 Example]

여기서는 USB memory를 수동으로 mount하는 작업을 해보도록 할 것이다. 먼저, "mount" 명령에서 mount point로 사용할 directory를 만들 것이다. 다음은 작업을 하기 전에 mount가 되는 위치인 "/medir/pi" directory의 내용을 확인하고, 다시 directory를 만든 다음 내용을 확인해 본 것이다. "/media/pi/ESD" directory 밑에는 아무 자료도 없는 것을 확인할 수 있다.

 

pi@raspberrypi3:~ $ ls -l /media/pi

total 4

drwx------ 2 root root 4096 Jun 13  2016 SETTINGS

pi@raspberrypi ~ $ sudo mkdir /media/pi/ESD

 

pi@raspberrypi3:~ $ ls -l /media/pi

total 8

drwxr-xr-x 2 root root 4096 Jan 28 03:16 ESD

drwx------ 2 root root 4096 Jun 13  2016 SETTINGS

pi@raspberrypi3:~ $ ls -l /media/pi/ESD

total 0

 

 


 

그런 다음 USB memory mount하는 작업을 한다. 다음은 작업을 위해서 "blkid" 명령으로 USB memory에 대한 device 이름을 확인하고, 해당 device에 대하여 "mount" 명령을 실행한 다음, "/media/pi/ESD" directory의 내용을 확인해 본 것이다.

 

pi@raspberrypi3:~ $ lsusb

pi@raspberrypi3:~ $ sudo blkid

/dev/mmcblk0p1: LABEL="RECOVERY" UUID="1715-1C28" TYPE="vfat" PARTUUID="0004fe7f-01"

/dev/mmcblk0p5: LABEL="SETTINGS" UUID="f8476b90-b9a0-4456-91e7-46fece4e553d" TYPE="ext4" PARTUUID="0004fe7f-05"

/dev/mmcblk0p6: SEC_TYPE="msdos" LABEL="boot" UUID="680D-6FDD" TYPE="vfat" PARTUUID="0004fe7f-06"

/dev/mmcblk0p7: LABEL="root0" UUID="4adc68f8-4b6e-41c8-ab14-bef7f71f803a" TYPE="ext4" PARTUUID="0004fe7f-07"

/dev/sda1: LABEL="ESD-USB" UUID="7290-B7A1" TYPE="vfat"

/dev/mmcblk0: PTUUID="0004fe7f" PTTYPE="dos"

pi@raspberrypi3:~ $ sudo mount /dev/sda1 /media/pi/ESD

 

pi@raspberrypi3:~ $ ls -l /media/pi/ESD

total 1624

-rwxr-xr-x 1 root root      43 Mar 31  2015 autorun.inf

drwxr-xr-x 5 root root    4096 Apr 10  2016 boot

-rwxr-xr-x 1 root root  400228 Oct 30  2015 bootmgr

-rwxr-xr-x 1 root root 1147736 Oct 30  2015 bootmgr.efi

drwxr-xr-x 4 root root    4096 Apr 10  2016 efi

-rwxr-xr-x 1 root root   79552 Oct 30  2015 setup.exe

drwxr-xr-x 2 root root    4096 Apr 10  2016 System Volume Information

drwxr-xr-x 6 root root    4096 Apr 10  2016 x64

drwxr-xr-x 6 root root    4096 Apr 10  2016 x86

drwxr-xr-x 3 root root    4096 Jan 26 21:51 Ztool

 

mount 작업이 완료된 이후에 "/media/pi/ESD" directory의 내용을 확인해 보면 USB memry의 자료들이 포함되어 있는 것을 확인할 수 있다. 이렇게 해서 USB memory에 대한 mount 작업이 완료된 것이다.


 

15.1.3.5    자동 mount 설정 

 

mount device file system은 시스템이 운영할 동안만 유효하며, 시스템이 down되면 mount가 해제되므로 새로 booting하면 새롭게 mount를 해주어야 한다.

 

/etc/fstab 파일을 이용하면 booting할 때마다 mount 작업이 자동으로 실행되도록 할 수 있다.

 

"/etc/fstab" 파일은 원래 Linux 운영체제 설치단계에서 root 파일시스템과 시스템에 설치된 다른 파일시스템의 정보를 바탕으로 자동적으로 만들어 진다. 다음은 Raspberry Pi를 설치한 후 "/etc/fstab" 파일의 상태이다.

 

proc            /proc           proc    defaults          0       0

/dev/mmcblk0p5  /boot           vfat    defaults          0       2

/dev/mmcblk0p6  /               ext4    defaults,noatime  0       1

# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that

 

사용자가 이 파일에 필요한 정보를 추가하려면 기존 설정 내용을 건드리지 않은 상태에서 새로운 항목을 추가하면 된다설정하는 방식은 다음과 같다

 

<file system>     <mount point>  <type>  <options>         <dump>           <pass>

 

하나의 file system에 대해서 한 행에 필요한 설정을 한다. 각 필드 사이는 Tab 키로 구분한다. 각 항목에 대한 상세한 내용은 다음과 같다.

 

 

   <file system> 

 

파일시스템을 대표하는 파티션의 device를 지정한다. 아래와 같이 여러 방법을 사용할 수 있다.

    /dev에 있는 device file 이름을 사용하는 방법

fdisk 명령이나 blkid 명령을 사용하여 /dev에 등록된 이름을 확인할 수 있다.

Ex) /dev/sda1

 


 

    LABEL을 사용하는 방법

LABEL=<label> 형식을 사용한다.

blkid 명령을 사용하면 LABEL을 파악할 수 있다.

Ex) LABEL="RECOVERY"

 

    UUID를 사용하는 방법         

UUID=<uuid> 형식을 사용한다.

blkid 명령을 사용하면 UUID를 파악할 수 있다.

Ex) UUID="FEF225C2F2257FCF"

 

/etc/fstab 파일에서 device 설정 내용을 지정할 때는 LABEL=<label> 또는 UUID=<uuid> 형태를 사용하는 것이 읽기 쉽고, 변동이 적으며, 이식이 용이하다.

 

 

   <mount point>

 

파일시스템이 mount될 위치이다.  mount된 파일시스템의 모든 directory 트리 구조와 저장된 데이터가 이 지점과 연결된다.

 

 

   <type>

 

해당 device file system 유형을 지정한다. ext?, tmpfs, devpts, sysfs, swap, vfat, hfs, ufs …와 같은 장치의 파일시스템 종류를 지정한다. "/proc/filesystems" 파일에서 Linux에서 현재 지원 가능한 파일시스템을 확인할 수 있다.

 

 

   <options>

 

"mount" 명령의 옵션이다. 파일시스템을 용도에 맞게 사용하기 위한 파일시스템 속성을 설정한다. defaults, auto, exec, suid, ro, rw, user, nouser ("man mount" 명령에서 "-o" 옵션 참조

 


 

   <dump>

 

파일시스템 덤프 여부: ( 0 또는 1의 값을 가짐)

dump 명령을 사용하여 백업을 수행할 때에만 의미가 있다.

숫자 0 : dump 명령으로 덤프 되지 않는 파일시스템.

숫자 1 : dump 명령으로 dump가 가능한 파일시스템.

 

 

   <pass>

 

파일시스템 검사 여부:

"fsck" 명령을 사용한 무결성 검사가 필요한지 여부를 가리킨다.

숫자 0 : 해당 파일시스템에 검사가 필요 없음 ("fsck" 명령이 실행 되지 않음)

숫자 1 : 파일시스템 검사가 먼저 필요 (루트 파일시스템)

숫자 2 : 파일시스템 검사가 먼저 필요 (루트 파일시스템을 제외한 나머지 파일시스템)

 

 

 

 

 

 

 


 

15.1.3.6    "umount" 명령 - device에 대한 directory 해제

 

특정 device file system Linux의 전체 file tree에서 분리할 때는 "umount" 명령을 사용한다.

 

[명령 형식]

umount          [ options ]   [ device ]    [ file-directory ]

 

[명령 개요]

    특정 device file system을 시스템의 전체 file tree에서 분리한다.

    user 권한    -- super user. 

 

[상세 설명]

    mount되어 있는 file system에서 어떤 파일이 사용 중이거나 특정 process가 그 directory working directory로 사용하고 있거나, file system위에 있는 swap 파일이 사용이라서 busy 상태인 경우는 그 device에 대해서 "umount" 작업을 할 수 없다.

 

[주요 option]

-h

Print help message and exit.

-r

In case unmounting fails, try to remount read-only.

-n

Unmount without writing in /etc/mtab.

-a

All of the file systems described in /etc/mtab are unmounted. (With umount version 2.7 and later: the proc filesystem is not unmounted.)

-t vfstype

Indicate that the actions should only be taken on file systems of the specified  type.   More than one type may be specified in a comma separated list.  The list of file system types can be prefixed with no to specify the file system types on which no action should be taken.

-O options

Indicate that the actions should only be taken on file systems with the specified options in /etc/fstab.  More than one option  type may be

specified in a comma separated list.  Each option can be prefixed with

no to specify options for which no action should be taken.

-f

Force unmount (in case of an unreachable NFS system).  (Requires kernel

2.1.116 or later.)

-l

Lazy unmount. Detach the filesystem from the filesystem hierarchy now,

and cleanup all references to the filesystem as soon as it is not  busy

anymore.  (Requires kernel 2.4.11 or later.)

 

 


 

Leave a Reply