外付けHDD の入れ替え手順


このドキュメントにはgrey に接続されてある外付けHDD を入れ替える際の 手順(方法)が記載されてある

1 入れ替え用のHDD の準備

HDD を他の計算機(ex. 情報実験機)に接続し, format する. 接続したHDD がsd? であるかを確認する.

  # dmesg | less
 

パーティションを切る

  # fdisk /dev/sd?
 
	Welcome to fdisk (util-linux 2.25.2).
	Changes will remain in memory only, until you decide to write them.
	Be careful before using the write command.

	Command (m for help): m (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
	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

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

	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): n (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-3907029167, default 2048): 2048
	Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167):
	Using default value 3907029167

	Command (m for help): w (w で書き込み)

	The partition table has been altered!

	Calling ioctl() to re-read partition table.
	Syncing disks.

HDD のフォーマット(5.5h ほどかかった(2 TB HDD))

  # mke2fs -c -t ext4 /dev/sd?1
 

HDD の容量, ファイルシステム等の確認

  # fdisk -l /dev/sd?
 
	Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
	81 heads, 63 sectors/track, 765633 cylinders, total 3907029168 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: 0xecee9b89

	Device Boot      Start         End      Blocks   Id  System
	/dev/sda1            2048  3907029167  1953513560   83  Linux

パーティションにラベルをつける(home.bk)

  # tune2fs -L home.bk /dev/sd?1
 

ラベル名の確認

  # tune2fs -l /dev/sd?1 | grep "Filesystem volume name"
 

2. grey に接続してバックアップをとる

grey を停止させて/home/ /home.bk にバックアップをとる

現行の/home または/home.bk でI/O エラーが出ていないか確認 (起きていたらバックアップは後日行う)

  # dmesg | grep sd
 

wall コマンドでログインしている一般ユーザに警告

  # wall
 
	This system will shutdown at ??:??
	Please logout
	(書き終わったら [Ctrl] + [D] キーを押す.)

ログインしているユーザを強制的にログアウト

  # who
  # ps aux | grep [who で分かったアカウント名]

ユーザログインのプロセスを強制的にkill する

  # kill -KILL PID

ネットワーク線を抜き, サーバで提供しているサービス(qmail,dovecot)を停止

  # service qmail stop
  # service dovecot stop

/home と/home.bk を同期するため, /etc/cron.daily/rsync を実行

  # /etc/cron.daily/rsync

メモリバッファをディスクと同期(数回実行)

  # sync

念のため, シャットダウン前に/etc/cron.daily/rsync の実行権限を落とす (boot 直後に/etc/cron.daily/rsync が走って万が一のことが起こるのを防ぐため)

  # chmod -x /etc/con.daily/rsync

シャットダウン

  # halt -p

サーバシャットダウン後, 現行の/home.bk を切り離し, 1 で作成した仕込み済みの新たなHDD に挿げ替える.

grey をブートさせ, 新しく付け替えたディスクが認識されているか確認 (正しくラベル付けと/etc/fstab が書かれていれば, 新しく付け替えたディスクが/home.bk で認識されるはず)

  # df -h
	/dev/sdc1        902G  4.2G  852G    1% /
	udev              10M     0   10M    0% /dev
	tmpfs            1.6G   33M  1.6G    3% /run
	tmpfs            4.0G     0  4.0G    0% /dev/shm
	tmpfs            5.0M     0  5.0M    0% /run/lock
	tmpfs            4.0G     0  4.0G    0% /sys/fs/cgroup
	/dev/sdd1        917G  4.2G  867G    1% /bk
	/dev/sdb1        1.8T  210G  1.5T   13% /home
	/dev/sda1        1.8T  210G  1.5T   13% /home.bk

/, /sys-bk, /home, /home.bk が全て認識されているか確認したら(容量などもチェック), rsync を実施(本実行する前にdry run, オプションだと -n をつけると実行時の動作だけ を表示してくれる.)

  # date >> /var/log/rsync-log/home.log
  # rsync -avn --delete --exclude lost+found /home/ /home.bk/ >> /var/log/rsync-log/home.log 2>&1
  # echo "$n" >> /var/log/rsync-log/home.log

/var/log/rsync-log/home.log を参照し, 問題ないようであれば本実行

  # /etc/cron.daily/rsync

rsync 実行後, df コマンドで容量などを確認(/home と /home.bk の 容量がおおよそ同じであれば OK)

  # df -h

rsync 終了後, /etc/cron.daily/rsync の実行権限を復活させておく

  # chmod +x /etc/cron.daily/rsync

最終更新日:2016/02/02 (三上峻) Copyright (C) 2000-2016 EPnetFaN