How to install Ubuntu from a USB stick

I found myself having to reinstall a server with no CD drive available. I had an old USB stick (256MB) lying around so I thought it would be nice to use that as an installer. Here's how I did it.

  • Install syslinux and mbr, which you will need later: apt-get install syslinux mbr
  • Connect the USB stick and use dmesg to find out what the device name is. Then, use fdisk to make a partition. Make it type fat16 and assign the boot flag to the partition. Quit fdisk.
  • Type mkfs.vfat /dev/sdb1 (substitute your device name) to create a fat filesystem.
  • Type syslinux /dev/sdb1 to install the syslinux bootloader.
  • Get one of the mini.iso's from Ubuntu. I used the amd64 version but there is also an i386 version (Links to 8.10, Intrepid Ibex).
  • Mount the .iso: mount -o loop ~/mini.iso /media/cdrom0
  • Take out the USB stick and connect it again. It will be mounted automatically (in my case at /media/disk).
  • Copy the contents to the USB stick: cp -r /media/cdrom0/* /media/disk/
  • Rename isolinux.cfg: cd /media/disk; mv isolinux.cfg syslinux.cfg
  • Finally, install a Master Boot Record on the stick: install-mbr /dev/sdb

Use the stick to boot the server and perform the installation as usual.

Note: The installer finishes by installing Grub in the MBR of the first harddisk it encounters. This will be a problem if the USB Stick is detected as the first. The result will be an unbootable HD (Grub error 2) and an unusable stick (Grub error 15). It might also be that the server will boot from the HD if you insert the USB stick. This will depend on the configuration of your server. The solution is to re-prepare the stick like above, boot from it, enter rescue mode, answer all the questions until you get to the bootloader part, and install Grub in the MBR of the right disk.

Reference: Ubuntu Community Docs

Trackback URL for this post:

http://www.func.nl/trackback/89

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".