Technology

Boot Linux from a flash drive to recover files

Posted by admin

After a long time, we are back to talking about some more cool tech things you can do with a USB flash drive. Today’s topic will focus on booting the Linux operating system from a USB stick. The purpose of booting Linux from a USB drive, at least the purpose of this guide, is to recover files from a broken installation of the Windows operating system or any other operating system. We can also safely run virus scans from the Linux distribution without infecting other PCs or having to boot the infected PC.

What you will need:

* A 512mb to 2GB USB stick (depending on distribution)
* A main board capable of booting from a USB device.
* and about 15 minutes plus download time.

Software to use:

* Latest stable version of UNetbootin

Step #1: Prepare the USB drive

Once you have all your materials together, plug in the USB drive and back up any files you may have on the drive.

Step #2: Installation on the USB

Start UNetbootin and select the following:

1. Use the first radio button “Distribution”. This will automatically download and install the distro you want.
2. Select SystemRescueCD. We’re going with this because it’s easy, the ntfs file system driver comes pre-packaged so no further customization is required.
3. Next, select your flash drive.
NOTE: Be sure to select your flash drive and not your Windows partition or primary partition, because doing so will destroy the currently installed operating system.
4. Finally, click “OK”.

The UNetbootin options to select are shown in an image in the source article linked at the bottom of this article.

Step #3: Bios Settings

We will need to configure your computer to boot from the USB stick. To do this, firstly, the motherboard will need to support this feature, and secondly, you will need to do some configuration.

1. Restart your computer and press “F2? or “del” depending on your motherboard to enter BIOS setup.
2. Find the section labeled Boot Sequence or a similar name. Sometimes this will be filed in a separate section, such as advanced BIOS features, or similar.
3. Move Removable or USB to the top of the list. If you don’t see these options listed, your motherboard most likely doesn’t support USB booting. Please refer to Google for more information on this.
4. Reboot the computer with the drive plugged in.

Step #4: Boot Linux

We are going to start at the command line for this guide. There are options to load a GUI for those of you who cringe at CLI. I must warn you though Command Line is much easier and faster.

1. Once your computer passes the post, you will see the bootloader screen. Navigate to “VMLinuz64″ and press enter.

After a bunch of OKs on the screen and most likely 1 red FAIL, the message “root@sysresccd /root %” will appear. This would indicate a success.

Step #5 – Copy files from a Windows partition to an external hard drive.

For this you will need an external medium in which to move your files, have it ready to receive your data. You can also use the USB stick you booted from, if of course there is enough space on it.

1. First we will need to identify our units. I will assume that you have two storage devices connected, one is the flash drive and the other is your Windows hard drive. Run the following command:

</p> <p> fdisk -l | less<br /> This command will show you all the storage devices on your system. Use the down and up arrows to navigate the output as it may be larger than your screen. My output for this command is shown below:

</p> <p> Disk /dev/sda: 160.0 GB, 160000000000 bytes 255 heads, 63 sectors/track, 19452 cylinders Units = 16065 * 512 cylinders = 8225280 bytes Disk Identifier: 0xd0f4738c Device Boot Start End Blocks Id System /dev/sda1 * 1 19451 1562401 7 HPFS/NTFS Disk /dev/sdb: 2085 MB, 2085617664 bytes 2 heads, 63 sectors/track, 32329 cylinders Units = 126 cylinders * 512 = 64512 bytes Disk Identifier: 0x00502bcd Device Boot Start End Blocks Id System /dev/sdb1 *1 32330 2036720 6 FAT16<br /> My device has a 160 GB NTFS partition. Knowing those two bits of information, we can guess and say that /dev/sda is our Windows device.

NOTE: To exit this exit screen press “q”.

2. Mount the Windows drive so that we can access the files on it. Run the mount command below:

</p> <p> mount /dev/sda /mnt/windows<br /> NOTE: You will need to replace “/dev/sda” with your device found in the output of fdisk -l. Although they are probably the same.

3. Let’s find out if we mount the correct device now. Run:

</p> <p> ls /mnt/windows<br /> This command will list the files and folders in a directory. If you see the telltale program files and WINDOWS directories, it mounted successfully.

4. Time to get out our backup device. Plug it in and wait a few seconds, then run the fdisk command again:

</p> <p> fdisk -l<br /> Prayed

</p> <p> cat /proc/scores<br /> You should see the two devices you saw last time and now there should be a new one. Match the device size to yours and note the most likely device location /dev/sdc.

Mount this device to the premade backup folder using the mount command again:

</p> <p> mount /dev/sdc /mnt/backup<br /> 5. Now it’s time to copy stuff from the old Windows drive to the backup drive.

If you want to copy your entire Windows drive to your backup drive, run this command:

</p> <p> cp -R /mnt/windows/* /mnt/backup/YOUR_FOLDER_NAME<br /> If you plan to copy individual files, type the full file path and then the full destination path.

Additional useful commands:

* Sometimes a virus can infect the first bit of code that runs on your system, the MBR (Master Boot Record). Fortunately, we can clean this up relatively easily on Linux. Executed:

</p> <p> dd if=/dev/zero of=/dev/sdb bs=512 count=1<br /> Remember to replace “/dev/sdb” with your device because if you lose and clean the wrong one you may have some problems.

* Maybe you don’t have an external device to back up, but you have another computer with a shared network. Well, let’s mount that network share so we can copy files to it. Create a mount point:

</p> <p> mkdir /mnt/network<br /> Mount the share:

</p> <p> mount -t smbfs //hostname/folder /mnt/network -o username=user1,password=mypasswordhere<br /> You can now copy and move files to the network share like any other directory.

To mount a share without a password, use:

</p> <p> mount -t smbfs //computername/folder /mnt/network<br /> Until next time.

Leave A Comment