Wednesday, October 31, 2012

Save a CD/DVD - Use a USB flash drive and dd

If you use Linux for ethical reasons then that may be a reason to be consious of our limited and dwindling resources, if you are interested in saving the environment you can refrain from burning a CD or DVD to install your favorite linux distribution. The vast majority of Linux distributions come out with newer versions on a prescheduled timeframe called a release cycle, The exception being Linux distributions that are semi-rolling or rolling release.

If you are like me you enjoy experiencing all that the Linux world has to offer, Choosing a single distrubtion as your main distribution but still dabbling in other distributions as well either through a dual/multi boot or via virtualization if your system is powerful enough. If you are using virtualization then you can simply mount the image upon install. However if you are configuring your to boot with multiple operating systems or simply testing one and reinstalling over the previous partition then this can eat up a lot of CD's or DVD's and waste a lot of money and resources.

You mean to tell me there is an alternative that is both more environmental and saves me money? Yes, The solution is using a USB flash drive in combination with the dd command.

There are a couple of ways to find the name of the device file associated with your USB flash drive, device file names are dynamically created in the order they are connected. Your hard drives show up first, followed by the USB flash drive. I personally have 2 hard drives and 1 USB flash drive so my USB Flash drive shows up as /dev/sdc.

Option 1 - fdisk

$ sudo fdisk -l
                                                                                                                                                                                                                               
Disk /dev/sda: 120.0 GB, 120034123776 bytes                                                                                                                                                                                    
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 sectors                                                                                                                                                          
Units = sectors of 1 * 512 = 512 bytes                                                                                                                                                                                         
Sector size (logical/physical): 512 bytes / 512 bytes                                                                                                                                                                          
I/O size (minimum/optimal): 512 bytes / 512 bytes                                                                                                                                                                              
Disk identifier: 0x000d60b7                                                                                                                                                                                                    
                                                                                                                                                                                                                               
   Device Boot      Start         End      Blocks   Id  System                                                                                                                                                                 
/dev/sda1              63    83971754    41985846   83  Linux                                                                                                                                                                  
/dev/sda2        83971755   105418529    10723387+  82  Linux swap / Solaris                                                                                                                                                   
/dev/sda3       105418530   234436544    64509007+   5  Extended                                                                                                                                                               
/dev/sda5   *   105418593   148424534    21502971   83  Linux                                                                                                                                                                  
/dev/sda6       148424598   191430539    21502971   83  Linux
/dev/sda7       191430603   234436544    21502971   83  Linux

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004f221

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63   417523711   208761824+   7  HPFS/NTFS/exFAT
/dev/sdb2       417523712  1441523711   512000000    7  HPFS/NTFS/exFAT
/dev/sdb3      1441525758  1543925759    51200001    5  Extended
/dev/sdb4      1543925760  1953523711   204798976   83  Linux
/dev/sdb5      1441525760  1457909759     8192000   82  Linux swap / Solaris
/dev/sdb6      1457911808  1498861567    20474880   83  Linux

Disk /dev/sdc: 8103 MB, 8103395328 bytes
47 heads, 21 sectors/track, 16035 cylinders, total 15826944 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005e84f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048    15826943     7912448    b  W95 FAT32

Option 2 - ls + verification.
$ ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda5  /dev/sda6  /dev/sda7  /dev/sdb  /dev/sdb1  /dev/sdb2  /dev/sdb3  
/dev/sdb4  /dev/sdb5  /dev/sdb6  /dev/sdc  /dev/sdc1
$ sudo mkdir -p /mnt/usb; sudo mount /dev/sdc1 /mnt/usb; df -h | grep sdc; ls /mnt/usb
/dev/sdc1       7.6G  4.0K  7.6G   1% /mnt/usb
clean!*  files_that_dont_matter*
$ sudo umount /mnt/usb
This way may take a little more typing to do the verification that the drive is of the correct size and that you are not erasing important data, If you happen to see a directory structure that looks in any way important to you, either you are targetting the incorrect device or you need to back up your data before running dd. Of course if you are sure the proper device is /dev/sdc after looking you can skip the second and third commands.

The dd command works on the bit level so should be run on the base device and not a partition of the device. I choose /dev/null as my device because at this particular time I had no particular reason to write a CD or DVD image. Depending on the speed of the USB flash drive (mine is slow) and the size of the image it could take a while to perform the write operation.

Warning - make sure the USB flash drive is not mounted prior to running the dd command or damage to your equipment may result, Running DD on the wrong device will cause the device to be erased and written over with the ISO.

$ sudo dd if=./chakra-2012.09-Claire-x86_64.iso  of=/dev/null 
 3254272+0 records in
 3254272+0 records out
 1666187264 bytes (1.7 GB) copied, 0.94725 s, 1.8 GB/s

At this point you should have a fully operational USB drive that shows up exactly like a CD or DVD would. The only other configuration you may have to perform is to access the BIOS and allow the USB drive to boot before the CD/DVD drive and hard drives. Once that is set when you boot your computer you should see the USB act as if it were a CD or DVD.

Congratulations, You have done your best to save the environment and successfully installed your Linux distribution.

No comments:

http://goo.gl/BGVrJP

MY Motto

My photo
giving amenity to all visitor.

Total Pageviews