Outils pour utilisateurs

Outils du site


issue78:c_c

Ceci est une ancienne révision du document !


Towards the end of September, I ended up replacing an old SATA 150 500GB hard drive with a Western Digital Blue 1TB drive. Doing so involved cloning it using Clonezilla, and resizing it using GParted. A few days later, I also ended up fixing an unrecognized external hard drive for a friend using TestDisk & Photorec. Seeing as almost every one of these scenarios was requested in some form during the survey, I decided to spend this month covering these tools.

Cloning & Resizing disks

Tools you'll need: • Clonezilla: http://clonezilla.org/clonezilla-live.php • GParted (liveCD from here: http://gparted.sourceforge.net/ or any liveCD that contains GParted, such as an Ubuntu liveCD)

Steps: • Connect both drives to your computer (for Desktop PCs, internally, and, for laptops, externally should work for the second drive). • Make sure you can recognize the correct drives (if you have two drives of the same size, make note of the serial numbers). This can be done with:

sudo hdparm -I /dev/sda

Replace /dev/sda with the actual device you want to check. It would be best to write down the serial number for later reference. • Once you have the information for both drives, it's time to put the Clonezilla CD in the drive and reboot. • Once you've booted to Clonezilla (by choosing any of the options in the boot list, though I would recommend the To RAM option), you'll need to work through the following: 1. Language – you can choose any you like, but I'll be working with the English names and choices. 2. Keyboard layout. Default is US, and if you're using anything different, you can choose it from the arch list (i.e. German keyboard: Arch List → QWERTZ → German (Latin)). If you have a french keyboard: You'll need to choose it from the full list instead of the arch list. This is a bug and won't work otherwise. 3. Start Clonezilla. 4. Here you can choose from two options: Device-Device, or Device-Image. If you're backing up/restoring a hard drive, then you'll probably be working with Device-Image. However, for cloning from one drive to another, you'll need to choose Device-Device. 5. Choosing beginner is probably the easiest. If, however, you want clonezilla to resize to the target disk's size, you can choose Expert and the -k1 option. However, I recommend doing this via GParted later. 6. In the scenario I've described, you'll need to choose either disk_to_local_disk, or part_to_local_part, depending on whether you want to clone the entire disk, or simply move a single partition to a bigger drive. 7. Choose source disk – Here you need to find the drive that matches your serial number for the original drive. In my scenario it was the 500GB drive. 8. Choose target disk – Here you need to find the serial number that corresponds to your new drive. 9. Choose if you need to have the source file system checked – If you're copying a Linux partition and you know it needs to be repaired, you can run the check. However, it's should be fine to skip this step (and therefore cut down the time you need). If it's an NTFS/FAT/HFS drive, I would recommend not running the check, as I'm unsure if it supports those types. 10. Now you'll be dumped to a terminal screen, and it will ask you the following: 10.1 If you're sure you want to continue, type “y” (without the quotes) and hit enter. 10.2 If you're sure you want to create new partitions on the target drive, type “y” (without the quotes) and hit enter. 10.3 If you want to clone the boot loader (if this is your primary disk), type “y” (without the quotes) and hit enter. 10.4 Lastly, it will ask once again if you're ready to continue, type “y” (without the quotes) and hit enter. 11. Now you should be back at a nice Ncurses interface with information on the status of the cloning process. 12. Once the cloning is finished, it will ask if you want to stay in the console (option #1), or if you want to exit/logout (option #2). Most likely you'll want to exit, so hit 2 and then choose an option (poweroff or reboot). 13. I would recommend powering off and removing the old drive, if you plan to get rid of it. Otherwise move on to the GParted steps and reformat the old drive if you want to continue using it. 14. If you've moved to a larger drive, you'll want to boot to your GParted CD now. Once the desktop has loaded, you'll need to open the GParted program. Then do the following: 14.1 Find the correct disk in the drop-down list at the top right. 14.2 Find the partition you want to resize, select it, and choose resize. 14.3 Adjust the size of the partition until there is no free space left (you can simply drag the end of the bar from the diagram to the end of the empty space). 14.4 Hit enter and wait for the process to finish. 14.5 Lastly, make a note of the device path for the drive (i.e. /dev/sda1), and if you need the UUID, open the terminal from the GParted desktop, and run: sudo blkid Take note of the UUID that corresponds to your drive. 14.6 You'll need to adjust your /etc/fstab file as well if you use UUIDs. Device paths should continue working, but, if not, simply jump back to this step. To do so, run the following commands in the terminal: sudo mount /dev/sda1 /mnt sudo nano /mnt/etc/fstab Replace the UUIDs with the correct ones according to blkid. Once you're done, hit ctrl-x, and choose to save the file before exiting: sudo umount /mnt 14.7 Reboot to your normal GRUB. 15. Now you're ready to boot to your old system on your new drive. However, you will need to manually edit the GRUB entry in order to point to the new disk, especially if you were using UUIDs. To do so, you need to select the GRUB entry in the menu, and hit the “e” key (for edit). Then use the arrow keys to move to the correct part of the entry (UUID or device path), and replace it with the new information. If you're running legacy GRUB (it will say GRUB 0.9.X at the top), you'll need to hit the “b” key to boot once you've made your changes. In GRUB2, the key is F10. In either case, the keys are listed at the bottom of the menu when editing. 16. If you've done the last step correctly, your system should boot properly. Once there, you'll need to adjust the GRUB entries correctly in the configuration files to make it permanent. 16.1 With legacy GRUB, you simply do the following: sudo nano /boot/grub/menu.lst Then find the correct entry and adjust the information as in Step 15. 16.2 For GRUB2 you can either use grub-customizer, by hand: 16.2.1. For Ubuntu (and derivatives): sudo update-grub 16.2.2. For any other systems: sudo grub-mkconfig -o /boot/grub/grub.cfg 17. You should be all set!

TestDisk & Photorec

What you need: To install Testdisk (or run a liveCD that contains TestDisk). In Ubuntu the package is called testdisk, and is in the universe repository.

When to use TestDisk: If your drive isn't being recognized as formatted (appears as “RAW” or “UNFORMATED” in GParted) but you haven't done anything to delete partitions. Or if logical partitions have vanished.

What to do before running testdisk: If you're planning to do more than re-create a partition table, you'll want to run the commands on an imaged copy of the drive (see Clonezilla step 4 above, and choose Device-Image). Since partition tables are a table of contents for your drive (in layman's terms), you can freely re-write it as you want without impacting the actual data. As such, doing this on the physical device should be fine, even if it needs multiple tries.

1. Run testdisk from a terminal. 2. You'll be asked about log creation, choose “create”. 3. You'll need to now choose the correct drive from the list. 4. Testdisk will automatically identify the partition table type. Do not choose anything but the default option unless you know exactly what you're doing. 5. Choose Analyse, which will scan the partition table, and then look for partition headers for “lost” partitions. 6. It will then show you the current partition structure – double-check here to make sure the partition you're looking for is missing. If it is listed, then this process won't help you and you can quit. If it is actually missing, continue by choosing “Quick Search”. 7. Testdisk will ask you a few questions based on the analysis, so answer them as best you can (suggested values are supplied by TestDisk for those who are unsure). 8. Once the scan is complete, it will show you a list of partitions it found (in green). Select the partition you want to restore (if you want to restore more than one, choose one to start with and complete step 9 for the other partitions as well). 9. Hit the “p” key to list the files on the partition (it should work for most formats, though it failed to do so on the HFS+ partition, claiming it needed to be compiled with that support, though I could find no indication as to the compilation option for this). 10. If these are the partitions you wanted, and the directories/files are listed properly, hit enter. 11. Testdisk will then show you the new table, which you can choose to write to the disk. If, however, something is still missing, you can choose the deeper search option (which works the same as Steps 9 and 10). For damaged files and partitions, you'll need to follow more specific advice, which you can find on the TestDisk wiki in the Further Reading section. 12. Once you've written the table (this worked fine for the HFS+ drive, and as such should work for everything), you may need to reboot before the drive shows up again, though in my case it popped up the moment the partition table was written.

If this doesn't yield results, and you're looking for files to restore (deleted, lost, etc.), you can also try the Advanced option instead of Analyse at Step 5. There are specific instructions on the wiki according to partition type.

If your hard drive is damaged or has been completely reformatted, you can try to recover items using Photorec. However, this results in files named by blocks instead of the actual file names (though Photorec may manage to restore some names, it's better to assume the worst).

1. Run photorec from the terminal. 2. Select your disk and choose proceed (if you have the option, choose the raw device listed as /dev/rdisk as it's faster). 3. Highlight the partition you want to scan (or the whole disk), then: 3.1. Open File Opt in order to select what files to recover (to avoid recovering tons of files you aren't interested in). There are further options under “Options”, but the defaults are most likely all you need. 3.2. Choose “search”. 4. Select file system type. 5. If your file system is corrupted, you can choose Whole in order to search for files from everywhere. However, if you've only deleted the files and want them back (and TestDisk has failed), you should be fine with the Free option. 6. Choose the location where the recovered files will be written. 7. Patience. Photorec will put them in folders called recup_dir.1, recup_dir.2,… within the folder you chose. Once the scan is running and files are being restored, you can access them even while the scan is running. If you end up interrupting the scan, you can resume it next time you run photorec.

Hopefully this article will help a few readers with recovering lost data or fixing “broken” drives. If you have any specific problems (that aren't explained in the Further Reading section links), feel free to email me and I will do my utmost to help solve these issues. If you have any questions, suggestions, or requests for articles, you're also welcome to email me those. My email address is: lswest34+fcm@gmail.com.

Further Reading:

TestDisk: http://www.cgsecurity.org/wiki/TestDisk_Step_By_Step

Clonezilla: http://clonezilla.org/

Photorec: http://www.cgsecurity.org/wiki/PhotoRec_Step_By_Step

issue78/c_c.1386415038.txt.gz · Dernière modification : 2013/12/07 12:17 de andre_domenech