우분투(Ubuntu) 홈서버 구축기(3) - 외장하드 마운트

Wondeok Kang (a.k.a. Wade)·2022년 4월 2일
0
post-thumbnail

1. 외장하드 마운트

미니 PC를 통해 서버 구성중 하드 용량 240 GB로는 부족한 감이 있어 집에 굴러다니던 500GB SSD 외장하드를 추가적으로 마운트 하기로 결정했다. 우선 연결하고 정상적으로 인식하는지 확인해본다.

root@deogicorgi-server:~# fdisk -l

Disk /dev/loop0: 55.33 MiB, 58007552 bytes, 113296 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop1: 54.98 MiB, 57626624 bytes, 112552 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop2: 70.58 MiB, 73990144 bytes, 144512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop3: 29.9 MiB, 31334400 bytes, 61200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop4: 29.91 MiB, 31342592 bytes, 61216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop5: 71.28 MiB, 74735616 bytes, 145968 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 223.58 GiB, 240057409536 bytes, 468862128 sectors
Disk model: Maxtor Z1 SSD 24
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: C3476B60-B041-4794-9918-0A65775AE3F0

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   1050623   1048576   512M EFI System
/dev/sda2  1050624 468858879 467808256 223.1G Linux filesystem


Disk /dev/sdb: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: USB3.0
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

2. fdisk로 드라이브 설정

가장 아래 /dev/sdb 로 정상적으로 인식하는 것이 보인다. fdisk 로 진입하여 적절한 작업을 진행해준다. 나의 경우 d를 이용하여 해당 볼륨을 삭제 후 n을 이용하여 새로운 파티션 추가, g를 이용하여 디스크 라벨을 리눅스용으로 설정했다. 작업이 완료되면 w를 입력해 저장하고 종료한다.

root@deogicorgi-server:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xb283705a.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help):

3. 포맷 & 마운트

다음으로 할 작업은 리눅스에서 안정적으로 사용하기위해 외장하드를 ext4형식으로 포맷하는 작업이다.

root@deogicorgi-server:~# mkfs.ext4 /dev/sdb

포맷이 완료되면 외장하드를 마운트해보자. 이때 재부팅 시에도 계속적으로 마운트가 유지되게 하기 위하여 fstab설정 또한 진행한다. 우선 해당 디스크의 UUID를 확인하기 위해 blkid 를 입력한다.

root@deogicorgi-server:~# blkid

/dev/sda1: UUID="B530-A397" TYPE="vfat" PARTUUID="22f5feb0-6eb3-4ae9-a7cf-7edf784fe7ae"
/dev/sda2: UUID="4ebae7c5-ece5-4173-aeec-79c7eb70378c" TYPE="ext4" PARTUUID="0667659c-f523-4cb6-b5b1-b070e2839443"
/dev/sdb: UUID="7344afee-255e-4cde-8080-16c92898d314" TYPE="ext4"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"

위의 정보를 보면 연결한 외장하드/dev/sdb의 UUID를 확인할 수 있다. 이 UUID를 복사해놓는다. 마운트 설정 시 사용할 것이다.
아래의 명령어로 fstabvi 편집기로 열어서 아래의 내용을 추가한다.

root@deogicorgi-server:~# vi /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/4ebae7c5-ece5-4173-aeec-79c7eb70378c / ext4 defaults 0 0
# /boot/efi was on /dev/sda1 during curtin installation
/dev/disk/by-uuid/B530-A397 /boot/efi vfat defaults 0 0
/swap.img       none    swap    sw      0       0

# 아래 부분 추가 형식은 다음과 같다.
# UUID=[UUID값] [실제 마운트할 디렉토리] [파티션포맷] defaults 0 0

UUID=7344afee-255e-4cde-8080-16c92898d314 /storage ext4 auto,user,rw 0 0

나의 경우 해당 디렉토리를 root 뿐만 아니라 모든 사용자가 사용할 예정이기 때문에 defaults 가 아닌 auto, user, rw로 설정했다. 저장 후 df 명령어로 현재 마운트 된 현황을 확인하면 /dev/sdb가 /storage로 정상적으로 마운트 된 것을 확인할 수 있다.

root@deogicorgi-server:~# df

Filesystem     1K-blocks    Used Available Use% Mounted on
udev             2964008       0   2964008   0% /dev
tmpfs             608128    1368    606760   1% /run
/dev/sda2      229183852 9151380 208320884   5% /
tmpfs            3040632       0   3040632   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs            3040632       0   3040632   0% /sys/fs/cgroup
/dev/sda1         523248    7944    515304   2% /boot/efi
/dev/sdb       479670976  262340 454972924   1% /storage
/dev/loop1         56320   56320         0 100% /snap/core18/1880
/dev/loop0         56704   56704         0 100% /snap/core18/1885
/dev/loop3         30720   30720         0 100% /snap/snapd/8542
/dev/loop2         72320   72320         0 100% /snap/lxd/16922
/dev/loop4         30720   30720         0 100% /snap/snapd/8790
/dev/loop5         73088   73088         0 100% /snap/lxd/16099
overlay        229183852 9151380 208320884   5% /var/lib/docker/overlay2/f902b8656327ba93f862fdc683afeb58d434a89f42cb341d2061f8ea028f741f/merged
tmpfs             608124       0    608124   0% /run/user/1000
profile
최고의 개발도구는 기록과 구글링이다.

0개의 댓글