Friday, 12 September 2014

Making a bootable USB comand line fedora linux

#include<iostream> //Please remove comments within cases when making a bootable device
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>

using namespace std;
int main()
{
int ch;
     char dev[100]="";
     char boot[100]="sudo dd if=";
     char boot1[100]=" of=";
     char unmnt[100] ="umount ";
     char iso[100] ="";
        char tmp[100]="";

    cout<<"\n\n";
    system("mount | grep /dev/sd");
    cout<<"\n\nEnter the device to be made bootable: ";
    cin>>dev;

   
    cout<<"Enter the iso file path to be used: ";
    cin>>iso;
   
    cout<<"Select option \n 1. Make Bootable without format \n 2. Format using fat File System & (Burn)Make Bootable \n 3. Format using ext4 File System & (Burn)Make Bootable \n 4. Format using msdos File System & (Burn)Make Bootable \n 5.Exit \n";
    cin>>ch;
   
    switch(ch)
    {
    case 1:
        cout<<"\nCopying bootable files on device.....\n";
       
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";
         //system(boot);
            break;
    case 2:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);
        cout<<unmnt;

        system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.vfat "<<dev;
        strcat(tmp,"sudo mkfs.vfat ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";

        // system(boot);
            break;
   
    case 3:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);cout<<unmnt;

        //system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.ext4 "<<dev;

        strcat(tmp,"sudo mkfs.ext4 ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";
   
         //system(boot);
            break;
    case 4:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);cout<<unmnt;

        //system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.msdos "<<dev;
       
        strcat(tmp,"sudo mkfs.msdos ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";

         //system(boot);
            break;
    case 5:
        exit(0);
        break;
    }


  return 0;
  }

/*this is the original linux command .Giving incorrect device names may currupt your system

[root] # mkfs.vfat /dev/sdc1
[root] # dd if=Fedora-Live-Desktop-x86_64-20-1.iso of=/dev/sdb
*/



/*--------------------OUTPUT------------------------------------
[root@localhost apcoer]# g++ bootable.cpp
[root@localhost apcoer]# ./a.out


/dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb1 on /run/media/apcoer/Fedora-Live-Desktop-x86_64-20-1 type iso9660 (ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)


Enter the device to be made bootable: /dev/sdb1
Enter the iso file path to be used: /home/apcoer/Pictures/Fedora-20Live-Desk.iso
Select option
 1. Make Bootable without format
 2. Format using fat File System & (Burn)Make Bootable
 3. Format using ext4 File System & (Burn)Make Bootable
 4. Format using msdos File System & (Burn)Make Bootable
 5.Exit
3
Unmounting your device...umount /dev/sdb1
mke2fs 1.42.7 (21-Jan-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61056 inodes, 243968 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=251658240
8 block groups
32768 blocks per group, 32768 fragments per group
7632 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Formatting your USB Device....sudo mkfs.ext4 /dev/sdb1sudo mkfs.ext4 /dev/sdb1
Copying bootable files on device.....sudo dd if=/home/apcoer/Pictures/Fedora-20Live-Desk.iso of=/dev/sdb1
1951744+0 records in
1951744+0 records out
999292928 bytes (999 MB) copied, 399.875 s, 2.5 MB/s
[root@localhost apcoer]#


[root@localhost apcoer]# ./a.out


/dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb on /run/media/apcoer/SONY_8GR type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)


Enter the device to be made bootable: /dev/sdb
Enter the iso file path to be used: /home/apcoer/Pictures/Fedora-20Live-Desk.iso        
Select option
 1. Make Bootable without format
 2. Format using fat File System & (Burn)Make Bootable
 3. Format using ext4 File System & (Burn)Make Bootable
 4. Format using msdos File System & (Burn)Make Bootable
 5.Exit
2
Unmounting your device...umount /dev/sdb
mkfs.fat 3.0.20 (12 Jun 2013)
mkfs.vfat: Device partition expected, not making filesystem on entire device '/dev/sdb' (use -I to override)
Formatting your USB Device....sudo mkfs.vfat /dev/sdbsudo mkfs.vfat /dev/sdb
Copying bootable files on device.....sudo dd if=/home/apcoer/Pictures/Fedora-20Live-Desk.iso of=/dev/sdb
Complete!
[root@localhost apcoer]#
*/

No comments:

Post a Comment