Physical / Logical 로 나뉨 : 작은 시스템에는 Physical partition으로 충분
Physical partioning은 label타입에 따라 DOS방식, GTP 방식이로 나뉨
# fdisk -l
or # lsblk
root@jsg-ubuntu:~# fdisk -l Disk /dev/sda: 20 GiB, 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 Disklabel type: dos Disk identifier: 0x2658b87a Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 39942143 39940096 19G 83 Linux /dev/sda2 39944190 41940991 1996802 975M 5 Extended /dev/sda5 39944192 41940991 1996800 975M 82 Linux swap / Solaris Disk /dev/sdb: 4 GiB, 4294967296 bytes, 8388608 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
# fdisk /dev/...
root@jsg-ubuntu:~# fdisk /dev/sdb Welcome to fdisk (util-linux 2.27.1). 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. Created a new DOS disklabel with disk identifier 0x059ba759. Command (m for help): m Help: ... Generic d delete a partition # 파티션 삭제 F list free unpartitioned space l list known partition types # 파티션 타입 목록 n add a new partition # 새로운 파티션 생성 p print the partition table # 현재 파티션 상태 출력 t change a partition type # 파티션 타입 변경 v verify the partition table i print information about a partition ... Save & Exit w write table to disk and exit # 변경된 사항 저장하고 종료 q quit without saving changes # 변경된 사항 저장하지 않고 종료 ...
Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p # primary partion으로 생성 Partition number (1-4, default 1): 1 # 1번 파티션 (/dev/sdb1) First sector (2048-8388607, default 2048): # 시작점 Last sector, +size{K,M,G,T,P} (2048-8388607, default 8388607): +2G # 끝점(+크기) Created a new partition 1 of type 'Linux' and of size 2 GiB. Command (m for help): p Disk /dev/sdb: 4 GiB, 4294967296 bytes, 8388608 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 Disklabel type: dos Disk identifier: 0x059ba759 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4196351 4194304 2G 83 Linux
Command (m for help): d Selected partition 1 Partition 1 has been deleted.
# mkfs -t fs_type device
or # mkfs.fs_type device
root@jsg-ubuntu:~# mkfs.ext4 /dev/sdb1 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 524288 4k blocks and 131072 inodes Filesystem UUID: 2dcf43d4-819c-40b2-9bd3-bf3c415c4a35 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
file system의 무결성을 확인
offline(unmount) 상태에서하는게 안전함
# fsck -t fs_type device
or # fsck.file_type device
root@jsg-ubuntu:~# fsck.ext4 /dev/sdb1 e2fsck 1.42.13 (17-May-2015) /dev/sdb1: clean, 11/131072 files, 25388/524288 blocks root@jsg-ubuntu:~# echo $? 0 # 0이면 정상
메모리 부족할 때 디스크의 도움 받을 수 있음
# mkswap -L label_name device
: 스왑 공간 생성
root@jsg-ubuntu:~# mkswap -L swapfs2 /dev/sdb2 mkswap: /dev/sdb2: warning: don't erase bootbits sectors (dos partition table detected). Use -f to force. Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) LABEL=swapfs2, UUID=c44f5b14-9bcc-4eca-89f9-13dff591f124
# swapon device
: 스왑 활성화
# swapoff device
: 스왑 비활성화
# cat /proc/swaps
: 스왑 공간 확인
root@jsg-ubuntu:~# cat /proc/swaps Filename Type Size Used Priority /dev/sda5 partition 998396 0 -2 /dev/sdb2 partition 1048572 0 -3
# findmnt
root@jsg-ubuntu:~# findmnt TARGET SOURCE FSTYPE OPTIONS / /dev/sda1 ext4 rw,relatime,errors=remo ├─/sys sysfs sysfs rw,nosuid,nodev,noexec, │ ├─/sys/kernel/security securityfs securit rw,nosuid,nodev,noexec, │ ├─/sys/fs/cgroup tmpfs tmpfs ro,nosuid,nodev,noexec, │ │ ├─/sys/fs/cgroup/systemd cgroup cgroup rw,nosuid,nodev,noexec, │ │ ├─/sys/fs/cgroup/memory cgroup cgroup rw,nosuid,nodev,noexec, │ │ ├─/sys/fs/cgroup/freezer cgroup cgroup ... ... └─/run/user/1000 tmpfs tmpfs rw,nosuid,nodev,relatim └─/run/user/1000/gvfs gvfsd-fuse fuse.gv rw,nosuid,nodev,relatim
# mount -t fs_type [-o option] device directory
root@jsg-ubuntu:~# mkdir /media/backup root@jsg-ubuntu:~# mount -t ext4 /dev/sdb1 /media/backup root@jsg-ubuntu:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 4G 0 disk ├─sdb2 8:18 0 1G 0 part [SWAP] └─sdb1 8:17 0 2G 0 part /media/backup # mount 됨 확인 sr0 11:0 1 1024M 0 rom sda 8:0 0 20G 0 disk ├─sda2 8:2 0 1K 0 part ├─sda5 8:5 0 975M 0 part [SWAP] └─sda1 8:1 0 19G 0 part /
# umount device
or # umount directory
root@jsg-ubuntu:~# umount /media/backup root@jsg-ubuntu:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 4G 0 disk ├─sdb2 8:18 0 1G 0 part [SWAP] └─sdb1 8:17 0 2G 0 part sr0 11:0 1 1024M 0 rom sda 8:0 0 20G 0 disk ├─sda2 8:2 0 1K 0 part ├─sda5 8:5 0 975M 0 part [SWAP] └─sda1 8:1 0 19G 0 part /
fuser -c[k] dir
로 PID 찾은후 kill 명령root@jsg-ubuntu:/media/backup# umount /media/backup umount: /media/backup: target is busy (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1).) root@jsg-ubuntu:/media/backup# fuser -c /media/backup /media/backup: 2657c
mount된 파티션의 옵션을 변경할 때
# mount -o remount,option device
root@jsg-ubuntu:~# mount -o remount,ro /dev/sdb1 root@jsg-ubuntu:~# findmnt TARGET SOURCE FSTYPE OPTIONS / /dev/sda1 ext4 rw,relatime,errors=remo ├─/sys sysfs sysfs rw,nosuid,nodev,noexec, │ ├─/sys/kernel/security securityfs securit rw,nosuid,nodev,noexec, ... └─/media/backup /dev/sdb1 ext4 ro,relatime,data=ordere
# mount --bind old_dir new_dir
: 하나의 디렉토리를 다른 디렉토리에 연결시킴부팅시 파일 시스템을 자동 마운트하기 위한 정보
device | mount point | fstype | options | dump | fsck |
---|---|---|---|---|---|
UUID=e65ee1... | / | ext4 | errors=remount-ro | 0 | 1 |
UUID=84970b... | none | swap | sw | 0 | 0 |
e2label device [new-label]
root@jsg-ubuntu:~# blkid /dev/sdb1 /dev/sdb1: LABEL="Study" UUID="2dcf43d4-819c-40b2-9bd3-bf3c415c4a35" TYPE="ext4" PARTUUID="059ba759-01"
tune2fs -U <clear|random|time|uuid_value> device
root@jsg-ubuntu:~# tune2fs -U $(uuidgen) /dev/sdb1 tune2fs 1.42.13 (17-May-2015) root@jsg-ubuntu:~# blkid /dev/sdb1 /dev/sdb1: LABEL="Study" UUID="9c4daae1-21b2-4619-8d02-db881a6fd4b3" TYPE="ext4" PARTUUID="059ba759-01"
findfs LABEL=label
or findfs UUID=uuid
root@jsg-ubuntu:~# findfs LABEL=Study /dev/sdb1 root@jsg-ubuntu:~# findfs UUID=9c4daae1-21b2-4619-8d02-db881a6fd4b3 /dev/sdb1
# blkid [device]
root@jsg-ubuntu:~# blkid /dev/sdb1 /dev/sdb1: LABEL="Study" UUID="9c4daae1-21b2-4619-8d02-db881a6fd4b3" TYPE="ext4" PARTUUID="059ba759-01"
root@jsg-ubuntu:~# cat /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # file_system mount_point type options dump pass UUID=e65ee146-aea7-418b-8946-8993e297d5a6 / ext4 errors=remount-ro 0 1 UUID=84970be2-9cd1-49c0-9f99-eec452cfccaa none swap sw 0 0 UUID=9c4daae1-21b2-4619-8d02-db881a6fd4b3 /media/backup ext4 defaults 0 1 root@jsg-ubuntu:~# lsblk # 컴퓨터 재실행시 자동 마운트 됨 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 4G 0 disk ├─sdb2 8:18 0 1G 0 part └─sdb1 8:17 0 2G 0 part /media/backup sr0 11:0 1 1024M 0 rom sda 8:0 0 20G 0 disk ├─sda2 8:2 0 1K 0 part ├─sda5 8:5 0 975M 0 part [SWAP] └─sda1 8:1 0 19G 0 part /
수동 mount 대신 자주 쓰임
일반 유저로 명령을 실행해야하고, 디렉토리를 자동 생성/삭제 해줌
$ udisksctl mount -b device
: 마운트
$ udisksctl unmount -b device
: 언마운트
$ udisksctl loop-setup --file XXX.iso
: 파일을 디바이스처럼 마운트
$ udisksctl status
: 장착된 장치 정보
$ udisksctl dump
or $ udisksctl info -d device
: 개별 장치 정보