|
|
当サイトは、玄箱PRO (KURO-BOX/Pro)を中心とした組み込み、Linuxと電子工作を扱っています。
会社案内
情報セキュリティおよび個人情報の取り扱いについて コメントとトラックバックは、spamを予防するために、編集担当が公開の作業をするまで非公開になっています。コメントはそれぞれ投稿した人のものです。 |

usb 2-1.4: new high speed USB device using ehci_platform and address 6 scsi2 : SCSI emulation for USB Mass Storage devices usb-storage: device found at 6 usb-storage: waiting for device to settle before scanning Vendor: WDC WD10 Model: EACS-00ZJB0 Rev: 1B01 Type: Direct-Access ANSI SCSI revision: 02 SCSI device sdb: 1953525168 512-byte hdwr sectors (1000205 MB) sdb: assuming drive cache: write through SCSI device sdb: 1953525168 512-byte hdwr sectors (1000205 MB) sdb: assuming drive cache: write through sdb: unknown partition table Attached scsi disk sdb at scsi2, channel 0, id 0, lun 0 Attached scsi generic sg1 at scsi2, channel 0, id 0, lun 0, type 0 usb-storage: device scan completeこれを見ると sdb として認識されたことがわかります。したがってデバイス・ファイルとしては /dev/sdb です。シリアル・コンソールに現れたメッセージを見るのを忘れたといったときには、dmesg コマンドと tail コマンドを組み合わせて使うとよいでしょう。
dmesg | tailを実行すると、
kurobox@kurobox:~$ dmesg | tail Vendor: WDC WD10 Model: EACS-00ZJB0 Rev: 1B01 Type: Direct-Access ANSI SCSI revision: 02 SCSI device sdb: 1953525168 512-byte hdwr sectors (1000205 MB) sdb: assuming drive cache: write through SCSI device sdb: 1953525168 512-byte hdwr sectors (1000205 MB) sdb: assuming drive cache: write through sdb: unknown partition table Attached scsi disk sdb at scsi2, channel 0, id 0, lun 0 Attached scsi generic sg1 at scsi2, channel 0, id 0, lun 0, type 0 usb-storage: device scan complete kurobox@kurobox:~$のようになります。tail コマンドはファイル(標準入力)の最後の部分だけを標準出力に出力するコマンドです。もちろん、tail コマンドではなく、less などページャを使って調べてもかまいません。
fdisk /dev/sdbとします。実行には、root の権限が必要なので、 su コマンドで root になるか、root でログインします。間違ったディスクを指定すると誤って重要なディスクのパーティション情報を壊してしまうことになるので、実行には十分に注意してください。
kurobox:/home/kurobox# fdisk /dev/sda 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) 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/sda1 1 7 56196 83 Linux /dev/sda2 8 373 2939895 83 Linux /dev/sda3 374 390 136552+ 82 Linux swap / Solaris /dev/sda4 391 30401 241063357+ 83 Linux Command (m for help): q kurobox:/home/kurobox#1から4番目の各領域の開始と終了のシリンダ番号、ブロックの大きさ、パーティション情報がわかります。つぎに購入したての新しい HDD に対して実行してみると以下のようになりました。
kurobox:/home/kurobox# fdisk /dev/sdb 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 121601. 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) 28Command (m for help): p Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System Command (m for help):まったくパーティション情報がないことがわかります。
kurobox:/home/kurobox# fdisk /dev/sdb 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 121601. 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)pコマンドで、現在のパーティション情報を確認してみます。
Command (m for help): p Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System新品のディスクなのでパーティション情報がありません。m でメニュー(コマンド)を確認してみます。
Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)n コマンドでパーティションを作成してみます。
Command (m for help): n ←入力 Command action e extended p primary partition (1-4) p ←入力 Partition number (1-4): 1 ←入力 First cylinder (1-121601, default 1): ←入力 Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601): 7 ←入力質問に答える形で、プライマリ・パーティション (p), パーティション番号 (1), 開始シリンダ (リターンのみでデフォルトの1を選択), 終了シリンダ (7) を入力しています。玄箱PROの場合はパーティション番号 1 には起動用のカーネルを保存しています。次のパーティションを作ります。
Command (m for help): n ←入力 Command action e extended p primary partition (1-4) p ←入力 Partition number (1-4): 2 ←入力 First cylinder (8-121601, default 8): ←入力 Using default value 8 Last cylinder or +size or +sizeM or +sizeK (8-121601, default 121601): 2800M ←入力プライマリ・パーティション (p), パーティション番号 (2), 開始シリンダ (リターンのみでデフォルトの8を選択), パーティションのサイズ (2800M) を入力しています。玄箱PROの場合はパーティション番号 2 は / パーティションに利用しています。次のパーティションを作ります。失敗したと思ったら、dコマンドでパーティションを削除します。
Command (m for help): d ←入力 Partition number (1-4): 2 ←入力 Command (m for help): p ←入力 Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 7 56196 83 Linuxもう一度パーティションを作ります。
Command (m for help): n ←入力 Command action e extended p primary partition (1-4) p ←入力 Partition number (1-4): 2 ←入力 First cylinder (8-121601, default 8): ←入力 Using default value 8 Last cylinder or +size or +sizeM or +sizeK (8-121601, default 121601): +3000M ←入力 Command (m for help): p ←入力 Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 7 56196 83 Linux /dev/sdb2 8 373 2939895 83 Linuxプライマリ・パーティション (p), パーティション番号 (2), 開始シリンダ (リターンのみでデフォルトの8を選択), パーティションのサイズ (3000M) を入力しています。3000M は約 3GB です。さらに二つのパーティションを作ります。パーティション3はスワップに 128MB 確保し、残り全部を /home に確保しています。
Command (m for help): n ←入力 Command action e extended p primary partition (1-4) p ←入力 Partition number (1-4): 3 ←入力 First cylinder (374-121601, default 374): ←入力 Using default value 374 Last cylinder or +size or +sizeM or +sizeK (374-121601, default 121601): +128M ←入力 Command (m for help): p ←入力 Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 7 56196 83 Linux /dev/sdb2 8 373 2939895 83 Linux /dev/sdb3 374 390 136552+ 83 Linux Command (m for help): n ←入力 Command action e extended p primary partition (1-4) p ←入力 Selected partition 4 First cylinder (391-121601, default 391): ←入力 Using default value 391 Last cylinder or +size or +sizeM or +sizeK (391-121601, default 121601): ←入力 Using default value 121601 tコマンドで /dev/sdb3 のパーティション・タイプを Linux swap に変更します。 Command (m for help): t ←入力 Partition number (1-4): 3 ←入力 Hex code (type L to list codes): 82 ←入力 Changed system type of partition 3 to 82 (Linux swap / Solaris)最後に確認します。
Command (m for help): p ←入力 Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 7 56196 83 Linux /dev/sdb2 8 373 2939895 83 Linux /dev/sdb3 374 390 136552+ 82 Linux swap / Solaris /dev/sdb4 391 121601 973627357+ 83 Linuxよければ w コマンドで書き込みます。
Command (m for help): w ←入力 The partition table has been altered! Calling ioctl() to re-read partition table. SCSI device sdb: 1953525168 512-byte hdwr sectors (1000205 MB) sdb: assuming drive cache: write through sdb: sdb1 sdb2 sdb3 sdb4 SCSI device sdb: 1953525168 512-byte hdwr sectors (1000205 MB) sdb: assuming drive cache: write through sdb: sdb1 sdb2 sdb3 sdb4 Syncing disks. kurobox:/home/kurobox#書き込みが終わると fdisk も終了します。もちろん、USB 外付けデータ・ディスクとして利用するときには、パーティションは一つだけしか作成しなくてもかまいません。
mkfs.ext3 /dev/sdb1 mkfs.ext3 /dev/sdb2 mkswap /dev/sdb3 mkfs.ext3 /dev/sdb43番目のパーティションだけ、swap パーティションなので利用するコマンドが違います。fdisk でパーティションを一つだけ作成したときには、そのパーティションだけ初期化します。
を実行すると、確保される領域が 2,000,000 ブロック (512bytes/ブロック) = 約 1GBになります。現在の値は、
tune2fs -r 2000000 /dev/sdb4
tune2fs -m /dev/sdb4を実行すると確認できます。
kurobox:/home/kurobox# mkdir /mnt2/ ←入力/dev/sda1, /dev/sdb1 をマウントします。
kurobox:/home/kurobox# mount /dev/sda1 /mnt ←入力 kjournald starting. Commit interval 5 seconds EXT3 FS on sda1, internal journal EXT3-fs: mounted filesystem with ordered data mode. kurobox:/home/kurobox# mount /dev/sdb1 /mnt2 ←入力 kjournald starting. Commit interval 5 seconds EXT3 FS on sdb1, internal journal EXT3-fs: mounted filesystem with ordered data mode.次に tar でコピーしました。tar を使うことで、パーミッションなどの情報を保ってコピーができます。昔からのテクニックです。/mnt がコピー元、/mnt2 がコピー先のディレクトリです。
kurobox:/home/kurobox# cd /mnt ←入力 kurobox:/mnt# tar cf - . | (cd /mnt2; tar xpf -) ←入力tar でコピーするのではなく、cp -a を使ってもかまいません。
cp -a . /mnt2/
kurobox:/mnt# cd / ←入力 kurobox:/# umount /mnt /mnt2 ←入力同様に / パーティションをコピーします。/ パーティション (/dev/sda2) はマウントされているので、 /dev/sdb2 のみマウントします。
kurobox:/# mount /dev/sdb2 /mnt ←入力 kjournald starting. Commit interval 5 seconds EXT3 FS on sdb2, internal journal EXT3-fs: mounted filesystem with ordered data mode.必要なディレクトリだけを指定してコピーします。
kurobox:/# tar cf - bin boot dev etc initrd lib media mtd opt root sbin srv tmp usbflash usr var | (cd /mnt; tar xpf -) ←入力警告が多少出ますが、無視します。コピーしなかったディレクトリは作成します。以下を実行するとよいでしょう。
mkdir /mnt/home /mnt/mnt /mnt/sys /mnt/proc /mnt/tmp chmod 1777 /mnt/tmp umount /mnt最後に /home (/dev/sda4) をコピーしました。
kurobox:/# mount /dev/sdb4 /mnt ←入力 kjournald starting. Commit interval 5 seconds EXT3 FS on sdb4, internal journal EXT3-fs: mounted filesystem with ordered data mode. kurobox:/# cd /home/ ←入力 kurobox:/home# tar cf - . | (cd /mnt; tar xpf -) ←入力この状態で電源を切り、USB HDD ケースからディスクを取り出し、玄箱PROに内蔵して電源を入れ起動すればディスクの入れ替えは終了です。なお玄箱PROの場合は不要ですが、PC でディスクを入れ替えたときにはブート領域(MBR: Master Boot Record)の書き換えも必要です。
このブログ記事を参照しているブログ一覧: 玄箱PROのハードディスク交換
このブログ記事に対するトラックバックURL: http://www.eleki-jack.com/mt/mt-tb.cgi/1716
おすすめ書籍 |
![]() |
コメントする