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

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

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

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

리눅스 / rsync / 동기화 프로그램

rsync는 동기화 프로그램이다. 백업할 때 유용하게 사용할 수 있다. 사용법 기본 abc 디렉토리 안의 def 디렉토리를 xyz 디렉토리 안에 동기화시킨다. 처음 실행하는 것이라면 xyz 디렉토리 안에 def 디렉토리가 복사된다. 다시 실행시키면 /abc/def 디렉토리의 내용 중 수정되거나 추가된 것만 /xyz/def 디렉토리로 복사된다. /abc/def에서 삭제된 내용은 /xyz/def에 반영되지 않는다. # rsync -avz /abc/def /xyz def 뒤에 /를 붙이면 def 디렉토리 ...

CentOS 7 / hostname 확인하고 변경하는 방법

CentOS 7 / hostname 확인하고 변경하는 방법

명령어 이용하기 hostname 확인 다음과 같이 명령하면 hostname을 출력한다. hostname hostname 변경 다음과 같이 명령하면 hostname을 abc로 변경한다. hostnamectl set-hostname abc 설정 파일 이용하기 hostname 확인 hostname 설정 파일은 /etc/hostname이다. 그 파일을 열거나 다음과 같이 명령하여 설정 파일의 내용을 볼 수 있다. cat /etc/hostname hostname 변경 텍스트 편집기로 열면 한 줄의 코드가 있는데, 그것이 hostname이다. 그 코드를 바꾸고 저장하면 hostname이 변경된다. 변경 사항 ...

CentOS 7 / Let’s Encrypt에서 무료 SSL 인증서 발급 받는 방법

CentOS 7 / Let’s Encrypt에서 무료 SSL 인증서 발급 받는 방법

CentOS 7에서 Let’s Encrypt 인증서를 발급 받는 방법을 요약합니다. 환경 CentOS 7 Apache Web Server 설치 저장소 추가 yum install epel-release 설치 yum install python-certbot-apache 인증서 발급 abc.com 인증서 발급 certbot --apache -d abc.com abc.com과 www.abc.com 인증서 동시 발급 certbot --apache -d abc.com -d www.abc.com 인증서 갱신 Let’s Encrypt 인증서는 90일마다 갱신해야 합니다. certbot renew

Ubuntu 24.04 Server / SSH / 포트 변경하는 방법

보안 등의 이유로 SSH 포트를 변경해야 한다면, 다음과 같이 한다. /etc/ssh/sshd_config에서 다음의 코드를... #Port 22 다음으로 변경한다. Port 1980 방화벽이 활성화되어 있다면 1980 포트를 열어준다. ufw allow 1980/tcp SSH 서비스를 다시 시작한다. systemctl restart ssh SSH 서비스를 다시 시작해도 적용되지 않으면, 컴퓨터를 다시 시작한다.

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

리눅스 / crontab 사용법

cron & crontab cron은 특정 시간에 특정 작업을 수행하게 하는 시스템 대몬이다. 백업, 캐시 메모리 비우기 등 주기적으로 어떤 작업을 해야할 때 유용하다. crontab은 시간과 작업을 적은 텍스트 파일이다. 사용자별로 파일이 존재한다. cron은 모든 사용자의 crontab 파일을 찾아서, 적혀진 일정대로 작업을 수행한다. 작업 목록 보기 예약 작업 목록을 보고 싶다면 다음과 같이 명령한다. 사용자의 crontab ...

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

리눅스에서 네트워크 정보는 주로 ifconfig, ip addr 명령어로 확인한다. 그런데, gateway 정보는 나오지 않는다. 만약 gateway 정보가 필요하다면 route 명령어를 사용한다. Ubuntu애서 명령어가 없다고 나오면 net-tools를 설치한다. apt install net-tools

Ubuntu 14.04 / LESS 설치하는 방법

우분투 14.04에 LESS를 설치하는 방법을 메모합니다. Node.js 설치 apt-get install nodejs NPM 설치 apt-get install npm LESS 설치 npm install -g less less-plugin-clean-css /usr/local/bin/lessc 파일 첫 줄에 다음과 같은 코드가 있습니다. #!/usr/bin/env node 다음처럼 바꿉니다. #!/usr/bin/env nodejs

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 방화벽을 사용 중이라면 다음과 같이 명령하여 포트를 ...

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