리눅스에서 USB 스토리지 장치를 편하게 사용하기

코너리의 이미지

리눅스에서 USB 스토리지 장치를 편하게 사용하기

1. Hotplug 를 이용한 자동 마운트

USB 장치가 연결되면 event가 발생하고, /etc/hotplug/usb.agent가 동작한다.
usb.agent는 /proc/bus/usb 및 /sys/bus/usb 를 검사하여 어떤 장치가 연결되었는지 조사하고 필요한 모듈을 올린다. (hotplug.functions 의 load_drivers 함수 이용 )

load_drivers 함수에서는 장치 정보 db인 usb.*map, modules.usbmap 파일을 읽어 해당 모듈들을 로딩하고, /etc/hotplug/$TYPE/$MODULE 을 실행시키는데, 여기서 TYPE은 usb, MODULE은 usb-storage 가 된다.

결국 usb 스토리지 장치의 경우 /etc/hotplug/usb/usb-storage 파일이 실행되므로, 자동으로 마운트하고자 할 경우에는 이 파일을 작성하면 되겠다.

chmod 755 usb-storage ; 물론 실행가능해야 한다.

#!/bin/sh
#
# /etc/fstab 설정에 따라 /mnt/usb에 마운트
mount /mnt/usb

위 코드는 간단하게 작성되었지만, 실제 usb 장치 디바이스 (예를 들면 /dev/sda)에 대한 정보를 얻을 수 없으므로, 이를 알아내는 작업을 추가하면 좋을 것이다.

/sys/bus/usb/drivers/usb-storage/장치/bInterfaceClass 번호(Major 번호)와 bInterfaceNumber (Miner 번호) 정도를 얻어 /proc/partitions 정보와 비교하면 장치 디바이스를 알아낼 수 있다.

2. Automount 사용하기

관련패키지 : autofs
설정디렉토리 : /etc/auto.*

실제 메인 정보는 /etc/auto.master 에 있다. 다른 파일은 이 파일에 지정된 서브 설정파일이다.

auto.master 파일의 포맷은 다음과 같다.

# auto.master
# 마운트 포인트   서브 설정파일 
/misc/            /etc/auto.misc

auto.misc 맵 파일의 예는 다음과 같다.

# auto.misc
# 키       옵션                                   장치
cd         -fstype=iso9660,ro,nosuid,nodev        :/dev/cdrom
usb        -fstype=auto,iocharset=cp949           :/dev/sda

실제 마운트 되는 위치는 '/misc/키' 이고, 해당 디렉토리로 이동하거나 ls 등으로 목록을 얻는등의 접근이 이뤄질때 바로 마운트되고 60초동안 사용이 없으면 umount 된다.
[/code]

Forums: 

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.