Ubuntu Live USB

I bought a Vantec NexStar CX case to use a 2.5" HDD as an external drive.

Since the HDD has plenty of space and I always need a Linux Live CD to fix something, I decided to install Ubuntu at the beginning of this HDD.

This process is quite simple in Ubuntu, which has a “Disk Creator”, but here in Arch Linux I would need to download a similar program to “Disk Creator” or do it manually. Here I show how to do it manually.

  1. Download the .iso image available at http://www.ubuntu.com/download

  2. Install syslinux and ms-sys

    julio@julio-acer ~> sudo pacman -S syslinux mtools
    julio@julio-acer ~> yaourt ms-sys
    
  3. Connect the external HDD to a USB port and check the device using fdisk -l (/dev/sdc here)

    julio@julio-acer ~  $  sudo fdisk -l
      Disk /dev/sdc: 500.1 GB, 500107862016 bytes
      171 heads, 40 sectors/track, 142803 cylinders, total 976773168 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: 0x000de160
    
         Device Boot      Start         End      Blocks   Id  System
      /dev/sdc1            2048     2099199     1048576    b  W95 FAT32
    
  4. Make sure the HDD does not contain anything important. Format it, create a partition of at least 1 GB, and mark it as bootable.

    julio@julio-acer ~> sudo fdisk /dev/sdc
    Command (m for help): d
    Selected partition 1
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4, default 1): 1
    First sector (2048-976773167, default 2048): 2048
    Last sector, +sectors or +size{K,M,G} (2048-976773167, default 976773167): +1G
    
    Command (m for help): t
    Selected partition 1
    Hex code (type L to list codes): c
    Changed system type of partition 1 to c (W95 FAT32 (LBA))
    
    Command (m for help): a
    Partition number (1-4): 1
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: If you have created or modified any DOS 6.x
    partitions, please see the fdisk manual page for additional
    information.
    Syncing disks.
    
  5. Use mkfs to create a FAT32 filesystem:

    julio@julio-acer ~  $  sudo mkfs.vfat -F 32 /dev/sdc1
    
  6. Rewrite the MBR

    julio@julio-acer ~  $  sudo dd if=/dev/zero of=/dev/sdc bs=446 count=1
    1+0 records in
    1+0 records out
    446 bytes (446 B) copied, 0.00234799 s, 190 kB/s
    
    julio@julio-acer ~  $  sudo ms-sys -s /dev/sdc
    Public domain syslinux master boot record successfully written to /dev/sdc
    
  7. Mount the external HDD

    julio@julio-acer ~  $  sudo mount /dev/sdc1 /media/pendrive/
    
  8. Install GRUB on the first partition

    julio@julio-acer ~  $  sudo grub-install - -no-floppy - -root-directory=/media/pendrive/ /dev/sdc
    
  9. Mount the .iso image

    julio@julio-acer ~  $  sudo mount -o loop ubuntu-11.04-desktop-i386.iso /media/iso/
    mount: warning: /media/iso/ seems to be mounted read-only.
    
  10. Copy the kernel and the initrd from the .iso to the /boot folder

    julio@julio-acer ~> sudo cp /media/iso/casper/{vmlinuz,initrd.lz} /media/pendrive/boot/
    
  11. Reserve a 512MB space for the casper-rw file, which will store all files and modifications made in the system.

    julio@julio-acer ~>  sudo dd if=/dev/zero of=/media/pendrive/casper-rw bs=1M count=512
    512+0 records in
    512+0 records out
    536870912 bytes (537 MB) copied, 1.92945 s, 278 MB/s
    
    julio@julio-acer ~>  sudo mkfs.ext3 -F /media/pendrive/casper-rw
    mke2fs 1.41.14 (22-Dec-2010)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    32768 inodes, 131072 blocks
    6553 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=134217728
    4 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks:
            32768, 98304
    
    Writing inode tables: done
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 38 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    
  12. Create a second partition to store the .iso

    julio@julio-acer ~> sudo fdisk /dev/sdc
        Command (m for help): n
        Command action
           e   extended
           p   primary partition (1-4)
        p
        Partition number (1-4, default 2): 2
        First sector (2099200-976773167, default 2099200):
        Using default value 2099200
        Last sector, +sectors or +size{K,M,G} (2099200-976773167, default 976773167): +730M
    
        Command (m for help): w
        The partition table has been altered!
    
        Calling ioctl() to re-read partition table.
        Syncing disks.
    
  13. Copy the files from the .iso to the second partition

    julio@julio-acer ~> sudo dd if=ubuntu-11.04-desktop-i386.iso of=/dev/sdc2
    1403484+0 records in
    1403484+0 records out
    718583808 bytes (719 MB) copied, 116.572 s, 6.2 MB/s
    
  14. Edit the Grub menu

    julio@julio-acer .../pendrive/boot/grub> cat menu.lst
    default         0
    timeout         10
    
    title           Ubuntu (Live)
    root            (hd0,0)
    kernel          /boot/vmlinuz boot=casper file=/preseed/ubuntu.seed persistent
    initrd          /boot/initrd.lz
    
  15. Unmount the disk, set the BIOS to boot from USB, and test your live USB.


Julio Batista Silva
Julio Batista Silva
Data Engineer

I’m a computer engineer passionate about science, technology, photography, and languages. Currently working as a Data Engineer in Germany.

comments powered by Disqus