Using a USB key to install linux
Posted on February 10, 2011
Download a script which runs all the steps here.
You have arrived at a download URL for a linux distribution which you just cannot wait to install. You are looking at an ISO file but you do not have a CD or DVD or just do not want to use it. You have a USB key large enough to fit the ISO just fine. What now?
The content of the ISO file can be copied to USB directly and will work. This works with Debian and Arch Linux but does not work with Ubuntu:
dd if=distro.iso of=/dev/sdX
The ISO image will not boot if copied verbatim to a DVD. This is what this article is about.
Prerequisities
- A blank USB memory stick or one that could be blanked entirely.
- An ISO file with the linux distribution. We will use the current version of Linux Mint.
- A running distribution which we will use to carry out the procedure: Ubuntu.
- You are logged in as root.
Commands
Insert the USB and find which letter it has been assigned. Look at the output of dmesg to find out, and use mount to see if and where the USB has been mounted. Unmout all those locations using umount /dev/sdXY where XY is the partition designation.
Now you are ready to start.
Wipe out the whole USB stick:
dd if=/dev/zero of=/dev/sdX bs=1k count=16k
Use the whole USB stick for the partition and do not create partitions:
mkdosfs -I /dev/sdX
Let the OS reread the partition table:
sfdisk -R /dev/sdX
Install a boot loader on the new USB disk:
syslinux /dev/sdX
Mount it:
mount /dev/sdX /mnt
Now, mount the ISO file to copy the content later on:
mkdir /tmp/isofile mount -o loop distro.iso /tmp/isofile
Find the isolinux directory in the ISO. It is in the root for Linux Mint but you may find it elsewhere on other distributions (boot/isolinux for example).
Copy the content of the directory to the root of the USB media, and rename the files accordingly:
cd /mnt rsync -av --progress /tmp/isofile/isolinux/ ./ mv isolinux.cfg syslinux.cfg rm -f isolinux.bin
Now comes the most important part of the installation process. You will need to edit syslinux.cfg to match the current setup. For the Linux Mint ISO, this means removing /cdrom from the filepaths in it:
sed 's~/cdrom~~g' -i syslinux.cfg
Copy the rest of the files:
rsync -av --progress /tmp/isofile/ ./ --exclude isolinux
Last but not the very least for Linux Mint, you need to replace vesamenu.c32 with the version that you used with syslinux, i.e. the current machine's:
cp /usr/lib/syslinux/vesamenu.c32 .
You may need to look for this file with locate vesamenu.c32 if you do not find it there.
This step was a lot hit-and-miss once I could not boot the new system.
Unmount all and boot with the new USB stick:
cd - umount /mnt umount /tmp/isofile
Conclusion
You should be able to boot from your USB stick now.
Download a script which runs all the steps.
Credits
- Bootable USB Key from Knoppix.
- Not a COM32R Image Error.