리눅스 / 하드디스크 파디션 만들기, 포맷하기, 마운트하기

리눅스에서 하드디스크 파티션 만들고, 포맷 하고, 마운트 하는 방법을 요약한다.

장착된 하드디스크 확인하기

  • ls 명령어로 컴퓨터에 장착된 하드디스크 정보를 출력할 수 있다.
  • /dev/sda, /dev/sdb 등이 하드디스크, /dev/sda1 등이 파티션이다.
# ls -l /dev/sd*
brw-rw----. 1 root disk 8,  0 Oct 16 13:12 /dev/sda
brw-rw----. 1 root disk 8,  1 Oct 16 13:12 /dev/sda1
brw-rw----. 1 root disk 8,  2 Oct 16 13:12 /dev/sda2
brw-rw----. 1 root disk 8, 16 Oct 16 13:12 /dev/sdb
brw-rw----. 1 root disk 8, 32 Oct 16 13:12 /dev/sdc
  • 파일시스템은 df -T 또는 blkid /dev/sd*로 확인할 수 있다. 마운트하지 않는 파티션에 대한 정보까지 알고 싶다면 후자를 사용한다.

파티션 만들기

  • 파티션을 관리하는 명령어는 fdisk이다.
  • /dev/sdb의 파티션을 관리하고 싶다면 다음과 같이 명령한다.
fdisk /dev/sdb

  • 도움말이 필요하면 m을 입력한다.

  • 새 파티션은 n을 입력하고 안내에 따라 만든다.

  • w를 입력해야 변경사항이 반영된다.

2TB 초과 하드디스크 파티션 만들기

2TB를 초과하는, 예를 들어 4TB 하드디스크를 장착하고 파티션을 만들려고 하면 다음과 같은 메시지를 보게 되고, 전체 디스크를 사용할 수 없다.

The size of this disk is 4 TiB (4398046511104 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

이런 경우 g를 입력하여 GPT partition table을 만든 후 파티션을 만든다.

Command (m for help): g
Created a new GPT disklabel (GUID: F13C6D0D-1E30-4448-B015-A61F3AE9EA48).

포맷하기

  • 포맷하는 명령어는 mkfs이다.
  • 예를 들어 /dev/sdb1 파티션을 ext4 파일 시스템으로 포맷하려면 다음과 같이 명령한다.
mkfs.ext4 /dev/sdb1
  • 예를 들어 /dev/sdb1 파티션을 xfs 파일 시스템으로 포맷하려면 다음과 같이 명령한다.
mkfs.xfs -f /dev/sdb1

  • NTFS 파일 시스템으로 포맷하고 싶다면 mkntfs 명령어를 사용한다.
mkntfs -f /dev/sdb1
  • 파일 시스템은 df -T 또는 blkid /dev/sd*로 확인할 수 있다. 마운트하지 않는 파티션에 대한 정보까지 알고 싶다면 후자를 사용한다.

마운트하기

  • 파티션을 특정 디렉토리에 연결해야 그 파티션을 사용할 수 있다.
  • 예를 들어 /dev/sdb1을 /home 디렉토리에 마운트하려면 다음과 같이 명령한다.
mount /dev/sdb1 /home
  • 마운트를 해제할 때는 umount 명령어를 사용한다.
umount /dev/sdb1

  • 부팅 시 자동으로 마운트되도록 하려면 /etc/fstab 파일에 다음과 같은 코드를 추가한다. /dev/sdb1 파티션을 /home 폴더에 마운트하라는 뜻이다. 파일 시스템 등 옵션은 적절히 변경한다.
/dev/sdb1 /home xfs defaults 0 0
  • fstab 파일의 변경 내용을 바로 적용하고 싶다면 다음과 같이 명령한다.
mount -a

UUID 사용하기

  • 하드디스크에 /dev/sdb 같은 이름이 붙고, 파티션에는 /dev/sdb1 같은 이름이 붙는데, 이 이름이 고정된 것은 아니다. 하드디스크 장착 위치를 바꾸거나, 인식 순서가 바뀌면 그 이름도 바뀐다. 그런 경우 마운트가 제대로 되지 않을 수 있다. 그래서 마운트를 할 때는 하드디스크 고유값인 UUID를 사용하는 것이 좋다.
  • UUID는 blkid 명령으로 확인할 수 있다.
[root@localhost ~]# blkid
/dev/sda1: UUID="69d9add5-2153-4bc2-ad99-1560fb205c4b" TYPE="ext4" PARTUUID="aa61ba4b-01"
/dev/sda2: UUID="PuMuNg-5YHg-qikJ-tc10-iPIM-7W1q-4fUqyc" TYPE="LVM2_member" PARTUUID="aa61ba4b-02"
/dev/mapper/cl-root: UUID="79c8cfcb-c9e2-4243-8cf2-cf10eab57c40" TYPE="xfs"
/dev/mapper/cl-swap: UUID="b69a5fc3-98db-4a27-b3d4-a7ef76244ad1" TYPE="swap"
/dev/mapper/cl-home: UUID="fd372a6b-ee76-41d6-b7e6-6e6a7cf8193b" TYPE="xfs"
/dev/sdb1: UUID="fd95c93f-03fc-418a-a6db-c26b921ec93b" TYPE="xfs" PARTUUID="e5f55ef6-01"
  • /etc/fstab에 마운트 정보를 넣을 때
/dev/sdb1 /home xfs defaults 0 0
  • 대신 다음처럼 한다.
UUID=fd95c93f-03fc-418a-a6db-c26b921ec93b /home xfs defaults 0 0

같은 카테고리의 다른 글

리눅스 / 그룹 / 그룹 조회, 그룹 추가, 그룹 삭제, 그룹 수정

리눅스 / 그룹 / 그룹 조회, 그룹 추가, 그룹 삭제, 그룹 수정

그룹 조회 그룹 목록은 /et/group 파일에 있습니다. cat 명령어로 전체를 조회하거나... cat /etc/group tail 명령어로 마지막 부분을 조회할 수 있습니다. # tail -n 5 /etc/group avahi:x:70: slocate:x:21: rngd:x:974: tcpdump:x:72: vboxsf:x:973: X:Y:Z 형식으로 나오는데, X는 그룹 이름, Y는 그룹 비밀번호, Z는 그룹 ID입니다. 그룹 추가 groupadd 명령으로 그룹을 추가합니다. # groupadd group-1 # tail -n 5 /etc/group slocate:x:21: rngd:x:974: tcpdump:x:72: vboxsf:x:973: group-1:x:1000: 그룹 삭제 groupdel 명령으로 그룹을 삭제합니다. # ...

리눅스 / 사용자 / 사용자 조회, 사용자 추가, 사용자 삭제, 사용자 수정

리눅스 / 사용자 / 사용자 조회, 사용자 추가, 사용자 삭제, 사용자 수정

사용자 조회 모든 사용자를 출력합니다. # cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin ... root과 useradd 또는 adduser를 통해 생성한 사용자 계정을 출력합니다. # grep /bin/bash /etc/passwd root:x:0:0:root:/root:/bin/bash jb:x:1000:1000:JB:/home/jb:/bin/bash 사용자 추가 useradd jb 사용자를 만듭니다. useradd jb 사용자 홈 디렉토리도 같이 만들고 싶다면 -d 옵션을 사용합니다. useradd jb -d /home/jbdir jb 사용자의 비밀번호를 만듭니다. passwd jb adduser adduser 명령어로 사용자를 추가할 수 있습니다. useradd와는 달리 사용자 홈 디렉토리를 자동으로 만들고, 비밀번호 ...

리눅스 / 명령어 / ls / 디렉토리와 파일 목록 출력하는 명령어

리눅스 / 명령어 / ls / 디렉토리와 파일 목록 출력하는 명령어

ls는 list의 약어로, 디렉토리와 파일 목록을 출력하는 명령어이다. ls 디렉토리명 디렉토리에 속한 디렉토리와 파일 목록을 출력한다. 숨김 파일은 나오지 않는다. 디렉토리명을 생략하면 현재 디렉토리에 속한 디렉토리와 파일 목록을 출력한다. 예를 들어 다음과 같이 명령하면 /var 디렉토리에 속한 디렉토리와 파일 목록을 출력한다. ls /var ls -a, ls -l -a 옵션을 붙이면 숨김 파일도 출력한다. -l 옵션을 붙이면 소유자, 파일 크기 ...

리눅스 / RAID / Linear RAID, RAID0, RAID1, RAID5, RAID6

리눅스 / RAID / Linear RAID, RAID0, RAID1, RAID5, RAID6

RAID 뜻과 종류 RAID Redundant Array of Inexpensive Disk or Redundant Array of Independent Disk 여러 개의 하드디스크를 하나처럼 사용하게 하는 기술. 예를 들어 1TB 하드디스크 두 개를 묶어서 2TB 하드디스크처럼 사용할 수 있다. 크게 하드웨어 RAID와 소프트웨어 RAID로 구분할 수 있다. 하드웨어 RAID는 성능이 좋으나 비싸다. 소프트웨어 RAID는 운영체제에서 지원하는 것으로 OS RAID라고도 한다. Linear RAID 두 ...

리눅스 / 명령어 / find / 파일 또는 디렉토리를 찾는 명령어

리눅스 / 명령어 / find / 파일 또는 디렉토리를 찾는 명령어

find는 파일 또는 디렉토리를 찾는 명령어입니다. 자주 사용하는 옵션 등을 정리해봅니다. find 현재 디렉토리 안에 있는 모든 파일과 디렉토리를 출력합니다. 숨긴 파일 또는 숨긴 디렉토리도 출력합니다. find /etc /etc 디렉토리 안에 있는 모든 파일과 디렉토리를 출력합니다. 숨긴 파일 또는 숨긴 디렉토리도 출력합니다. find -name abc 현재 디렉토리 안에서 이름이 abc인 파일 또는 abc인 디렉토리를 검색합니다. find -name ...

리눅스 / 명령어 / rdate / 타임서버의 시간과 동기화해주는 명령어

리눅스 / 명령어 / rdate / 타임서버의 시간과 동기화해주는 명령어

rdate는 서버의 시간과 타임서버의 시간을 동기화해주는 명령어입니다. rdate는 설치되어있지 않는 경우가 많으므로, 필요하다면 설치를 해야 합니다. CentOS라면 yum install rdate Ubuntu라면 apt install rdate 와 같이 명령하여 설치할 수 있습니다. 타임서버의 시간을 확인할 때는 -p 옵션을 사용합니다. 현재 서버의 시간을 변경하지 않습니다. rdate -p time.bora.net 현재 서버의 시간을 타임서버의 시간으로 맞출 때에는 -s 옵션을 붙입니다. rdate -s time.bora.net CentOS ...

리눅스 / 명령어 / touch / 빈 파일 만들기, 최종 수정 시간 변경하기

리눅스 / 명령어 / touch / 빈 파일 만들기, 최종 수정 시간 변경하기

touch는 빈 파일 만들거나 파일의 최종 수정 시간을 현재 시간으로 바꾸는 명령어입니다. touch abc.txt abc.txt 파일이 없다면, 내용이 없는 abc.txt 파일을 만듭니다. abc.txt 파일이 있다면, 파일의 최종 수정 시간을 현재로 변경합니다.

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있습니다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용합니다. 각 명령어로 find 명령어를 찾아보겠습니다. # which find /usr/bin/find # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz # locate find /usr/bin/find /usr/bin/find2perl /usr/bin/findmnt /usr/bin/nl-link-ifindex2name /usr/bin/nl-link-name2ifindex /usr/bin/oldfind /usr/lib64/python2.7/modulefinder.py /usr/lib64/python2.7/modulefinder.pyc /usr/lib64/python2.7/modulefinder.pyo /usr/sbin/btrfs-find-root /usr/sbin/findfs /usr/share/bash-completion/completions/findmnt /usr/share/doc/findutils-4.5.11 /usr/share/doc/findutils-4.5.11/AUTHORS /usr/share/doc/findutils-4.5.11/COPYING /usr/share/doc/findutils-4.5.11/ChangeLog /usr/share/doc/findutils-4.5.11/NEWS /usr/share/doc/findutils-4.5.11/README /usr/share/doc/findutils-4.5.11/THANKS /usr/share/doc/findutils-4.5.11/TODO /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_find.py /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_stop_find.py /usr/share/info/find-maint.info.gz /usr/share/info/find.info.gz /usr/share/locale/be/LC_MESSAGES/findutils.mo /usr/share/locale/bg/LC_MESSAGES/findutils.mo /usr/share/locale/ca/LC_MESSAGES/findutils.mo /usr/share/locale/cs/LC_MESSAGES/findutils.mo /usr/share/locale/da/LC_MESSAGES/findutils.mo /usr/share/locale/de/LC_MESSAGES/findutils.mo /usr/share/locale/el/LC_MESSAGES/findutils.mo /usr/share/locale/eo/LC_MESSAGES/findutils.mo /usr/share/locale/es/LC_MESSAGES/findutils.mo /usr/share/locale/et/LC_MESSAGES/findutils.mo /usr/share/locale/fi/LC_MESSAGES/findutils.mo /usr/share/locale/fr/LC_MESSAGES/findutils.mo /usr/share/locale/ga/LC_MESSAGES/findutils.mo /usr/share/locale/gl/LC_MESSAGES/findutils.mo /usr/share/locale/hr/LC_MESSAGES/findutils.mo /usr/share/locale/hu/LC_MESSAGES/findutils.mo /usr/share/locale/id/LC_MESSAGES/findutils.mo /usr/share/locale/it/LC_MESSAGES/findutils.mo /usr/share/locale/ja/LC_MESSAGES/findutils.mo /usr/share/locale/ko/LC_MESSAGES/findutils.mo /usr/share/locale/lg/LC_MESSAGES/findutils.mo /usr/share/locale/lt/LC_MESSAGES/findutils.mo /usr/share/locale/ms/LC_MESSAGES/findutils.mo /usr/share/locale/nl/LC_MESSAGES/findutils.mo /usr/share/locale/pl/LC_MESSAGES/findutils.mo /usr/share/locale/pt/LC_MESSAGES/findutils.mo /usr/share/locale/pt_BR/LC_MESSAGES/findutils.mo /usr/share/locale/ro/LC_MESSAGES/findutils.mo /usr/share/locale/ru/LC_MESSAGES/findutils.mo /usr/share/locale/rw/LC_MESSAGES/findutils.mo /usr/share/locale/sk/LC_MESSAGES/findutils.mo /usr/share/locale/sl/LC_MESSAGES/findutils.mo /usr/share/locale/sr/LC_MESSAGES/findutils.mo /usr/share/locale/sv/LC_MESSAGES/findutils.mo /usr/share/locale/tr/LC_MESSAGES/findutils.mo /usr/share/locale/uk/LC_MESSAGES/findutils.mo /usr/share/locale/vi/LC_MESSAGES/findutils.mo /usr/share/locale/zh_CN/LC_MESSAGES/findutils.mo /usr/share/locale/zh_TW/LC_MESSAGES/findutils.mo /usr/share/man/man1/find.1.gz /usr/share/man/man1/find2perl.1.gz /usr/share/man/man1/oldfind.1.gz /usr/share/man/man8/btrfs-find-root.8.gz /usr/share/man/man8/findfs.8.gz /usr/share/man/man8/findmnt.8.gz locate 명령어는 -n 옵션으로 출력 개수를 정할 수 있습니다. # locate ...

리눅스 / 게이트웨이(gateway) 확인하는 방법

리눅스 / 게이트웨이(gateway) 확인하는 방법

리눅스에서 네트워크 정보는 주로 ifconfig, ip addr 명령어로 확인합니다. 그런데, gateway 정보는 나오지 않습니다. 만약 gateway 정보가 필요하다면 route 명령어를 사용합니다.

리눅스 / 명령어 / man / 명령어의 설명서 출력하는 명령어

리눅스 / 명령어 / man / 명령어의 설명서 출력하는 명령어

man은 manual의 약어로, 명령어의 설명서를 출력하는 명령어입니다. man 뒤에 명령어 이름을 넣고 엔터를 누릅니다. 예를 들어 man rm 은 rm 명령어의 설명서를 출력합니다. ↑키를 누르면 한 줄 위로 올라가고, ↓키를 누르면 한 줄 아래로 내려갑니다. Page Up 키를 누르면 한 페이지 위로 올라가고, Page Down 키를 누르면 한 페이지 아래로 내려갑니다. /를 누르고 단어를 입력하면 ...