서버/Linux II 2016. 2. 3. 16:05
Linux II - 03. 마운트 이해
1. 'mount' 명령어를 이용한 마운트
'mount' 명령어를 이용하여 해당 파일 시스템을 마운트한다. 반대로 마운트를 해지할 경우에는 'umount' 명령어(umount -a)를 사용한다. 단, 'mount' 명령어를 이용한 마운트 정보는 시스템이 재부팅되면 기록이 남지 않기 때문에 언마운트 상태로 시작된다.
Ex1) '/dev/sdb' 파티션 생성 및 파일 시스템 생성
첫번째 주파티션 : 50M 할당
두번째 주파티션 : 50M 할당
세번째 주파티션 : 50M 할당
네번째 주파티션 : 나머지 모든 영역 할당
login as: root
root@192.168.1.7's password:
Last login: Wed Feb 3 14:12:30 2016 from 192.168.1.1
[root@CentOS2 /root]#
[root@CentOS2 /root]# ls /dev/sdb*
/dev/sdb
[root@CentOS2 /root]# fdisk -l /dev/sdb
Disk /dev/sdb: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000131fb
Device Boot Start End Blocks Id System
[root@CentOS2 /root]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-204, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-204, default 204): +50M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (52-204, default 52): 52
Last cylinder, +cylinders or +size{K,M,G} (52-204, default 204): +50M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (103-204, default 103): 103
Last cylinder, +cylinders or +size{K,M,G} (103-204, default 204): +50M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (154-204, default 154): 154
Last cylinder, +cylinders or +size{K,M,G} (154-204, default 204): 204
Command (m for help): p
Disk /dev/sdb: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000131fb
Device Boot Start End Blocks Id System
/dev/sdb1 1 51 52208 83 Linux
/dev/sdb2 52 102 52224 83 Linux
/dev/sdb3 103 153 52224 83 Linux
/dev/sdb4 154 204 52224 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@CentOS2 /root]# ls /dev/sdb*
/dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb4
[root@CentOS2 /root]# fdisk -l /dev/sdb
Disk /dev/sdb: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000131fb
Device Boot Start End Blocks Id System
/dev/sdb1 1 51 52208 83 Linux
/dev/sdb2 52 102 52224 83 Linux
/dev/sdb3 103 153 52224 83 Linux
/dev/sdb4 154 204 52224 83 Linux
[root@CentOS2 /root]# mkfs -t ext4 /dev/sdb1
[root@CentOS2 /root]# mkfs -t ext4 /dev/sdb2
[root@CentOS2 /root]# mkfs -t ext4 /dev/sdb3
[root@CentOS2 /root]# mkfs -t ext4 /dev/sdb4
Ex2) '/dev/sdb1' 마운트 실시 (옵션 : rw, suid, exec)
[root@CentOS2 /root]# cd /mnt
[root@CentOS2 /mnt]# mkdir test1 test2 test3 test4
[root@CentOS2 /mnt]# cd
[root@CentOS2 /root]# ls /mnt
hgfs test1 test2 test3 test4
[root@CentOS2 /root]# mount -t ext4 -o rw,suid,exec /dev/sdb1 /mnt/test1
- o : 옵션 (기본값 : rw,suid,exec)
기본값 |
내용 |
반대 설정 |
rw |
읽기,쓰기 가능 |
ro |
suid |
SetUID 사용 가능 |
nosuid |
exec |
파일 실행 가능 권한 |
noexec |
auto |
부팅시 자동 마운트 |
noauto |
nouser |
일반 계정 마운트 금지 |
user |
atime |
Access 타임 기록 |
noatime |
Ex3) '/dev/sdb2' 마운트 실시 (옵션 : nosuid)
[root@CentOS2 /root]# mount -t ext4 -o nosuid /dev/sdb2 /mnt/test2
[root@CentOS2 /root]# cp /bin/cat /mnt/test2/newcat
[root@CentOS2 /root]#
[root@CentOS2 /root]# cd /mnt/test2
[root@CentOS2 /mnt/test2]# ls -l
ls -l
합계 61
drwx------. 2 root root 12288 2016-02-03 15:24 lost+found
-rwxr-xr-x. 1 root root 48568 2016-02-03 16:08 newcat
[root@CentOS2 /mnt/test2]# chmod u+s newcat
[root@CentOS2 /mnt/test2]# ls -l
합계 61
drwx------. 2 root root 12288 2016-02-03 15:24 lost+found
-rwsr-xr-x. 1 root root 48568 2016-02-03 16:08 newcat
[root@CentOS2 /mnt/test2]# cd
[root@CentOS2 /root]#
[root@CentOS2 /root]# su - user1
[user1@CentOS2 /home/user1]$
[user1@CentOS2 /home/user1]$ cd /mnt/test2
[user1@CentOS2 /mnt/test2]$ ls -l
합계 61
drwx------. 2 root root 12288 2016-02-03 15:24 lost+found
-rwsr-xr-x. 1 root root 48568 2016-02-03 16:08 newcat
[user1@CentOS2 /mnt/test2]$ ./newcat /etc/shadow
./newcat: /etc/shadow: 허가 거부
[user1@CentOS2 /mnt/test2]$ mount
/dev/sda1 on / type ext4 (rw)
~ 중간생략~
/dev/sdb1 on /mnt/test1 type ext4 (rw)
/dev/sdb2 on /mnt/test2 type ext4 (rw,nosuid)
[user1@CentOS2 /mnt/test2]$ exit
logout
[root@CentOS2 /root]#
Ex4) '/dev/sdb3' 마운트 실시 (옵션 : rw, noexec)
[root@CentOS2 /root]# mount -o noexec,rw /dev/sdb3 /mnt/test3
[root@CentOS2 /root]# cp /bin/cat /mnt/test3
[root@CentOS2 /root]#
[root@CentOS2 /root]# cd /mnt/test3
[root@CentOS2 /mnt/test3]# ls -l
합계 61
-rwxr-xr-x. 1 root root 48568 2016-02-03 16:17 cat
drwx------. 2 root root 12288 2016-02-03 15:24 lost+found
[root@CentOS2 /mnt/test3]# ./cat /etc/shadow
-bash: ./cat: 허가 거부
[root@CentOS2 /mnt/test3]# mount
/dev/sda1 on / type ext4 (rw)
~중간 생략
/dev/sdb1 on /mnt/test1 type ext4 (rw)
/dev/sdb2 on /mnt/test2 type ext4 (rw,nosuid)
/dev/sdb3 on /mnt/test3 type ext4 (rw,noexec)
[root@CentOS2 /mnt/test3]# cd
[root@CentOS2 /root]#
Ex5) '/dev/sdb4' 마운트 실시 (옵션 : ro)
[root@CentOS2 /root]# mount -o ro /dev/sdb4 /mnt/test4
[root@CentOS2 /root]# cd /mnt/test4
[root@CentOS2 /mnt/test4]# touch 1111
touch: cannot touch `1111': 읽기전용 파일 시스템
[root@CentOS2 /mnt/test4]# ls
lost+found
[root@CentOS2 /mnt/test4]# rm -rf lost+found
rm: cannot remove `lost+found': 읽기전용 파일 시스템
[root@CentOS2 /mnt/test4]# mount
/dev/sda1 on / type ext4 (rw)
~ 중간 생략 ~
/dev/sdb1 on /mnt/test1 type ext4 (rw)
/dev/sdb2 on /mnt/test2 type ext4 (rw,nosuid)
/dev/sdb3 on /mnt/test3 type ext4 (rw,noexec)
/dev/sdb4 on /mnt/test4 type ext4 (ro)
[root@CentOS2 /mnt/test4]# cd
[root@CentOS2 /root]#
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 76K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb1 46M 826K 43M 2% /mnt/test1
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
Ex6) 시스템 재부팅 및 마운트 정보 확인
[root@CentOS2 /root]# reboot
login as: root
root@192.168.1.7's password:
Last login: Wed Feb 3 15:27:50 2016 from 192.168.1.1
[root@CentOS2 /root]#
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
[root@CentOS2 /root]# rm -rf /mnt/test*
2. 부팅시 자동 마운트 설정
부팅시 사용할 마운트 정보는 'etc/fstab' 파일로 관리한다. 이 파일은 관리자가 직접 편집해야 하며, 부팅시 마운트할 장치가 있다면 여기에 등록을 해야 한다.
[root@CentOS2 /root]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Feb 3 01:40:21 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=7c533aa0-0a72-4a94-b076-382622ad8486 / ext4 defaults 1 1
UUID=f55d38f2-1434-4107-8aab-3f9ac3cba3b5 /home ext4 defaults 1 2
UUID=78b6f307-7ca2-4ae7-b2e5-866f01d64a15 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@CentOS2 /root]# cd /mnt
[root@CentOS2 /mnt]# mkdir test1 test2 test3 test4
[root@CentOS2 /mnt]# cd
[root@CentOS2 /root]# ls /mnt
hgfs test1 test2 test3 test4
Ex1) 장치명을 이용하여 마운트 설정
[root@CentOS2 /root]# vi /etc/fstab
1 |
필드 |
내용 |
|
Dump | |
/dev/sda1 |
파일 시스템 이름 |
|
0 |
덤프 되지 않은 파일 시스템 |
/boot |
마운트 포인트 |
|
1 |
데이터 백업을 위해 Dump 가능 |
ext4 |
파일 시스템 유형 |
|
파일 점검 옵션 | |
rw |
옵션 |
|
0 |
부팅시 파일 시스템 점검 않함 |
0 |
Dump 관련 설정 |
|
1 |
부팅시 파일 시스템 점검시 가장 먼저 검사 |
0 |
파일 점검 옵션 |
|
2 이상 |
파일 시스템 점검시 순서 |
[root@CentOS2 /root]# mount -a
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb1 46M 826K 43M 2% /mnt/test1
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
[root@CentOS2 /root]# umount -a
umount: /dev/shm: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
[root@CentOS2 /root]# reboot
login as: root
root@192.168.1.7's password:
Last login: Wed Feb 3 17:14:02 2016 from 192.168.1.1
[root@CentOS2 /root]#
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb1 46M 826K 43M 2% /mnt/test1
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
Ex2) LABEL을 이용하여 마운트 설정
[root@CentOS2 /root]# e2label /dev/sdb1 /test1 (삭제 # e2label /dev/sdb1 '')
[root@CentOS2 /root]# e2label /dev/sdb2 /test2 (삭제 # e2label /dev/sdb2 '')
[root@CentOS2 /root]# e2label /dev/sdb3 /test3 (삭제 # e2label /dev/sdb3 '')
[root@CentOS2 /root]# e2label /dev/sdb4 /test4 (삭제 # e2label /dev/sdb4 '')
[root@CentOS2 /root]# e2label /dev/sdb1
/test1
[root@CentOS2 /root]# e2label /dev/sdb2
/test2
[root@CentOS2 /root]# e2label /dev/sdb3
/test3
[root@CentOS2 /root]# e2label /dev/sdb4
/test4
[root@CentOS2 /root]# blkid | grep /dev/sdb
[root@CentOS2 /root]# vi /etc/fstab
1 |
[root@CentOS2 /root]# mount -a
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb1 46M 826K 43M 2% /mnt/test1
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
[root@CentOS2 /root]# umount -a
umount: /dev/shm: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
[root@CentOS2 /root]# reboot
login as: root
root@192.168.1.7's password:
Last login: Wed Feb 3 17:48:37 2016 from 192.168.1.1
[root@CentOS2 /root]#
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb1 46M 826K 43M 2% /mnt/test1
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
Ex3) UUID을 이용하여 마운트 설정
UUID : 파일 시스템이 생성될때 할당 받는 ID
[root@CentOS2 /root]# ls -la /dev/disk/by-uuid/
합계 0
drwxr-xr-x. 2 root root 180 2019-02-21 17:10 .
drwxr-xr-x. 4 root root 80 2019-02-22 00:52 ..
lrwxrwxrwx. 1 root root 10 2019-02-22 00:53 2bbb5430-a91b-4b10-91af-3cf7fb87a79a -> ../../sda2
lrwxrwxrwx. 1 root root 10 2019-02-21 17:10 2e683278-9d49-4e68-a42d-f8ffadfc187d -> ../../sdb3
lrwxrwxrwx. 1 root root 10 2019-02-22 00:53 305b97ef-f852-453c-8516-5deaf8aec5f3 -> ../../sda1
lrwxrwxrwx. 1 root root 10 2019-02-21 17:10 31d40b89-c81d-44ec-b12b-2088e651338e -> ../../sdb4
lrwxrwxrwx. 1 root root 10 2019-02-21 17:10 5fa9cc44-37c0-4713-b977-c5deb49d69be -> ../../sdb1
lrwxrwxrwx. 1 root root 10 2019-02-22 00:53 a59d6886-bd63-48e9-a170-f60980bae919 -> ../../sda3
lrwxrwxrwx. 1 root root 10 2019-02-21 17:10 f609d686-adca-4ce5-81c9-aff9f39c29d1 -> ../../sdb2
[root@CentOS2 /root]# tune2fs -l /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name: /test1
Last mounted on: <not available>
Filesystem UUID: 7accb373-dcc1-4292-b12b-ea9915a9b6da
~중간 생략~
[root@CentOS2 /root]# tune2fs -l /dev/sdb1 | grep -i uuid
Filesystem UUID: 7accb373-dcc1-4292-b12b-ea9915a9b6da
[root@CentOS2 /root]# tune2fs -l /dev/sdb2 | grep -i uuid
Filesystem UUID: 1beadb11-a212-47bf-8841-0756dc831705
[root@CentOS2 /root]# tune2fs -l /dev/sdb3 | grep -i uuid
Filesystem UUID: 26571417-1bfa-4ca0-aed6-dcbf1ee4ca3c
[root@CentOS2 /root]# tune2fs -l /dev/sdb4 | grep -i uuid
Filesystem UUID: 3e3e281e-233e-4dcb-9a5f-b6fdca99f220
[root@CentOS2 /root]# vi /etc/fstab
1 |
[root@CentOS2 /root]# mount -a
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
/dev/sdb1 46M 826K 43M 2% /mnt/test1
[root@CentOS2 /root]# umount -a
umount: /dev/shm: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
[root@CentOS2 /root]# reboot
login as: root
root@192.168.1.7's password:
Last login: Wed Feb 3 18:02:09 2016 from 192.168.1.1
[root@CentOS2 /root]#
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb1 46M 826K 43M 2% /mnt/test1
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
Ex4) '/etc/fstab' 파일에 등록된 마운트 정보 특징
[root@CentOS2 /root]# umount -a
umount: /dev/shm: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
- '/etc/fstab' 파일에 등록된 마운트 정보는 마운트를 해지한 이후, 다시 마운트할 경우 파일 시스템 장치명만 지정하면 된다.
[root@CentOS2 /root]# mount /home
[root@CentOS2 /root]# mount /dev/sdb1
[root@CentOS2 /root]# mount /dev/sdb2
[root@CentOS2 /root]# mount /dev/sdb3
[root@CentOS2 /root]# mount /dev/sdb4
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
/dev/sdb1 46M 826K 43M 2% /mnt/test1
/dev/sdb2 46M 875K 42M 2% /mnt/test2
/dev/sdb3 46M 875K 42M 2% /mnt/test3
/dev/sdb4 46M 826K 43M 2% /mnt/test4
Ex5) /etc/fstab' 파일 복구
[root@CentOS2 /root]# vi /etc/fstab
1 |
[root@CentOS2 /root]# umount -a
umount: /dev/shm: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount: /: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@CentOS2 /root]# mount -a
[root@CentOS2 /root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 13G 4.5G 7.1G 39% /
tmpfs 495M 72K 495M 1% /dev/shm
/dev/sda3 477M 2.3M 449M 1% /home
[root@CentOS2 /root]# rm -rf /mnt/test*
[root@CentOS2 /root]# ls /mnt
'서버 > Linux II' 카테고리의 다른 글
Linux II - 06. LVM (Logical Volume Manager) (0) | 2016.02.19 |
---|---|
Linux II - 05. 파일 시스템 점검 및 복구 (0) | 2016.02.17 |
Linux II - 04. 파일 시스템 구조 (0) | 2016.02.04 |
Linux II - 02. 리눅스 추가 설치 II (설치 완료 & 기타 설정) (0) | 2016.02.03 |
Linux II - 01. 리눅스 추가 설치 I (설치 시작 & 파티션 작업) (0) | 2016.02.02 |