20210415 (목)
9:32 review
디스크 구조
Platter 논리적 구조
- Track
- Sector
- Cylinder
파티셔닝
- 디스크의 공간을 구획하는 것
(1) MBR Partitioning
- BIOS Firmware를 가진 컴퓨터에서 사용 가능
- Primary Partiton 4개 생성 가능
- 최대 용량 2TB까지 지원
Primary Partiton : OS 설치가 가능한 파티션
Extended Partiton : Logical 파티션의 정보를 담는 특수한 파티션. 데이터 저장 불가
Logical Partiton : 데이터 저장은 가능하지만 OS 설치가 불가한 파티션
(2) GPT Partitioning
- EFI/UEFI Firmware를 가진 컴퓨터에서 사용 가능
- 128개의 Partition 생성 가능
- 최대 8ZB까지 지원
디스크 인터페이스
E-IDE
SATA
SCSI
SAS(Serial Attached SCSI)
=======================================
디스크 장착 → 파티셔닝 → File System
MBR 파티셔닝 : 4개의 파티셔닝까지 가능.
# fdisk /dev/sdb
[root@localhost dev]# 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 0x4a922873.
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-41943039, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 10000
Partition 1 of type Linux and of size 3.9 MiB is set
Command (m for help): p
Disk /dev/sdb: 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: 0x4a922873
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10000 3976+ 83 Linux
Command (m for help): d
Selected partition 1
Partition 1 is deleted
File System : 디스크에 데이터를 저장하고 관리하는 방식
- EXT2 / EXT3 / EXT4 : 리눅스 초기부터 개발되어 리눅스에서 기본적으로 사용하는 파일시스템
- XFS : CentOS7, Oracle Linux 에서 기본 파일시스템으로 사용하는 파일시스템
- FAT / FAT16 / FAT32 : Microsoft에서 개발한 파일 시스템 MS-DOS, Windows 9x, 메모리 카드 등에서 사용
- exFAT : Microsoft에서 개발한 파일시스템 FAT32의 최대 파일크기 4GB제한을 극복
- NTFS : Windows NT 계열 운영체제에서 사용하는 파일 시스템
- ISO9660 : CD, DVD에서 사용하는 파일 시스템
- UDFS : DVD에서 데이터 저장용으로 사용하는 파일 시스템
ext2 방식으로 mkfs를 통해 파일시스템 만들기 (mkfs 초기화 명령어)
# mkfs -t FSTYPE DEVICE
# mkfs -t ext2 /dev/sdc1
[root@localhost ~]# mkfs -t ext2 /dev/sdc1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
마운트
# mount [option] DEVICE MOUNT_POINT
# mount -t xfs /mnt/data1
파일시스템을 추가한 후 마지막 단계는 디렉터리 구조의 디렉터리에 파일시스템을 마운트 하는 것이다. 디렉터리 계층에 파일 시스템을 마운트하면 사용자 공간 유틸리티가 장치의 파일에 액세스하거나 쓸 수 있다.
관리자는 mount 명령을 사용하여 장치를 디렉터리 위치 또는 마운트 지점에 수동으로 연결한다. mount 명령은 장치, 마운트 지점 및 선택적으로 파일 시스템 옵션을 인수로 허용한다.
파일 시스템 옵션은 파일 시스템의 동작을 사용자 지정 한다.
1) 마운트 포인트 생성 (/mnt)
# mkdir /mnt/data1
2) 마운트
# mount -t FSTYPE DEVICE MOUNT_POINT
[root@localhost /]# mount -t ext2 /dev/sdc1 /mnt/data1
[root@localhost /]# mount |grep root
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sdc1 on /mnt/data1 type ext2 (rw,relatime,seclabel,data=ordered)
3) u마운트
# umount DEVICE
[root@localhost mnt]# umount /dev/sdc3
4) 영구 마운트 /etc/fstab
①장치 파일 ② 마운트 포인트 ③파일 시스템 ④마운트_옵션 ⑤덤프유무 ⑥FSCK 유무
/dev/mapper/centos-root / xfs defaults 0 0
UUID=3e6953e1-8a31-4d07-83b1-51087da100aa /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdd1 /mnt/storage ext4 defaults 0 0
①/dev/sdd1 ② /mnt/storage ③ ext4 ④ defaults ⑤ 0 ⑥ 0
=================================================
스왑영역관리 (/etc/fstab)
* 커널은 스왑 공간을 사용해서 메모리의 비활성 페이지를 보관하여 시스템 RAM을 확보한다. 시스템 RAM과 스왑 공간을 합해서 가상메모리라고 한다.
* 물리적 메모리가 부족한 경우 잘 사용하지 않는 프로세스를 swap 영역으로 옮기고 새로운 프로세스를 실행시키기 위한 가상 메모리 영역을 확보
1) swap 영역 초기화 - mkswap
# mkswap DEVICE
2) swap 영역 연결
# swapon DEVICE
3) swap 영역 연결 확인
# free → 메모리 상태 확인
# swapon -s → swap 영역 상세 확인
4) swap 영역 연결 해제
# swapoff DEVICE
5) swap 영역 영구 마운트
# vim /etc/fstab
# DEVICE swap swap MOUNT_OPTION DUMP 유무, FSCK 유무
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1882072 723916 348444 28924 809712 975440
Swap: 2097148 0 2097148
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1882072 723916 348444 28924 809712 975440
Swap: 2097148 0 2097148
[root@localhost ~]# fdisk /dev/sdd
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.
Command (m for help): p
Disk /dev/sdd: 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: 0x1902e63a
Device Boot Start End Blocks Id System
/dev/sdd1 2048 2099199 1048576 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-41943039, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-41943039, default 41943039): +256M
Partition 2 of type Linux and of size 256 MiB is set
Command (m for help): p
Disk /dev/sdd: 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: 0x1902e63a
Device Boot Start End Blocks Id System
/dev/sdd1 2048 2099199 1048576 83 Linux
/dev/sdd2 2099200 2623487 262144 83 Linux
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): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe
[root@localhost ~]# mkswap /dev/sdd2
Setting up swapspace version 1, size = 262140 KiB
no label, UUID=c00b5741-4abc-4363-980e-a818bbfd98d3
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1882072 731556 327196 30000 823320 966616
Swap: 2097148 0 2097148
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2097148 0 -2
[root@localhost ~]# swapon /dev/sdd2
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1882072 737468 321284 30000 823320 960712
Swap: 2359288 0 2359288
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2097148 0 -2
/dev/sdd2 partition 262140 0 -3
[root@localhost ~]# swapoff /dev/sdd2
[root@localhost ~]# free
total used free shared buff/cache available
Mem: 1882072 737084 321548 30108 823440 960980
Swap: 2097148 0 2097148
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2097148 0 -2
[root@localhost ~]#
영구 스왑 :
# vi /etc/fstab
/dev/sdd2 swap swap defaults 0 0
→ 마운트 필드와 순번 같으나 device 경로가 아닌 swap 을 써준다. (/mnt 같은 경로가 없는 셈)
====
스왑 요약
# fdisk n뉴파티션 -> p 프라이머리 -> defaults defaults -> 파티션 지정 +2G
t -> 파티션넘버 -> hexcode 82 -> w 저장아웃
# partprobe
# mkswap /dev/sde2
# swapon /dev/sde2
※ patprobe 관련 : 커널에서 변경사항을 인식 못하였을 때, 해당 명령어로 모든 변경사항을 검토하고 반영하게 된다. /dev/sr0 에서 경고문 발생은 CD-ROM 은 원래 읽기만 가능하기 때문에 경고창이 뜨는 것이다.
[root@localhost ~]# partprobe → 경고를 보지 않을려면 : [root@localhost ~]# partprobe /dev/sdb |