본문 바로가기
HW 프로그래밍/라즈베리파이

라즈비안 외장하드 포맷 및 자동마운트

by N2info 2020. 2. 29.

1. 외장하드 포맷 및 마운트(언마운트후 포맷해야 함)

pi@raspberrypi:~ $ sudo mkfs.ext4 /dev/sda
mke2fs 1.44.5 (15-Dec-2018)
/dev/sda contains a ext4 file system
	last mounted on Sat Feb 29 16:21:13 2020
Proceed anyway? (y,N) y
Creating filesystem with 31258710 4k blocks and 7815168 inodes
Filesystem UUID: ee8dcf40-db20-44c7-a9d5-c66006a95cdf
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (131072 blocks): 
done
Writing superblocks and filesystem accounting information:        
done

pi@raspberrypi:~ $ 

2. 파티션(참조:https://paranwater.tistory.com/418)

위 명령에서 이어 계속 fdisk를 실행하고 있는 상태 입니다

Command (m for help): n                        <---- 새 파티션 생성 명령
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p                        <---- p타입으로 명령
Partition number (1-4, default 1): 1
First sector (2048-976773167, default 2048): 2048                        <---- 파티션 시작값을 적음
Last sector, +sectors or +size{K,M,G} (2048-976773167, default 976773167): 9767731                        <---- 피티션 끝 값을 적음

시작 값과 끝 값으로 용량이 정해 집니다

Command (m for help): n                        <---- 다시한번 새로운 파티션을 만드는 명령
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p                        <---- p타입으로 명령
Partition number (1-4, default 2): 2
First sector (9767732-976773167, default 9767732): 9767732                        <---- 두번째 파티션 시작 위치
Last sector, +sectors or +size{K,M,G} (9767732-976773167, default 976773167): 976773167                        <---- 두번째 파티션 끝나는 위치

Command (m for help): w                        <---- 저장 (fdisk종료됨)
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

root@raspberrypi:/#
pi@raspberrypi:~ $ sudo fdisk /dev/sda

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


Command (m for help): p
Disk /dev/sda: 119.2 GiB, 128035676160 bytes, 250069680 sectors
Disk model: Generic         
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: dos
Disk identifier: 0x1cd5629c

Device     Boot Start       End   Sectors   Size Id Type
/dev/sda1        2048 250069679 250067632 119.2G 83 Linux

Command (m for help): 

3. 자동 마운트

 /etc/fstab 에 마운트하는 추가해 주면 알아서 마운트가 된다고 해서 해 봤는데, 현실은 부팅이 안됨 ㅠㅠ

다시 알아봄(참조 : http://www.rasplay.org/?p=4854)

마운트된것을 확인하고, /etc/rc.local 파일을 아래와 같이 수정함

pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G  6.3G   22G  23% /
devtmpfs        459M     0  459M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M  6.3M  457M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   53M  200M  21% /boot
/dev/sda1       117G   61M  111G   1% /home/pi/SDD
tmpfs            93M     0   93M   0% /run/user/1000
pi@raspberrypi:~ $ cd dev/sda1
bash: cd: dev/sda1: 그런 파일이나 디렉터리가 없습니다
pi@raspberrypi:~ $ cd /dev/sda1
bash: cd: /dev/sda1: 디렉터리가 아닙니다
pi@raspberrypi:~ $ cd /home/pi/SDD
pi@raspberrypi:~/SDD $ ls
lost+found
pi@raspberrypi:~/SDD $ sudo nano /etc/rc.local
pi@raspberrypi:~/SDD $ 
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

# ADD

sudo mount /dev/sda1 /home/pi/SDD
 
exit 0

재부팅하니 잘 잡힘