D ドライブをバックアップする(自分用メモ)

WindowsマシンのD ドライブ(1TB HDD)がそろそろ古くなってきたので、1TB SSDに換装しました。あまりやらないことなので、自分用に手順を記録しておくことにします。記事自体は長く見えますが、作業ログを垂れ流してるだけなので実質的な内容は少ないです。(昔作った手順書をよくわからずになぞってるので、意味不明なことをしているかもしれません。)

※なお、Cドライブ(起動ドライブ)をバックアップするときの手順とは細かいところが違うのでこの記事は参考になりません。

準備:
1. 裸族のお立ち台(でもなんでもいいですが手軽なやつが望ましい)に新しいSSDをセットする
2. ubuntu usb をPCに刺して起動する(usbから起動するとHDDにインストールするかい?みたいな事を聞かれますが「試すだけ」みたいなのを選択しましょう)。usb からの起動をするときに、F11だったりF8だったり、なんかのキーを押すことになるかもしれません。
3. terminal を立ち上げます。以降、terminal での作業になります。

ubuntu@ubuntu:~$ sudo fdisk -l

Disk /dev/sda: 300.1 GB, 300069052416 bytes
255 heads, 63 sectors/track, 36481 cylinders, total 586072368 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: 0xfb95cd73

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sda2          206848   586070015   292931584    7  HPFS/NTFS/exFAT

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1953521663   976759808    f  W95 Ext'd (LBA)
/dev/sdb5            4096  1953521663   976758784    7  HPFS/NTFS/exFAT

Disk /dev/sdc: 1024.2 GB, 1024209543168 bytes
255 heads, 63 sectors/track, 124519 cylinders, total 2000409264 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/sdc doesn't contain a valid partition table

■解説■
fdisk はディスク管理のコマンドです。ここでは Disk /dev/sda, Disk /dev/sdb, Disk /dev/sdc の3つのディスクについてそれぞれの詳細が表示されていることだけ理解できれば良いです。sda や sdb という名前は ubuntu がつけた名前で、Windowsのドライブレターとは対応していません。よって、上の情報から対応を読み取らねばなりません。

1.sda の箇所を見ると
Device Boot (略)
/dev/sda1 * (略)
となっていますが、Boot の下に*があることから sda はCドライブであることがわかります。
2.sdc の Disk identifier が 0x00000000 であることから、ブランクメディアであることがわかります。
3.よって残る sdb が D ドライブとなります。

ubuntu@ubuntu:~$ sudo dd if=/dev/sdb of=/dev/sdc bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00141734 s, 361 kB/s

■解説■
MBRをコピーしました。今回はDドライブをそのまま複製したいので、パーティション情報もそのまま受け継ぐわけです。このあと、fdisk で /dev/sdc を編集していきます。

ubuntu@ubuntu:~$ sudo fdisk /dev/sdc
Warning: ignoring extra data in partition table 5
Warning: ignoring extra data in partition table 5
Warning: ignoring extra data in partition table 5
Warning: invalid flag 0xfffe of partition table 5 will be corrected by w(rite)

■解説■
以降、しばらく fdisk の対話モードに入ります

Command (m for help): p #パーティションの情報を表示する

Disk /dev/sdc: 1024.2 GB, 1024209543168 bytes
255 heads, 63 sectors/track, 124519 cylinders, total 2000409264 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: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  1953521663   976759808    f  W95 Ext'd (LBA)
/dev/sdc5   ?  3385380806  6838131599  1726375397   c2  Unknown

Command (m for help): d #現在のパーティションを削除する
Partition number (1-5): 1

Command (m for help): p #パーティションの情報を表示する

Disk /dev/sdc: 1024.2 GB, 1024209543168 bytes
255 heads, 63 sectors/track, 124519 cylinders, total 2000409264 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: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n #新しいパーティションを作成する
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): e #Dドライブなので拡張領域を選択する
Partition number (1-4, default 1): 1
First sector (2048-2000409263, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2000409263, default 2000409263): 
Using default value 2000409263

Command (m for help): p  #パーティションの情報を表示する

Disk /dev/sdc: 1024.2 GB, 1024209543168 bytes
255 heads, 63 sectors/track, 124519 cylinders, total 2000409264 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: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  2000409263  1000203608    5  Extended

Command (m for help): n #新しいパーティションを作成する
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l #論理パーティションを作成する
Adding logical partition 5
First sector (4096-2000409263, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-2000409263, default 2000409263): 
Using default value 2000409263

Command (m for help): p #パーティションの情報を表示する

Disk /dev/sdc: 1024.2 GB, 1024209543168 bytes
255 heads, 63 sectors/track, 124519 cylinders, total 2000409264 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: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  2000409263  1000203608    5  Extended
/dev/sdc5            4096  2000409263  1000202584   83  Linux

Command (m for help): t #パーティションのタイプを変更する(sdc5 が Linux になってるのでNTFSに修正したい)
Partition number (1-5): 5  #sdc5 を変更したいので「5」を選択する
Hex code (type L to list codes): l 

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 < 3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list codes): 7 #NTFSに対応する hex コードを上の一覧から判断して選択する
Changed system type of partition 5 to 7 (HPFS/NTFS/exFAT)

Command (m for help): p #パーティションの情報を表示する

Disk /dev/sdc: 1024.2 GB, 1024209543168 bytes
255 heads, 63 sectors/track, 124519 cylinders, total 2000409264 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: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  2000409263  1000203608    5  Extended
/dev/sdc5            4096  2000409263  1000202584    7  HPFS/NTFS/exFAT

Command (m for help): w #変更を保存して fdisk の対話モードを終了する
The partition table has been altered!

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

■解説■
以上で、/dev/sdc にDドライブの内容をコピーする準備が整ったはずです。一応確認してみます。

ubuntu@ubuntu:~$ sudo fdisk -l

Disk /dev/sda: 300.1 GB, 300069052416 bytes
255 heads, 63 sectors/track, 36481 cylinders, total 586072368 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: 0xfb95cd73

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      206847      102400    7  HPFS/NTFS/exFAT
/dev/sda2          206848   586070015   292931584    7  HPFS/NTFS/exFAT

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  1953521663   976759808    f  W95 Ext'd (LBA)
/dev/sdb5            4096  1953521663   976758784    7  HPFS/NTFS/exFAT

Disk /dev/sdc: 1024.2 GB, 1024209543168 bytes
183 heads, 63 sectors/track, 173511 cylinders, total 2000409264 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: 0xfb95cd6c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  2000409263  1000203608    5  Extended
/dev/sdc5            4096  2000409263  1000202584    7  HPFS/NTFS/exFAT

■解説■
今気づいたのですが、sdc1 を f にし忘れてますね。起動時に警告されたわけだ^^;

ubuntu@ubuntu:~$ sudo dd if=/dev/sdb1 of=/dev/sdc1
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.00076339 s, 1.3 MB/s
ubuntu@ubuntu:~$ sudo dd if=/dev/sdb5 of=/dev/sdc5

■解説■
sdb1 を sdc1 に、sdb5 を sdc5 に、それぞれ dd します。後者は非常に時間がかかります。
そこで、別のteminalを開いて
root@ubuntu:/home/ubuntu$ sudo watch -n 100 "pkill -USR1 dd"
のようにして監視してやると、どのくらい進んだか100秒毎に示してくれるので便利です。(pkillはプロセスを殺すためにも使えますが、ここではプロセスへのシグナル送信に使っています。)

さて、今回の作業では sdb が1000.2 GBで、sdc が1024.2 GBなので24GBの余りがあります。このままだとこの24GBが使えないので、リサイズします。

ubuntu@ubuntu:~$ sudo ntfsresize /dev/sdc5
ntfsresize v2012.1.15AR.1 (libntfs-3g)
Device name        : /dev/sdc5
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 1000200991232 bytes (1000201 MB)
Current device size: 1024207446016 bytes (1024208 MB)
New volume size    : 1024207442432 bytes (1024208 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 330500 MB (33.0%)
Collecting resizing constraints ...
WARNING: Every sanity check passed and only the dangerous operations left.
Make sure that important data has been backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device '/dev/sdc5'.
ubuntu@ubuntu:~$ 

これでubuntuでの作業は完了です。ubuntuをシャットダウンしてPCの電源ケーブルを抜き、ケースを開けてhddをssdに換装します。

コメントする

1件のコメント

  1. Cドライブの交換(作業メモ) | 萌えとかプログラミングとか

コメントを残す