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

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

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

  • 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
같은 카테고리의 다른 글

Ubuntu Server 22.04 / vsftpd로 FTP 서버 구축하기

vsftpd vsftpd(Very Secure FTP Daemon)는 유닉스와 리눅스에서 사용할 수 있는 가벼운 FTP 서버입니다. 주요 특징은 다음과 같습니다. Virtual IP configurations Virtual users Standalone or inetd operation Powerful per-user configurability Bandwidth throttling Per-source-IP configurability Per-source-IP limits IPv6 Encryption support through SSL integration 설치 vsftpd는 우분투 패키지에 포함되어 있으므로 다음과 같이 명령하여 설치할 수 있습니다. # apt install vsftpd 방화벽을 사용 중이라면 다음과 같이 명령하여 포트를 ...

리눅스 / 커널

리눅스 커널은 리눅스 운영체제의 핵심 구성 요소로, 시스템 하드웨어와 소프트웨어 간의 중재자 역할을 합니다. 커널은 시스템 자원을 관리하고, 프로세스 간의 통신을 지원하며, 기본적인 보안과 안정성을 제공합니다. 리눅스 커널은 자유 소프트웨어 및 오픈 소스 소프트웨어 개발 및 배포 모델에 따라 개발됩니다. 리눅스 커널의 주요 기능 프로세스 관리 프로세스 생성 및 종료 : 커널은 새로운 ...

Ubuntu 18.04 Server / Nginx, PHP, MariaDB 설치하고 설정하기

Ubuntu 18.04 Server / Nginx, PHP, MariaDB 설치하고 설정하기

Nginx 설치 Nginx를 설치합니다. # apt install nginx 만약 방화벽을 사용하고 있다면 포트를 열어줍니다. # ufw allow 'Nginx Full' 서버 주소로 접속했을 때 다음과 같이 나오면 제대로 된 것입니다. 시작, 정지 등 Nginx를 시작합니다. # systemctl start nginx Nginx를 멈춥니다. # systemctl stop nginx Nginx를 재시작합니다. # systemctl restart nginx Nginx를 다시 로드합니다. # systemctl reload nginx Nginx를 설치하면 부팅 시 자동으로 시작하게 설정됩니다. 만약 자동 ...

Rocky Linux 9 / Apache, PHP, MariaDB 설치

Rocky Linux 9 / Apache, PHP, MariaDB 설치

Rocky Linux 9에 Apache, PHP, MariaDB를 설치하는 방법을 정리합니다.

CentOS / 버전 확인하는 방법

CentOS / 버전 확인하는 방법

cat /etc/redhat-release # cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) cat /etc/*release* # cat /etc/*release* CentOS Linux release 7.4.1708 (Core) Derived from Red Hat Enterprise Linux 7.4 (Source) NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" CentOS Linux release 7.4.1708 (Core) CentOS Linux release 7.4.1708 (Core) cpe:/o:centos:centos:7

CentOS 8 / Squid로 Proxy Server 만드는 방법

CentOS 8 / Squid로 Proxy Server 만드는 방법

리눅스로 프록시 서버(Proxy Server)를 만들 때 스퀴드(Squid)를 주로 사용합니다. 오픈 소스이고, 대부분의 리눅스 배포판에 패키지로 포함되어 있습니다. 스퀴드(squid)는 대중적인 오픈 소스(GPL)소프트웨어 프록시 서버이자 웹 캐시이다. 반복된 요청을 캐싱함으로 웹서버의 속도를 향상시키는 것부터, 네트워크 자원을 공유하려는 사람들에게 웹, DNS와 다른 네트워크 검색의 캐싱을 제공하고, 트래픽을 걸러줌으로써 안정성에 도움을 주는 등에 이르기까지 광범위 ...

Ubuntu 18.04 Server / apt / 패키지 설치, 삭제, 업그레이드하는 명령어

Ubuntu에서 패키지를 관리하는 명령어는 여러 가지가 있습니다. 그 중 널리 사용되는 것은 apt-get과 apt입니다. 아래는 apt를 이용하여 패키지를 설치하고 삭제하고 업그레이드하는 방법입니다. 대부분의 경우 apt-get을 사용해도 작동합니다. APT 사용법 패키지 목록을 갱신합니다 # apt update 모든 패키지를 최신 버전으로 업그레이드합니다. # apt upgrade abc 패키지를 설치합니다. 의존성있는 패키지도 함께 설치합니다. # apt install abc abc 패키지를 삭제합니다. 설정 ...

리눅스 / 명령어 / alias / 명령어 별칭 만들기

긴 명령어 또는 복잡한 명령어를 자주 사용한다면 alias를 사용하자. 시간을 많이 절약할 수 있다. alias 목록 보기 alias를 실행하면 현재 등록된 alias를 출력한다. alias 예를 들어 ll을 실행한다는 것은 ls -alF를 실행하는 것과 같다. alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto' alias grep='grep --color=auto' alias l='ls -CF' alias la='ls -A' alias ll='ls -alF' alias ls='ls --color=auto' alias 만들기 alias는 다음과 같이 만든다. abc를 실행하는 ...

CentOS 8 / 원격 데스크톱으로 연결하는 방법

CentOS 8 / 원격 데스크톱으로 연결하는 방법

서버용으로 CentOS를 사용하는 경우 보통 Minimal로 설치하고, 원격 접속은 SSH로 한다. 하지만 하드웨어 사양이 좋아지고 사용의 편리함으로 GUI(Graphical User Interface)를 설치하는 경우도 많아지고 있다. GUI가 설치되어 있다면 SSH보다는 원격 데스크톱으로 관리하는 게 편하다. CentOS에 원격 데스크톱으로 접속하는 방법을 알아본다. 패키지 설치 다음과 같이 명령하여 EPEL(Extra Packages of Enterprise Linux) 저장소를 추가한다. yum install ...

리눅스 / 명령어 / 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 옵션으로 출력 ...