Saturday, June 21, 2014

Make bootable usb under linux

Intro 

if you want to create bootable usb stick (pen drive) keep reading, first we will present a general overview of procedure and then step by step instructions with possible errors you could bump into along the road. Users who have done format of their usb flash sticks should proceed to part 2 of this tutorial (creating bootable usb stick using unetbootin

The general procedure 

requirements:
1. usb flash stick with sufficient memory space.
2. iso image of windows or linux depending what OS you want install on host machine.

general procedure:
1. Format your usb stick with FAT32 , FAT file system. (see formating usb stick under linux bellow for instructions how to do that)
2. using unetbootin program make your usb flash stick bootable.
3. boot from usb stick (see boot from usb)
4. install windows or linux OS (this is quite straight forward process once you boot from usb)

possible errors:
1. ISO file is corrupted and you need to download another ISO file image.
2. unetbootin finished creating bootable flash stick, but flash stick won't boot
        2a. If there is a boot manager screen of unetbootin but it won't boot, it's probably problem with ISO file so you need to find another working ISO image and redo the procedure. 
        2b. If there is no boot manager screen poping then usb is not bootable, try another usb port.



Format usb stick under linux 

There are a few ways to make this work, here are some of them starting from the easiest method. 

Format usb stick under linux Ubuntu

This method works for ubuntu distro of linux (they made it very simple *user friendly, hence it's so popular)
1. plug in you usb flash stick 
2.  find your disks application and open it. Here is how it looks like: 
click on disks icon

3. When you open disks app find your usb flash disk under "disk drives" like on image bellow:
4. Important: In order to format you usb flash drive it shouldn't be mounted onto file-system, by default it is, so you need to click stop sign and this will unmount usb flash drive from file system. You will know it's unmounted by checking In use status, see the image (it should say In use: NO) 

5. Click that settings icon like pointed on image under step 3. and select "FORMAT..." option. This will bring new window and with format options, see next image
6. Under erase leave it quick (don't overwrite existing data) 
Slow means that system will do full format in sense that every single bit of memory will be overwritten with zero. under Type select "compatible with all system devices (FAT)" and fill in last field Name whatever you want, it's name of your flash stick with you mount it. Next you click format and prompt window will ask you whether you are sure you want to format and you hit "FORMAT" 
(tip bellow explains that if you use quick format of data previously saved can be extracted with some recovery tools unless overwritten, so if you want to give your flash to another user consider full format. For our use this will not be necessary.)

Here is an image of prompt dialog: 
Click format button
If you've selected quick format process should finish in a second. And that should be it, you're done with format of your usb stick. This is the the easiest way and it's for users using Ubuntu linux distro.
If you're not using Ubuntu, bellow is another way via command shell. But before that, if you don't unmount your usb from file system, the error will be presented like on image bellow: 
If this happens you've forgot to unmount your usb, go back to step 4. 

Format usb stick under linux (In general all distros)

Before we could format usb stick, we need to find device path mapping of our usb flash stick. To do this type open your command shell (press CTRL+ALT+T) and type in: sudo fdisk -l like on image bellow:


Remeber to do this as super user (root) otherwise you won't be able to see disk partitions. Hence sudo.
The output should be something like on image (depending on your partition tables and devices) 

/dev/sdc1 is the device mapping of usb under my linux distro.
So this output will give you information of device mapping and mine is /dev/sdc1, mapping of your device will be something else perhaps /dev/sd[xa][xb] where [xa] is letter [a-z] number of hd devices on system, and [xb] is a number of partition.

We will need this information, so we can format our flash stick latter on. Now we need to unmount flash usb stick from file system, but before we do that, we should figure out what is the device -> file system mapping of usb. You can find this information by typing sudo mount command via command shell.

$ sudo mount 

Here is the image of output from my system, on yours it will be different but essentially what we need.
if device is mounted onto file system, you will see something like this. 


Once you've found this information (notice you see here mapping of device as well /dev/sdc[x] but if device is not mounted by default we wouldn't know what the mapping is before checking fdisk -l output)

On the image we see that mount path is /media/ddr/bootablefla (essentially it's shorten name of usb stick if name is too long). When you figure out what's the mounted device path, we can unmount device from file system. 

1. Unmount device from file system like so: 

$ sudo umount /media/ddr/bootablefla 

Where after umount you type your own mounted device path. After this step we can format usb stick. 

2. format usb stick. 

To format usb stick, you will need device mapping path and we've found for me it's /dev/sdc1 using fdisk -l command. 

To format usb stick, type command (in command shell) 

$ sudo mkfs.vfat /dev/sdc1

Here is the image of output: 


Note: if you haven't done umount from file system (of usb) error will on output and then you should go back to step 1. 

Just to give you some more options, here are some of other file system types, we've done format using FAT file-system.

mkfs.cramfs   mkfs.ext3     mkfs.ext4dev  mkfs.msdos
mkfs.bfs      mkfs.ext2     mkfs.ext4     mkfs.minix    mkfs.vfat

msdos is FAT32 file system.
ext2,ext3,ext4 linux file systems.
vfat is FAT file system. 
So now you're done with usb flash stick format, now you can make your bootable flash disk. Keep reading.

Other ways to format usb are by using gparted but that won't be covered in this tutorial. 


Creating bootable usb stick using unetbootin

in order to create bootable usb, you'll need one little program called unetbootin. You can download program from here http://unetbootin.sourceforge.net/

When you've downloaded your linux version of unetbootin, you should make it executable by assigning +x permissions to the binary file. (extension is .bin) 

To do this find the path where you've downloaded your unetbootin and execute following command:

$ chmod +x filename (where filename shoud be unetbootin filename ... for me it's unetbootin-linux-608.bin

Now you can start unetbootin using command: 

$ ./unetbootin-linux-608.bin &



You'll be asked for root access (root password and you type in yours) now application will run and it will look like something like this:

Now you should select diskimage iso path, click "..." and select your ISO image you've downloaded earlier. When you select your ISO image path, make sure type is USB DRIVE and Drive is set to your device path (it should auto detect all required fields) then you click "OK". 

After that you'll have to wait for some time until unetbootin copies all the image data to USB stick. Process looks like this: 



You hit exit, and that's it, you have bootable flash stick! 

So when the process finishes, you've done it! That's all there is to it. Now you have a bootable usb flash stick (pen drive) or what ever you call it. To boot from you usb keep reading this tutorial, it will be explained as well (but shortly).

Boot from USB

1. stick in your usb flash stick into usb port. 
2. restart your computer
3. when computer restarts start pressing "ESC" keyboard button (depending on laptop or pc there will be diferent keys most likely ESC, F2, F6, DELETE   

On some laptops pressing ESC gives you possibility to choose booting device for one instance and that's great just select your usb device and hit "ENTER" 

Otherwise you'll have to make a usb flash stick device a priority in BIOS under boot settings. When you do that, remeber to save settings in BIOS. Also don't mess around with other settings. Next time you restart if there is bootable flash stick plugged in, computer will recognize it and start boot process.

That's pretty much it. Hope you find this article / tutorial helpful. Good luck! 
  
  

No comments:

Post a Comment