harumaki.net

インフラ屋の覚書や、ラーメン食べある記とか。

GNU/Linux infra

USB接続HDDのマウント(Linux)

投稿日:2009年10月4日

Last Updated on 2012年12月28日 by かんりにん

久しぶりにパーティション切ってフォーマットしようとしたら
やり方を忘れてしまっていた…
たまにしかやらないので手順を忘れやすい為、メモしとく(自分用にw)。

OS
CentOS5.*系
つなげたサーバー
HPのDLシリーズ
使用HDD
職場のマシンルームに余っていた未使用のIDE 250GB (メーカーはWD)
やったこと
IDEのHDDをUSB接続のHDDケースに入れてサーバーへ接続。そしてローカルディスクのデータをバックアップ。

 ディスク自体はIDEだけど、サーバーへの接続はUSBなので
 /dev/hd*ではなく/dev/sd*で認識されたw 当然転送速度は遅いw

作業順序

  • 1)フォーマット(fdisk)
  • 2)ファイルシステム作成(mkfs.ext3)
  • 3)マウント
      →完成!

手順

1)フォーマット(fdisk)

1-1.デバイス確認

#  fdisk -l
Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes
255 heads, 63 sectors/track, 8920 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
	
	           Device Boot      Start         End      Blocks   Id  System
	/dev/cciss/c0d0p1   *           1          13      104391   83  Linux
	/dev/cciss/c0d0p2              14        8920    71545477+  8e  Linux LVM
	
Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
	
Disk /dev/sda doesn't contain a valid partition table

1-2.該当ディスクをフォーマット

#  fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 30401.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

メッセージをなんとなく待ちつつ、fdisk終了。

1-3.パーティションテーブルを確認

Command (m for help): p

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

上記のように、現時点では何もない。

1-4.領域を作成

基本領域か拡張領域を選択。
今回は基本領域4にした。

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p					←基本領域を選択するので"p"を入力
Partition number (1-4): 4		←基本領域の"4"を指定
First cylinder (1-30401, default 1): 1	←開始シリンダーを"1"に指定
Last cylinder or +size or +sizeM or +sizeK (1-30401, default 30401): 30401	←終了シリンダーを30401に指定

1-5.設定した領域を確認

あらためてオプションpを入力。

Command (m for help): p

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot       Start          End         Blocks    Id  System
   /dev/sda4               1       30401   244196001   83  Linux

先ほど設定したパーティション番号とシリンダー設定が反映されている。

1-6.設定した領域を書き込み。

Command (m for help): w		←"w"を入力して適用。
The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.
#

上記にてフォーマット終了。

1-7.パーティション状態を確認。

ディスク/dev/sdaの下にパーティション/dev/sda4が認識されていることを確認。

#  fdisk -l

Disk /dev/cciss/c0d0: 73.3 GB, 73372631040 bytes
255 heads, 63 sectors/track, 8920 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d0p1   *           1          13      104391   83  Linux
/dev/cciss/c0d0p2              14        8920    71545477+  8e  Linux LVM

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda4               1       30401   244196001   83  Linux

2)ファイルシステム作成(mkfs.ext3)

つづけてファイルシステムext3を適用。
コマンド"mkfs.ext3"にてパーティションを指定し、実行したら後は待つだけ。

#  mkfs.ext3 /dev/sda4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
30539776 inodes, 61049000 blocks
3052450 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
1864 block groups		←フォーマット中はここがカウントされるので、お茶をしながら待つ。
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
#

上記で完了。

3)マウント

/mnt以下にusb1ディレクトリを作成し、ここに/dev/sda4をマウントさせる。

3-1./mntディレクトリを確認

#  ls -al /mnt/
total 16
drwxr-xr-x  2 root root 4096 Mar 30  2007 ./
drwxr-xr-x 23 root root 4096 Oct  2  2009 ../

3-2.マウントポイントとしてディレクトリusb1を作成

#  mkdir usb1

3-3./dev/sda4を/mnt/usb1へマウント

#  mount -t ext3 /dev/sda4 /mnt/usb1/

3-4.マウント確認

  • mountコマンドにて確認
    #  mount
    /dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
    proc on /proc type proc (rw)
    sysfs on /sys type sysfs (rw)
    devpts on /dev/pts type devpts (rw,gid=5,mode=620)
    /dev/cciss/c0d0p1 on /boot type ext3 (rw)
    tmpfs on /dev/shm type tmpfs (rw)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    /dev/sda4 on /mnt/usb1 type ext3 (rw)
  • dfコマンドにて確認
#  df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      67323516  61743796   2104676  97% /
/dev/cciss/c0d0p1       101086     15931     79936  17% /boot
tmpfs                  1037040         0   1037040   0% /dev/shm
/dev/sda4            240362656    191772 227961084   1% /mnt/usb1
#

上記にてUSB HDDを利用可能に。
最後に/etc/fstabにマウントポイントを追記し、OS起動時に自動でマウントされるよう
設定を行っておくとよい
(が、ブート中にマウントさせると起動が遅くなる、ということもあるので、テストしてからが吉)。

-GNU/Linux, infra

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


関連記事

no image

smtp-sink

smtp-sink(テスト環境) † smtpのテストツール。postfixのパッケージに含まれている。 MTA経由でメールやSMTPメッセージを受け取り、そのまま破棄する。 配信数を測 …

no image

インフラ運用の心得:最低限やっておくこと

インフラ運用に最低限やっておくこと † 以下の整備については、呼吸するのと同じくらい当たり前のこととしてやっておくこと。 もちろん必要以上のコストはかけない前提で。 必要と感じたことは都 …

no image

mysql sshトンネリングでの暗号化接続をさくっと試す

リモートホストのMySQLサーバーへアクセスする際に、クライアント – サーバー間の通信を暗号化する方法をかるく検証。 (MySQLのDBスキーマやテーブルの暗号化ではない) 方法としては …

[AWS]s3-tools(s3cmd)のインストールと検証

EC2上のDB→S3バケットへのダンプファイルの転送にて、s3fs以外のものでも試してみよう、ということで 今日はs3-toolsのテストを。 インスタンスはAmazon Linux AMI、ラージイ …

no image

ssh ホストベース認証(メモ)

概要 パスワード/パスフレーズなしでSSHログインできるよう、ホストベース認証を設定する方法。 ↑ クライアント側(接続元)設定 ホストベースでの外部ホストへの接続を許可するため /etc/ …