리눅스1> 2018.01.10_21일차 - 1. Partitioning 2. Process
* 프로세스(Process)
프로세스(Process)
- 컴퓨터에서 연속적으로 실행되고 있는 컴퓨터 프로그램을 말함
사용형식
ps [option]
option
-e : 모든 프로세스를 출력
-f : 풀 포맷형식으로
프로세스 종료 명령어
사용형식
kill PID
프로세스 항목
UID : User ID(사용자 고유 식별자)
PID : Process ID(자식, 프로세스 고유 식별자)
PPID : Parents ID(부모, 프로세스 고유 식별자)
C : CPU(점유율)
STIME : Start Time(접속한 시간)
TTY : TeleTYpe Writer(가상 터미널)
TIME : 실행시간
CMD : CoMmanD(명령어)
[root@localhost itbank]# ps -ef
[root@localhost itbank]#
////////////////////////////////////////////////
/etc/inittab -> 리눅스가 부팅할 때 운영레벨을 선택하는 설정파일
# 1 - Single user mode
단일 사용자(root로 바로 로그인, 비번없이)
Windows에서 안전모드와 같다
파일시스템을 점검, 관리자 비밀번호 변경, 악성코드, 바이러스 등
관리자가 관리하기 위해서 (복구모드)
CLI환경
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
다중 사용자(어떠한 사용자로 로그인, 비번입력), NFS(서비스)를 지원하지 않음
CLI환경
# 3 - Full multiuser mode
다중 사용자(어떠한 사용자로 로그인, 비번입력), NFS(서비스)를 지원함
CLI환경
# 4 - unused
/etc/inittab을 사용하지 않음(2번과 동일)
CLI환경
# 5 - X11
X-Window를 사용하여 그래픽을 지원함, 3번 기능까지 지원함
(현재 우리가 사용하고 있는 운영레벨임)
# 0 - halt (Do NOT set initdefault to this)
종료
# 6 - reboot (Do NOT set initdefault to this)
재부팅
* 현재
CentOS 6이전 | CentOS 7
/etc/inittab | /lib/systemd/system/
--------------------------------------
runlevel 0 -> poweroff.target
runlevel 1 -> rescue.target
runlevel 2 -> multi-user.target
runlevel 3 -> multi-user.target
runlevel 4 -> multi-user.target
runlevel 5 -> graphical.target
runlevel 6 -> reboot.target
운영레벨 변경하기(CentOS 7 기준)
ln -sf /lib/systemd/system/TARGET.target /etc/systemd/system/default.target
systemctl set-default TARGET.target
운영레벨 확인(CentOS 7기준)
systemctl get-default
////////////////////////////////////////////////
* 관리자 비밀번호 분실 시 해결방법
1> 비밀번호 분실 시 해결방법
부팅시 커널에서 알파벳 'e' -> 15줄에서 방향키 왼쪽 버튼을 눌러서 rhgb quiet까지를 삭제후
ro를 rw로 변경 후 한 칸 띄고 init=/bin/bash를 입력 후 ctrl+x를 누름
비밀번호를 바꾸어야 하므로 passwd 명령어를 사용하여 비번을 바꾸자
exec /sbin/init 치면 재부팅
비밀번호 분실 시 해결방법
2> grub 암호화 걸기
root로 그래픽으로 로그인 하시고 아래와 같이 작업을 하세요
준비물
mkdir /backup
cp /boot/grub2/grub.cfg /backup
cp /etc/grub.d/00_header /backup
1) /etc/grub.d/00_header를 확인!
2) 문서 편집기를 이용하여 00_header를 작업!
3) 맨 마지막 줄 아래에 작성하기
cat << EOF
set superusers="root"
password root linuxone
EOF
4) 저장 후 종료
5) grub2-mkconfig -o /boot/grub2/grub.cfg 타이핑하고 엔터!
6) reboot
EOF
화면에 긴 문장을 한번에 출력할 경우
띄어쓰기 줄바꾸기도 그대로 유지
EOF 바로 앞까지 출력
[실습]
// 비번 변경
재부팅
> 3줄 있을 때, 마우스 안에 넣고 e 또는 ctrl+alt+insert
> 위에서 15째줄 까지 오고 왼쪽 무우스 누르기 이 줄 다 지우고
> 커서를 ro쪽 오고 ro를→ rw init=bin/bash 로 변경
> Ctrl-X
> bash-4.2# passwd Enter
> 1, 1
># exec /sbin/init // 재부팅
// 암호화 처리 ; 알파벳 e 못치게(보안 처리)
# ls -l /backup
# cp /etc/grub.d/00_header /backup // group에 관련된 파일
# ls -l /backup
# vi /etc/grub.d/00_header
맨 밑에
빈 줄 생성
360 cat << EOF
361 set superusers="centos7"
362 password centos7 linux1 // lunux1 : 비번
363 EOF
:wq
# grub2-mkconfig -o /boot/grub2/grub.cfg
done
이 뜨면 된거
# reboot
세 줄 떴을 때 알파벳 e 누르고 비번 눌러서 체크해보기
centos7
linux1
////////////////////////////////////////////////
* Partitioning 방법
1. HDD 추가 (IDE)
poweroff> VMware> Edit virtual machine> settings> add> 예>
Hard Disk 클릭> IDE 체크> Create a new virtual disk 클릭>
Maximum disk size : 1.0 GB> Disk file(기본값)> Finish> 확인 후 OK
2. HDD 삭제
poweroff> Edit virtual machine> settings> 삭제할 HDD를 선택>
Remove> OK
3. HDD 확인
사용형식
fdisk [option]
fdisk [option] 장치명
option
-l : 하드디스크와 파티션 목록
4. 파티션 생성
사용형식
fisk 장치
fdisk에서 사용할 명령어들
d는 파티션 삭제
l은 파티션 타입 리스트
m은 도움말 출력
n은 파티션 생성
p는 파티션 테이블 출력
q는 저장하지 않고 종료
t는 파티션의 시스템 ID 변경
w는 저장하고 종료
1) Primary(주) Partition 생성
n → p 또는 enter → 파티션 번호는 생성하는 순서대로 잡아주는 것이 좋음(1 또는 enter)
→ 첫 번째 섹터는 기본값대로 → 마지막 섹터는 용량으로 하는게 편함(용량은 +용량단위) +500M
2) Extened(확장)
Partition 생성
n → e → 파티션 번호 순서대로(2 또는 enter) → 첫번째 섹터는 기본값으로(enter)
→ 마지막 섹터는 용량으로(+용량단위) +300M
3) Logical(논리)
Partition 생성
n → l → 파티션 번호는 무조건 5번(이상) → 첫번째 섹터는 기본값으로(enter)
→ 마지막 섹터는 용량으로(+ 용량단위) 또는 용량으로 enter(남은 용량 다 잡아라)
→ enter
삭제시 d
Partition num : 2
확장(extended) 지우면 logical 도 같이 지워짐
p
sdb1 : HDD명+partition num,
End : sector
Blocks : 용량
ID : 리눅스 시스템 고유 번호, 83
확장은 System의 Extended
논리는 Device Boot의 /dev/sdb5 => 5번부터인것 확인~!
5. 포맷(Make File System)
사용형식
mkfs [option] 인자값 장치
(파티션)
또는
mkfs. 인자값 장치(파티션)
option
-t : type.
인자값
xfs // centos7 에서 쓰는 파일 시스템 (windows에서 NTFS; FAT32(기본값) : 4GB 이상은 못 받음)
cf. 포맷 대상
p(주), l(논리)
p는 포맷이 되는데
e는 포맷이 안됨(사용할 수 있는 공간이 아님)
(참고!
CentOS 5.x 포맷 방법
mkfs -t ext3 장치(파티션)
또는
mkfs.ext3 장치(파티션)
CentOS 6.x 포맷 방법
mkfs -t ext4 장치(파티션)
또는
mkfs.ext4 장치(파티션) )
6. 마운트(mount)
- 파일 시스템을 디렉터리 일부에 넣어서 이용가능하게 하는 작업
마치, 디릭터리처럼 사용하는 것을 마운트라 할 수 있음
- 서버의 자원을 사용하는 것이므로 관리자만 사용가능
- 장치파일을 디렉터리화 함
사용형식(mount 장착)
mount
→ 마운트 된 목록을 출력
mount 장치(파티션) 임의의 디렉터리(mount point)
사용형식(mount 장착해제)
umount 장치(파티션)
또는
umount 임의의 디렉터리(mount point)
별도로 mount 상태 확인할 때 df -h를 사용함
df(명령어)는 디스크 공간 확인
-h은 사람이 보기 편하게 출력
! mount 주의사항
1) mount를 할 때 하나의 장치나 파티션은 반드시 하나의 임의의 디렉터리(mount point)를
사용해야 함
(예를 들어, 1개의 장치를 사용할 때 여러 개의 mount point를 사용할 필요가 없으며, 여러
개의 장치를 하나의 mount point로 mount 해서는 안 됨)
2) umount를 할 때 반드시 mount point에 있어선 안 됨
(예를 들어, mount point나 그 하위에 있으면 umount가 안됨. 그래서 mount point가 아닌
곳으로 변경해야 함)
3) mount를 할 때 Primary Partition과 Logical Partition만 해당 됨 // 포맷이 되니까
(Extended Partition은 mount 할 수 없음) // 포맷이 안되니까
4) mount를 할 때 반드시 기존에 사용중인 디렉터리로 mount 해서는 안 됨
(예를 들어, 사용자 홈 디렉터리 X 기존에 사용중인 /home/itbank 로 하지마!!!
mkdir로 새로 만들것! )
ex>
장치파일 |
디렉터리 |
/dev/sdb1 |
/a |
귀신 → 어떤 사람
mount
↑ 빙의
Driver
S/W ↔ H/W
☆ CD-ROM 사용 방법
먼저 iso image file을 삽입!
: VM> Settings> CD/DVD => C:0_CentOS7>ISO
사용형식
mount /dev/sr0(원본파일) 임의의 디렉터리(mount point)
또는
mount /dev/cdrom(바로가기) 임의의 디렉터리(mount point)
(참고로
The partition table has been altered! // w 눌렀을 때??
Calling ioctl() to re-read partition table.
Syncing disks.
위 문구 사이에... The new table will be used at the next reboot ... 문구가 나오면
재부팅을 반드시 하세요)
cf) 로그인 하기 전에 CD-ROM을 삽입 한 경우
수동으로 mount 해줘야..,
centOS 5.x : /dev/hdc
centOS 6.x : /dev/sr0
/dev/cdrom
cf) vmware하단에 CD 아이콘 불 안 깜박 거리면
오.버> connect 클릭!
[root@localhost ~]# cd ~itbank
[root@localhost itbank]#
// 하드디스크와 파티션 보기
[root@localhost itbank]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x000a586b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 6293503 2097152 82 Linux swap / Solaris
/dev/sda3 6293504 41943039 17824768 83 Linux
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
[root@localhost itbank]#
// 내가 추가한 장치 보기
[root@localhost itbank]# fdisk -l /dev/sdb
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
// 파티션 생성
[root@localhost itbank]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xd8f28c00.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xd8f28c00
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +500M
Partition 1 of type Linux and of size 500 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xd8f28c00
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1026047 512000 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e
Partition number (2-4, default 2): 2
First sector (1026048-2097151, default 1026048):
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-2097151, default 2097151): +300M
Partition 2 of type Extended and of size 300 MiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (1028096-1640447, default 1028096):
Using default value 1028096
Last sector, +sectors or +size{K,M,G} (1028096-1640447, default 1640447):
Using default value 1640447
Partition 5 of type Linux and of size 299 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xd8f28c00
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1026047 512000 83 Linux
/dev/sdb2 1026048 1640447 307200 5 Extended
/dev/sdb5 1028096 1640447 306176 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
// 포맷
[root@localhost itbank]#
[root@localhost itbank]# mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost itbank]#
[root@localhost itbank]#
[root@localhost itbank]# mkfs -t xfs /dev/sdb2
mkfs.xfs: /dev/sdb2 appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@localhost itbank]#
[root@localhost itbank]# mkfs.xfs /dev/sdb5
meta-data=/dev/sdb5 isize=512 agcount=4, agsize=19136 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=76544, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost itbank]#
[root@localhost itbank]#
// 마운트(장치 쓰기)
// 아직 장치를 쓸 수 없음..,
[root@localhost itbank]# mkdir /dev/sdb1/hello
mkdir: `/dev/sdb1/hello' 디렉토리를 만들 수 없습니다: 디렉터리가 아닙니다
[root@localhost itbank]#
[root@localhost itbank]# touch /dev/sdb1/hello
touch: cannot touch `/dev/sdb1/hello': 디렉터리가 아닙니다
[root@localhost itbank]#
[root@localhost itbank]# ls -l /dev/sdb1
brw-rw----. 1 root disk 8, 17 1월 10 13:31 /dev/sdb1 // b : block system file
[root@localhost itbank]#
[root@localhost itbank]#
[root@localhost itbank]# mkdir /mountpoint
[root@localhost itbank]#
[root@localhost itbank]# ls -l /mountpoint/
합계 0
[root@localhost itbank]#
[root@localhost itbank]# touch /mountpoint/testfile2
[root@localhost itbank]#
[root@localhost itbank]# ls -l /mountpoint
합계 0
-rw-r--r--. 1 root root 0 1월 10 14:05 testfile2
[root@localhost itbank]#
[root@localhost itbank]# ls -l /dev/sdb1
brw-rw----. 1 root disk 8, 17 1월 10 13:31 /dev/sdb1
[root@localhost itbank]#
[root@localhost itbank]# mount /dev/sdb1 /mountpoint // /dev/sdb1 == /mountpoint
[root@localhost itbank]#
[root@localhost itbank]# ls -l /mountpoint/
합계 0 // dev/sdb1으로 mount를 해서 testfile2가 사라짐
[root@localhost itbank]#
[root@localhost itbank]#
[root@localhost itbank]# ls -l /mountpoint
합계 0
-rw-r--r--. 1 root root 0 1월 10 14:08 testfile1
// 현재 마운트된 목록 확인
// 1> 마운트된 detail한 목록
[root@localhost itbank]# mount | tail -1
/dev/sdb1 on /mountpoint type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
or
// 2> mount 유무
[root@localhost itbank]# df -h | tail -1
/dev/sdb1 497M 26M 472M 6% /mountpoint
// 마운트 해지
[root@localhost itbank]# umount /dev/sdb1
or
[root@localhost itbank]# umount /mountpoint
// 확인해 보면 해지 된 것을 알 수 있다
[root@localhost itbank]# mount | tail -1
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=99972k,mode=700)
[root@localhost itbank]#
[root@localhost itbank]# df -h | tail -1
tmpfs 98M 0 98M 0% /run/user/0
[root@localhost itbank]#
[root@localhost itbank]# ls -l /mountpoint/
합계 0
-rw-r--r--. 1 root root 0 1월 10 14:05 testfile2
[root@localhost itbank]#
[root@localhost itbank]# ls -l /dev/sdb1
brw-rw----. 1 root disk 8, 17 1월 10 13:31 /dev/sdb1
[root@localhost itbank]#
[root@localhost itbank]#
[root@localhost itbank]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 17G 4.8G 13G 28% /
devtmpfs 474M 0 474M 0% /dev
tmpfs 489M 0 489M 0% /dev/shm
tmpfs 489M 7.0M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 1014M 194M 821M 20% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
[root@localhost itbank]#
// CD-ROM mount
[root@localhost ~]# mount | tail -1
/dev/sr0 on /run/media/root/CentOS 7 x86_64 type iso9660 (ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)
[root@localhost ~]#
f[root@localhost ~]# df -h | tail -1
/dev/sr0 8.1G 8.1G 0 100% /run/media/root/CentOS 7 x86_64
[root@localhost ~]#
[root@localhost ~]# umount /dev/sr0
[root@localhost ~]#
[root@localhost ~]# mount | tail -1
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
[root@localhost ~]#
[root@localhost ~]# ls -l /dev/sr0
brw-rw----+ 1 root cdrom 11, 0 1월 10 14:30 /dev/sr0
[root@localhost ~]#
[root@localhost ~]# ls -l /dev/cdrom
lrwxrwxrwx. 1 root root 3 1월 10 14:30 /dev/cdrom -> sr0
[root@localhost ~]#
[root@localhost ~]# mount /dev/cdrom /mountpoint
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]#
[root@localhost ~]# mount | tail -1
/dev/sr0 on /mountpoint type iso9660 (ro,relatime)
[root@localhost ~]#
[root@localhost ~]# df -h | tail -1
/dev/sr0 8.1G 8.1G 0 100% /mountpoint
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# cd /mountpoint/
[root@localhost mountpoint]#
[root@localhost mountpoint]# ls
CentOS_BuildTag GPL RPM-GPG-KEY-CentOS-7 images
EFI LiveOS RPM-GPG-KEY-CentOS-Testing-7 isolinux
EULA Packages TRANS.TBL repodata
// unmount
[root@localhost mountpoint]# pwd
/mountpoint
[root@localhost mountpoint]# umount /dev/cdrom
umount: /mountpoint: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@localhost mountpoint]#
[root@localhost mountpoint]# cd ~itbank
[root@localhost itbank]#
[root@localhost itbank]# umount /dev/cdrom
'BigData_Off1 > 리눅스1' 카테고리의 다른 글
리눅스1> 2018.01.09_20일차 - File system & Disk Management(① 개념 ② Partition) (0) | 2018.01.09 |
---|---|
리눅스1> 2018.01.06(08)_18~19일차 - 패키지 설치 1) RPM 2) YUM (0) | 2018.01.05 |
리눅스1> 2018.01.05_17일차 - 3) 보관(tar), 4) 다중압축(tar+gzip, tar+bzip2) (0) | 2018.01.05 |
리눅스1> 2018.01.04_16일차 - umask, 압축(gzip, bzip2) (0) | 2018.01.04 |
리눅스1> 2018.01.03_15일차 - 권한> 3. 소유권, <실습>사용자 복구 관련 (0) | 2018.01.03 |