Difference between revisions of "Copying ISO Images To USB"

From NST Wiki
Jump to navigationJump to search
(Using dd - Linux System)
(Using dd or 'fdlcdd' - Linux System)
Line 45: Line 45:
 
* You will not have access to all of the fancy features available when using the Live USB tools (separate writable home partition, overlay, etc).
 
* You will not have access to all of the fancy features available when using the Live USB tools (separate writable home partition, overlay, etc).
  
== Using ''dd'' or 'fdlcdd' - Linux System ==
+
== Using ''dd'' or 'dcfldd' - Linux System ==
  
 
The following demonstrates how to use ''[http://en.wikipedia.org/wiki/Dd_(Unix) dd]'' on a Linux system to copy the contents of the ISO image to a 8GB USB flash drive ("'''/dev/sdc'''") from the command line. An '''8GB''' Block Size ("'''BS'''") was used for file transfer optimization. Make sure the USB flash drive is not mounted ''prior'' to performing the copy.  The [http://en.wikipedia.org/wiki/Cmp_(Unix) cmp] utility is used after the copy for verification.
 
The following demonstrates how to use ''[http://en.wikipedia.org/wiki/Dd_(Unix) dd]'' on a Linux system to copy the contents of the ISO image to a 8GB USB flash drive ("'''/dev/sdc'''") from the command line. An '''8GB''' Block Size ("'''BS'''") was used for file transfer optimization. Make sure the USB flash drive is not mounted ''prior'' to performing the copy.  The [http://en.wikipedia.org/wiki/Cmp_(Unix) cmp] utility is used after the copy for verification.
Line 51: Line 51:
 
<div class="centerBlock"><div class="noteMessage">'''Note:''' Alternatively, one could use the '''[http://forensicswiki.org/wiki/Dcfldd dcfldd]''' ('''[http://forensicswiki.org/wiki/Defense_Computer_Forensics_Lab Defence Computer Forensics Lab]''') utility for copying the image to the USB drive. This utility provides console output progress information during the copy operation. The "'''''statusinterval'''''" option is used to specify the update period in "'''N blocks'''" transferred.
 
<div class="centerBlock"><div class="noteMessage">'''Note:''' Alternatively, one could use the '''[http://forensicswiki.org/wiki/Dcfldd dcfldd]''' ('''[http://forensicswiki.org/wiki/Defense_Computer_Forensics_Lab Defence Computer Forensics Lab]''') utility for copying the image to the USB drive. This utility provides console output progress information during the copy operation. The "'''''statusinterval'''''" option is used to specify the update period in "'''N blocks'''" transferred.
  
  [root@shopper2 iso]# dcfldd if=./nst-30.x86_64.iso of=/dev/sdc bs=8M statusinterval=64;
+
  [root@shopper2 iso]# dcfldd if=./nst-32.x86_64.iso of=/dev/sdc bs=8M statusinterval=64;
 
  448 blocks (3584Mb) written.
 
  448 blocks (3584Mb) written.
 
  482+0 records in
 
  482+0 records in

Revision as of 12:22, 5 May 2020

The NST distribution is based off of Fedora. Because of this you can use a variety of methods to install the NST ISO image onto USB media (memory sticks, SD cards, etc).

The following sections provide a quick reference for some common methods for transferring the ISO image to a USB flash drive. What is described below is just the tip of the iceberg. For full details, refer to the man pages for the various utilities used and visit the "How to create and use Live USB" page on the Fedora wiki.

Using liveusb-creator

If you are more comfortable with graphical applications, you can use the liveusb-creator tool. Look for the Fedora LiveUSB Creator launcher icon under system tools. This tool offers a subset of the features provided by the livecd-iso-to-disk command line utility, but is recommended for beginners (or people that don't have time to read and can live with limitations).

There is a version of liveusb-creator available that runs under Windows.

For more details on using the liveusb-creator tool, refer to Fedora's excellent write up: "How to create and use Live USB" .

Using livecd-iso-to-disk

The livecd-iso-to-disk command line utility provides a lot more options than the simplified liveusb-creator tool. The livecd-iso-to-disk utility can be installed on a NST (or any Fedora based system) by running the following command:

sudo rpm -q livecd-tools || sudo yum install livecd-tools

Once installed, you can run use the livecd-iso-to-disk utility in the following manner (there are a lot more options available and you are encouraged to read the man page).

 sudo livecd-iso-to-disk --noverify nst-20-5102.i686.iso /dev/sdx1

NOTE: You will need to substitute the name of the ISO file to use (nst-20-5102.i686.iso) and the USB disk partition to install to (/dev/sdx1) according to your situation.

The following example formats the USB drive and enables EFI/UEFI booting of your USB drive with a 64 bit version of the NST ISO image (for newer Intel hardware and Macs).

 sudo livecd-iso-to-disk --format --efi --noverify nst-20-6480.x86_64.iso /dev/sdx1

If you booted from a DVD ISO image, it is possible to create USB media using from the DVD you have booted from. Substitute /run/initramfs/livedev for the name of the ISO file to use (you may also need to include the --noverify option as we aren't sure verification works when reading from raw devices). Here is an example:

sudo livecd-iso-to-disk --noverify /run/initramfs/livedev /dev/sdx1

You will need to change /dev/sdx1 shown above to the partition of your USB flash drive you want initialized. Add the --format and --reset-mbr options if you need to clear/initialize your USB flash drive to a good working state.

For more details on using the livecd-iso-to-disk tool, refer to Fedora's excellent write up: "How to create and use Live USB" .

Directly Copying ISO Image To USB

One of the simplest methods to convert a ISO image to bootable USB is to directly copy the image to the USB media. The dd command can be used for this purpose on Linux and Mac based systems.

Here are some things to be aware of when using the dd method:

  • The entire USB flash drive is used. Hence, if you use a 16GB flash drive, you won't be able to store information on any of the remaining disk space.
  • The systems which you want to boot from need to support booting from USB ISO images in addition to or instead of booting from USB FAT images. This may lead to better or worse compatibility.
  • You will not have access to all of the fancy features available when using the Live USB tools (separate writable home partition, overlay, etc).

Using dd or 'dcfldd' - Linux System

The following demonstrates how to use dd on a Linux system to copy the contents of the ISO image to a 8GB USB flash drive ("/dev/sdc") from the command line. An 8GB Block Size ("BS") was used for file transfer optimization. Make sure the USB flash drive is not mounted prior to performing the copy. The cmp utility is used after the copy for verification.

Note: Alternatively, one could use the dcfldd (Defence Computer Forensics Lab) utility for copying the image to the USB drive. This utility provides console output progress information during the copy operation. The "statusinterval" option is used to specify the update period in "N blocks" transferred.
[root@shopper2 iso]# dcfldd if=./nst-32.x86_64.iso of=/dev/sdc bs=8M statusinterval=64;
448 blocks (3584Mb) written.
482+0 records in
482+0 records out
[root@vortex livecd]# 
[root@shopper2 Downloads]# ls -al ./nst-20-5102.x86_64.iso 
-rw-r--r-- 1 root root 2002780160 Dec  2 06:21 ./nst-20-5102.x86_64.iso
[root@shopper2 Downloads]#
[root@shopper2 Downloads]# lsscsi -s
[0:0:0:0]    disk    ATA      OCZ-VERTEX3      2.25  /dev/sda    120GB
[1:0:0:0]    disk    ATA      SanDisk SDSSDX24 R211  /dev/sdb    240GB
[12:0:0:0]   disk    SanDisk  Cruzer           1.01  /dev/sdc   8.00GB
[root@shopper2 Downloads]#
[root@shopper2 Downloads]# dd if=./nst-20-5102.x86_64.iso of=/dev/sdc bs=8M
238+1 records in
238+1 records out
2002780160 bytes (2.0 GB) copied, 519.832 s, 3.9 MB/s
[root@shopper2 Downloads]#
[root@shopper2 Downloads]# cmp -l ./nst-20-5102.x86_64.iso /dev/sdc
cmp: EOF on ./nst-20-5102.x86_64.iso
[root@shopper2 Downloads]#

SD Card Issues

We have seen issues when trying to use SD cards on some systems. When SD cards are working correctly, you will typically see a /dev/mmcblk0 device appear after inserting the card. If you don't see this device, check the output of dmesg:

[nst@refritos Downloads]$ sudo dmesg | tail
[73111.146616] CPU3: Package temperature/speed normal
[73111.146617] CPU4: Package temperature/speed normal
[73111.146618] CPU0: Package temperature/speed normal
[78944.735796] lenovo 0005:17EF:6048.0006: unknown main item tag 0x0
[78944.736422] input: ThinkPad Compact Bluetooth Keyboard with TrackPoint
[78944.737291] lenovo 0005:17EF:6048.0006: input,hidraw1: BLUETOOTH HID v3.12 Keyboard [ThinkPad Compact Bluetooth Keyboard with TrackPoint] on 00:c2:c6:e9:c3:bf
[79106.142226] mmc0: error -84 whilst initialising SD card
[79106.310011] mmc0: error -84 whilst initialising SD card
[79106.472897] mmc0: error -84 whilst initialising SD card
[79106.666591] mmc0: error -84 whilst initialising SD card
[nst@refritos Downloads]$

The mmc0 errors indicate that the system recognized that a SD card was inserted, but did not know how to handle it. If your SD card reader is connected to the PCI bus, the following command can be used to verify that the reader was detected:

[nst@refritos Downloads]$ lspci | grep -i sd
02:00.0 SD Host controller: O2 Micro, Inc. SD/MMC Card Reader Controller (rev 01)
3d:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM961/PM961
[nst@refritos Downloads]$ 

At this point, you can try loading two kernel modules and then re-insert the card:

[nst@refritos Downloads]$ sudo modprobe tifm_sd
[nst@refritos Downloads]$ sudo modprobe mmc_block
[nst@refritos Downloads]$ 

After re-inserting the card, check your dmesg output and verify that at least the /dev/mmcblk0 appears as a device. There may be additional mmc devices entries for each partition (below we see two partitions) and if you have more than one SD card inserted your index may be something other than 0.

[nst@refritos Downloads]$ sudo dmesg | tail
[78944.736422] input: ThinkPad Compact Bluetooth Keyboard with TrackPoint as /devices/pci0000:00/0000:00:14.0/usb1
[78944.737291] lenovo 0005:17EF:6048.0006: input,hidraw1: BLUETOOTH HID v3.12 Keyboard [ThinkPad Compact Bluetooth Keyboard with TrackPoint] on 00:c2:c6:e9:c3:bf
[79106.142226] mmc0: error -84 whilst initialising SD card
[79106.310011] mmc0: error -84 whilst initialising SD card
[79106.472897] mmc0: error -84 whilst initialising SD card
[79106.666591] mmc0: error -84 whilst initialising SD card
[79290.022431] mmc0: Tuning timeout, falling back to fixed sampling clock
[79290.024275] mmc0: new ultra high speed SDR104 SDHC card at address 0007
[79290.024840] mmcblk0: mmc0:0007 SD16G 14.6 GiB 
[79290.028134]  mmcblk0: p1 p2
[nst@refritos Downloads]$ ls /dev/mmc*
/dev/mmcblk0  /dev/mmcblk0p1  /dev/mmcblk0p2
[nst@refritos Downloads]$ 

At this point dd command can then be used to write a disk image to the SD card. In the example below, we are writing a disk image for a Raspberry PI by streaming the output of the unzip command directly into dd (leaving the Raspberry PI image in its compressed state). Also, notice how the ddstatus alias was created. I typically have this line in my ~/.bashrc file as it sets the block size and indicates that I want progress displayed on stderr.

[nst@refritos Downloads]$ unzip -l 2018-06-27-raspbian-stretch.zip 
Archive:  2018-06-27-raspbian-stretch.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
4823449600  06-26-2018 21:22   2018-06-27-raspbian-stretch.img
---------                     -------
4823449600                     1 file
[nst@refritos Downloads]$ alias ddstatus='sudo dd bs=4M status=progress'
[nst@refritos Downloads]$ unzip -p 2018-06-27-raspbian-stretch.zip 2018-06-27-raspbian-stretch.img | ddstatus of=/dev/mmcblk0
4817616896 bytes (4.8 GB, 4.5 GiB) copied, 249 s, 19.3 MB/s
0+54139 records in
0+54139 records out
4823449600 bytes (4.8 GB, 4.5 GiB) copied, 395.651 s, 12.2 MB/s
[nst@refritos Downloads]$ 

Finally, if you would like the SD card modules loaded at boot, create a module configuration file /etc/modules-load.d/mmc.conf with the following content:

# Load necessary modules access SD cards
tifm_sd
mmc_block

Using dd - Mac System

It is also possible to use the dd command to copy the contents of the ISO image to a USB flash drive having a capacity of 2GB (or more). The following demonstrates how to do this from the command line on a Mac. The diskutil utility was used prior to invoking the dd command determine the device entry for the USB flash drive and to unmount any active partitions.

taco-e:tlp pkb$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *512.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            511.8 GB   disk0s2
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *750.2 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS TIMEMAC                 749.8 GB   disk1s2
/dev/disk3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *8.0 GB     disk3
   1:             Windows_FAT_32 tldboot                 128.0 MB   disk3s1
   2:                      Linux                         7.9 GB     disk3s2
taco-e:tlp pkb$ diskutil unmountDisk /dev/disk3
Unmount of all volumes on disk3 was successful
taco-e:tlp pkb$ sudo dd if=/Volumes/public/vm/iso/nst-20-5102.i686.iso of=/dev/disk3 bs=$((8*1024*1024))
220+1 records in
220+1 records out
1847590912 bytes transferred in 2957.797273 secs (624651 bytes/sec)
taco-e:tlp pkb$ diskutil eject /dev/disk3
Disk /dev/disk3 ejected
taco-e:tlp pkb$

Direct Write For Windows Systems

If you are on a Windows based system, you will not have access to the dd command. However, there are other methods which allow you to directly write ISO images to USB media. Detailed instructions can be found at Fedora's excellent: "How to create and use Live USB" page.