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

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

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

  • 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 22.04 Server / ZIP 압축 파일 푸는 방법

ZIP 파일을 압축 해제하기 위해서는 unzip 패키지가 필요하다. # apt install unzip xxx.zip 파일을 압축 해제하려면 다음과 같이 명령한다. # unzip xxx.zip 다음과 같이 명령하여 도움말을 볼 수 있다. # unzip -h 결과는 다음과 같다. UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP. Usage: unzip Default ...

Ubuntu 16.04 / SASS 설치하는 방법

우분투 16.04에 SASS를 설치하는 방법은 두 가지가 있습니다. 방법 1 apt install ruby-sass 방법 2 apt install ruby gem install sass 설치되었는지 확인하는 방법 sass -v SASS 버전이 출력되면 제대로 설치된 것입니다. Sass 3.4.23 (Selective Steve) 참고 최신 버전의 SASS를 사용하고 싶다면 방법 2로 설치합니다.

리눅스 / 명령어 / cat / 파일 내용 출력하는 명령어

리눅스의 cat(concatenate의 약자) 명령어는 파일의 내용을 화면에 출력하거나 파일을 결합하는 데 사용됩니다. cat 명령어는 주로 텍스트 파일을 다룰 때 유용하며, 여러 개의 파일을 한 번에 읽거나 결합할 수 있습니다. 다음과 같은 두 개의 파일이 있다고 할 때 file1 1-1 1-2 1-3 file2 2-1 2-2 2-3 cat filename cat 뒤에 파일 이름을 넣으면 파일 안의 내용을 보여줍니다. # cat file1 1-1 1-2 1-3 파일 이름을 연달아 넣으면 ...

리눅스 / 배포판 / 데비안(Debian) - 역사, 특징, 장점

데비안의 역사 데비안(Debian)은 자유 소프트웨어 재단의 리눅스 배포판으로 1993년에 이안 머독(Ian Murdock)에 의해 시작되었습니다. 데비안 프로젝트는 커뮤니티 기반의 오픈 소스 프로젝트로서, 전 세계의 개발자와 기여자들이 협력하여 발전시켜 왔습니다. 데비안은 GNU 프로젝트의 일환으로 시작되었으며, 현재는 리눅스 커널뿐만 아니라 다양한 커널을 지원하는 운영체제를 제공합니다. 초기 역사 1993년 8월 16일, 이안 머독은 데비안 프로젝트를 발표했습니다. 데비안의 ...

Ubuntu 16.04 Server / PHP / 메모리 늘리는 방법

PHP 설정은 php.ini에서 한다. Ubuntu 16.04에서 php.ini의 위치는 /etc/php/7.0/apache2/php.ini 이다. PHP 버전에 따라 7.0은 다른 숫자일 수 있다. 메모리를 늘리기 위해 수정해야 할 것은 memory_limit이다. 기본값은 128M이다. 128을 적절히 변경한다. memory_limit = 128M 변경한 설정이 적용되도록 하려면 웹서버를 다시 시작하거나 다시 로드한다. Apache 웹서버라면 다음과 같이 명령하여 다시 시작할 수 있고, # service apache2 restart 다음과 같이 ...

Ubuntu 20.04 Server / hostname 확인하는 방법, 변경하는 방법

Ubuntu 20.04 Server / hostname 확인하는 방법, 변경하는 방법

hostname 확인하는 방법 방법 1 - 명령어로 확인하기 다음과 같이 명령하면 hostname을 출력한다. hostname 방법 2 - 설정 파일 열어서 확인하기 /etc/hostname 파일에 hostname이 있다. cat /etc/hostname hostname 변경하는 방법 방법 1 - 명령어로 변경하기 다음과 같이 명령하면 hostname이 abc로 바뀐다. hostnamectl set-hostname abc 방법 2 - 설정 파일 열어서 변경하기 텍스트 에디터로 /etc/hostname 파일을 열어서 내용을 abc로 바꾸면 hostname이 abc로 바뀐다. 재부팅 재부팅을 하면 변경사항이 ...

Rocky Linux 9 / 설치

Rocky Linux 9 / 설치

다운로드 아래 링크에서 ISO 파일을 다운로드한다. https://rockylinux.org/download Boot, Minimal, DVD 세 가지가 있는데, 다음과 같이 설명되어 있다. Boot Used to install the operating system from another source (such as a HTTP repository of the binary files). Can also be used to enter Rescue Mode. Minimal Used to install the operating system from another source (such as a ...

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

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

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

리눅스 / chown, chmod / 파일 또는 디렉토리 소유자, 소유그룹, 권한 설정

chown과 chmod는 파일 및 디렉토리의 권한과 소유자를 관리하는 데 사용되는 Linux 명령어입니다. 정보 확인 ls 명령어에 -l 옵션을 붙여서 파일 또는 디렉토리의 권한과 소유자(그룹)을 확인할 수 있습니다. 제일 앞에 있는 문자는 디렉토리인지 파일인지는 나타냅니다. d는 디렉토리라는 뜻이고, -는 파일이라는 뜻입니다. 그 다음 3개의 문자열은 소유자의 권한을, 그 다음 3개의 문자열은 소유그룹의 권한을, 그 다음 ...