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

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

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

  • 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 명령으로 확인할 수 있다.
# 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
같은 카테고리의 다른 글

리눅스 / 절전 모드 진입 끄는 방법, 노트북 덮개 닫아도 켜져 있게 하는 방법

노트북에 리눅스를 설치했다. 노트북에 설치했지만 용도는 서버용. 그래서 항상 켜져 있어야 한다. 그런데 노트북의 특성인지 일정 시간이 지나면 절전 모드로 들어가고, 노트북 덮개를 닫으면 잠금(?) 상태가 된다. 그래서 서비스가 중지되거나 원격 연결이 되지 않는데... 항상 켜져 있게 하는 방법은 다음과 같다. 절전 모드 진입하기 않게 하는 방법 다음과 같이 명령하면 절전 모드가 해제된다. # ...

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

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

리눅스 / 배포판 / 수세 리눅스(SUSE Linux) - 역사, 특징, 장점

수세 리눅스의 역사 수세 리눅스(SUSE Linux)는 독일의 뉘른베르크에 본사를 두고 있는 SUSE 회사에 의해 개발된 리눅스 배포판입니다. SUSE는 "Software- und System-Entwicklung"의 약자로, "소프트웨어 및 시스템 개발"을 의미합니다. 초기 역사 SUSE 리눅스는 1992년에 설립되어, 처음에는 Slackware를 기반으로 한 리눅스 배포판을 제공했습니다. SUSE는 독일어권 지역을 중심으로 인기를 끌었으며, 이후 독자적인 리눅스 배포판을 개발하게 되었습니다. 노벨(Novell) 인수 2003년 ...

리눅스 / IP 확인하는 방법

리눅스에서 IP 주소를 확인하는 방법은 여러 가지가 있으며, 이를 수행하는 데 사용되는 명령어와 도구는 다음과 같습니다. 이 명령어들은 모두 터미널에서 실행됩니다. ip addr 아래 명령어를 실행하면 모든 네트워크 인터페이스의 상세 정보가 표시됩니다. IP 주소는 inet 항목에서 확인할 수 있습니다. # ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen ...

리눅스 / 명령어 / free / 메모리 사용량 확인하는 명령어

free는 메모리 사용량을 확인하는 명령어이다. free # free total used free shared buff/cache available Mem: ...

리눅스 / 명령어 / cd / 다른 디렉토리로 이동하는 명령어

cd는 change directory의 약자로, 다른 디렉토리로 이동하는 명령어이다. cd 현재 로그인한 사용자의 홈 디렉토리로 이동한다. 일반적으로 root 계정이라면 /root로, 사용자 jb 계정이라면 /home/jb로 이동한다. cd ~user user의 홈 디렉토리로 이동한다. 다음과 같이 명령하면 jb 사용자의 홈 디렉토리로 이동한다. # cd ~jb cd 디렉토리명 지정한 디렉토리로 이동한다. 절대경로, 상대경로 다 사용할 수 있다. 다음과 같이 명령하면 /etc 디렉토리로 이동한다. # cd /etc 현재 ...

리눅스 / 로그아웃 명령어, 재부팅 명령어, 종료 명령어

로그아웃 명령어 # logout # exit 재부팅 명령어 즉시 재부팅 # reboot # shutdown -r now # init 6 일정 시간 또는 일정 시간 후 재부팅 10분 후 재부팅 # shutdown -r 10 12시에 재부팅 # shutdown -r 12:00 취소 # shutdown -c 종료 명령어 즉시 종료 # poweroff # shutdown -h now # shutdown -P now # halt -p # init 0 일정 시간 또는 일정 시간 후에 종료 10분 후에 종료 # ...

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

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용한다. which 명령어로 find 명령어를 찾는다. # which find /usr/bin/find whereis 명령어로 find 명령어를 찾는다. # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz locate 명령어로 find 명령어를 찾는다. # 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 옵션으로 출력 ...

리눅스 - 오픈 소스의 선두 주자

리눅스 개요 리눅스(Linux)는 유닉스(Unix) 운영체제의 계열에 속하는 자유롭고 오픈 소스인 운영체제입니다. 리눅스 커널은 1991년 핀란드의 대학생이었던 리누스 토르발스(Linus Torvalds)에 의해 처음 개발되었으며, GNU 프로젝트의 일환으로 개발된 다양한 소프트웨어와 결합되어 완전한 운영체제를 구성합니다. 오늘날 리눅스는 서버, 데스크탑, 모바일 장치, 임베디드 시스템 등 다양한 플랫폼에서 널리 사용되고 있습니다. 리눅스의 역사 리눅스의 역사는 1991년으로 거슬러 올라갑니다. ...

리눅스 / 명령어 / cal / 달력을 출력하는 명령어

cal은 달력을 출력하는 명령어이다. 아무 옵션 없이 사용하면 현재 날짜가 속한 달의 달력을 출력한다. cal October 2022 Su Mo Tu We Th Fr Sa 1 2 3 4 5 ...