Write A Program In Python/C++ To Make USB Device Bootable by Installing Required System Files.
============ Python Program ============
import commands print "\nCREATING A BOOTABLE USB\n"; print "\nSTEP 1: UNMOUNTING THE DEVICE\n" print commands.getoutput("umount /dev/sdb*") print commands.getoutput("echo y | mkfs /dev/sdb") print "\nSTEP 3: MODIFY 1st SECTOR OF DEVICE\n" print commands.getoutput("dd if=boot_sect.bin of=/dev/sdb bs=512 count=1") print "\nSTEP 4: CREATING THE FILE SYSTEM\n" print commands.getoutput("echo n p \"\n\n\n\n\n\" w | fdisk /dev/sdb") print "\nDONE\n"
============ OUTPUT ============
[root@localhost ~]# python pythonbootable.py CREATING A BOOTABLE USB STEP 1: UNMOUNTING THE DEVICE mke2fs 1.42.7 (21-Jan-2013) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 977280 inodes, 3908352 blocks 195417 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4005560320 120 block groups 32768 blocks per group, 32768 fragments per group 8144 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Writing superblocks and filesystem accounting information: done STEP 3: MODIFY 1st SECTOR OF DEVICE dd: failed to open ‘boot_sect.bin’: No such file or directory STEP 4: CREATING THE FILE SYSTEM Welcome to fdisk (util-linux 2.23.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xa883a4db. Command (m for help): Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-31266815, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-31266815, default 31266815): Using default value 31266815 Partition 1 of type Linux and of size 14.9 GiB is set Command (m for help): The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. DONE
======== USB Burning Open Source Software ========
Write A Program In Python/C++ To Make USB Device Bootable by Installing Required System Files.
Reviewed by Hardik Pandya
on
3:55:00 PM
Rating:
No comments: