본문 바로가기

blog/scrap

ubuntu hdd 추가 - 자동 마운트

반응형

ubuntu hdd 추가 - 자동 마운트 (재부팅 자동 적용)

 

출처 : [출처] ubuntu hdd 추가|작성자 핑크토끼

 

스크랩에 본문과 다르게 재부팅하고 바로 적용이 안되어 확인해보니
$ sudo mount -a
위 명령어를 한번 하고 난 뒤로는 자동으로 마운트가 되었습니다.

 

HDD를 물리적으로 추가하였는데, Ubuntu에서 자동으로 붙지 않는다.

USB 같은 것은 자동으로 잘 잡아주면서... 이거 왠지 사용자 친화적이지 않다.

그래서, CLI로 추가 작업을 진행해주어야 한다.

1. HDD 잘 인식하는지 확인하기

- HDD 관련 작업은 fdisk 명령어로 대부분 처리할 수 있다.

$ sudo fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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 identifier: 0x00089aab
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 100663295 50330624 83 Linux
/dev/sda2 100665342 104855551 2095105 5 Extended
/dev/sda5 100665344 104855551 2095104 82 Linux swap / Solaris
Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders, total 419430400 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 identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table

- /dev/sda 는 잘 연결되어 있고, /dev/sdb는 물리적으로만 잘 붙어있다는 것을 확인할 수 있다.

- 친절히 제일 마지막 줄에 파티션 테이블도 안만들어져 있다고 알려주고 있다.

2. 파티션 작업

- 앞에서 찾아낸 작업해야할 HDD를 지정해서 파티션 작업을 진행하면 된다.

$ sudo fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb9110add.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-419430399, default 2048): (enter)
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): (enter)
Using default value 419430399
Command (m for help): p
Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders, total 419430400 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 identifier: 0xb9110add
Device Boot Start End Blocks Id System
/dev/sdb1 2048 419430399 209714176 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

- 각자의 상황에 따라 위와 같이 출력되지 않거나 다른 옵션을 선택해야할 경우도 있을 것이다.

- 일단은 필자의 상황으로 설명을 하도록 하겠다. 다양한 옵션에 대한 설명은 생략!

3. 포맷

- 파티션 작업을 했다고 바로 사용할 수는 없다. 포맷을 하고 사용해야 한다. 파일시스템을 만들어주는 과정이다.

$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13107200 inodes, 52428544 blocks
2621427 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1600 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
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 (32768 blocks): done
Writing superblocks and filesystem accounting information: done

- ext4가 아닌 다른 파일시스템을 사용할 사람은 바꾸면 된다.

4. UUID 확인

- 앞에서 붙인 HDD를 다루기 위해서는 고유의 값인 UUID를 알아야 한다.

$ ls -l /dev/disk/by-uuid/
합계 0
lrwxrwxrwx 1 root root 10 6월 22 18:22 29f6905f-be40-4321-b7c0-7658f2cb4c3e -> ../../sdb1
lrwxrwxrwx 1 root root 10 6월 22 18:06 822b2062-39d1-4ba3-ab4d-fdc332fec050 -> ../../sda5
lrwxrwxrwx 1 root root 10 6월 22 18:06 94200076-d0b4-4dea-97d4-ee5bedc01bf5 -> ../../sda1

5. mount 등록

- 방금 만든 파티션은 지금 접근해서 사용할 수는 없다. 파티션을 마운트(mount) 해주어야 사용할 수가 있는 것이다.

- 하지만, 한 번만 사용할 것이 아니라 매번 부팅할 때마다 마운트 되는 것이 필요하다.

$ sudo mkdir /srv/repository

- 마운트 하고자 하는 경로의 디렉토리를 미리 만들어 두자.

$ sudo nano /etc/fstab

...
UUID=29f6905f-be40-4321-b7c0-7658f2cb4c3e /srv/repository ext4 errors=remount-ro 0 1

- 부팅 時 자동으로 마운트할 내용을 위와 같이 적어주면 된다.

$ sudo mount -a

- 재부팅하지 않아도 마운트 시킬 수 있다.

$ sudo chown hp14:hp14 /srv/repository

- 권한은 마운트 뒤에 설정해주면 적용된다.

6. 확인

- 잘 붙었는지 확인해보자.

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 48G 11G 35G 24% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 991M 4.0K 991M 1% /dev
tmpfs 201M 900K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1002M 76K 1001M 1% /run/shm
none 100M 40K 100M 1% /run/user
/dev/sdb1 197G 60M 187G 1% /srv/repository

여기까지 하면 끄~~읕

 

반응형