#pragma section-numbers off #format wiki #pragma supplementation-page on {{{#!wiki caution If necessary use the [[http://wiki.tldp.org/Linux_on_a_Pendrive_HOWTO?action=supplementation|Discussion page]] to give comments. }}} == Discussion Page Content if any == <> ---- = Linux on a Pendrive HOWTO = Laszlo Gerencser (GerencserL ''at'' gmail) '''Revision History''' ||10.06.2009 || v1.1 - first upload unformatted || Laszlo Gerencser|| ||12.06.2009 || v1.1b - some text formatting|| Laszlo Gerencser|| ||12.06.2009 || v1.1c - text formatting|| Laszlo Gerencser|| This document describes how to install a bootable Linux on a pendrive while keeping the original pendrive functionality under Windows and other operating systems. = 1. Introduction = Linux live CD-s are useful for trying a Linux distribution but they have two problems which make the daily usage uncomfortable: they are slow and you cannot save your configuration changes and data back to the CD. Installing Linux on a pendrive is a trivial solution when you need a portable environment. There are several known methods of doing this, however, not all of them provide you with a full, constraint-free Linux environment and none of them preserves the original pendrive functionality under other operating systems, like Windows. The method described below gives you these advantages. = 2. Summary for the brave ones = We will shrink the original Fat32 partition of the pendrive and create an Ext2 partition next to it. Then we will install Linux to the newly created Ext2 partition putting the boot loader onto the pendrive's MBR. Finally we will configure the computer's BIOS to boot from the pendrive. That's all. Sounds easy? If you are a brave Linux expert, feeling lucky and eager to take the risk then you don't have to read the rest of this document, just go on and do it. May the Force be with you! = 3. What do you need? = * '''A fast pendrive with 8GB capacity at least.''' The faster the pendrive is the better the result will be. You should choose one with some kind of flash indicator which blinks when the pendrive is in use. Pendrives are slower than hard disks so a visual feedback is useful when you run Linux from it. * '''The install CD of your favourite Linux distribution.''' One with a lightweight desktop environment is recommended because full-featured desktop environments (like Gnome or KDE) can slow down your system. You can try Xubuntu, Crunchbang, Linux Mint, ZenWalk or other streamlined distributions. You can go with full-featured ones like Ubuntu, Fedora or anything if you stick to them but be prepared: they will be slow on older machines. * '''A computer with a BIOS supporting USB pendrive boot.''' Choose a computer which have no critical functions and valuable data on it because the following steps like partitioning and installing have inherent risk of system crash and data loss. = 4. Preparation = . '''4.1. Make a backup''' of the system and data on your computer. Just to be on the safe side. . '''4.2. Check your pendrive''' under Windows or other operating systems. Try to copy files from and to it. Delete all files when you have finished. (See the last chapter for troubleshooting.) . '''4.3. Boot the computer from your Linux live CD'''. We will use this system for the remaining steps. . '''4.4. Make an internet connection'''. It is not mandatory but can be useful during the long and boring process of installation. . '''4.5. Plug your pendrive in'''to the USB slot of the computer. = 5. Partitioning the pendrive = Your pendrive has one big Fat32 partition. (If not, go to the last chapter for troubleshooting.) This is the partition type Windows and other operating systems are able to use. We will shrink this partition and create a new Ext2 partition next to it which will be used to install Linux onto. The order of the partitions is important: Fat32 has to be the first one and Ext2 the second. Windows operating systems have problems with pendrives beginning with a non-Fat32 partition. We will not create swap partitions because pendrives are too slow for that purpose; your Linux and applications have to fit in the RAM. . '''5.1. Start your favourite partition editor''', GParted for example. . '''5.2. Select your pendrive to partition'''. Usually, this is the device /dev/sd''?'' where ''?'' can be replaced with a, b, c, etc. (Be aware: some systems have hard disks here!) . '''5.3. Doublecheck that you have selected the right device''', your pendrive. Check the partition and the size. You have to see one big Fat32 partition with the size of your pendrive (a bit less in some cases). WARNING: if you partition an other device your data will most probably be lost forever! . '''5.4. Shrink the Fat32 partition of your pendrive''' to a smaller size. Leave at least 4GB free space behind it for the Ext2 partition. Do not format the Fat32 partition! . '''5.5. Create the new Ext2 partition''' on the free space of your pendrive. Size it to the maximum. . '''5.6. Apply your changes and check the results'''. You should have two partitions on your pendrive now, the first is a Fat32 and the second is an Ext2. = 6. Installing Linux = We will install Linux to the newly created Ext2 partition of the pendrive and put the boot loader into the pendrive's Master Boot Record. This will need manual/expert/advanced installation or settings because automatic installations use the first hard disk as a default. . '''6.1. Start the installation of your Linux''' as if you would install it to your computer's hard disk. There is a menu item or an icon to do it in most of the distributions. . '''6.2. Choose manual/expert/advanced mode or settings''' or something similar which gives you full control on choosing the device and partition your Linux will be installed to. Choose the Ext2 partition of your pendrive. Edit the partition. Set the mount point to / (root) and the usage type to Ext2 filesystem. Let the installer format the partition. Do not use any other devices or partitions for any purpose during the installation. If you get a warning on not having a swap partition, ignore it. . '''6.3. Doublecheck that you have selected the Ext2 partition of your pendrive'''. Installing to a wrong partition can cause data loss, system crash and other things you dont want to experience. . '''6.4. Choose the pendrive as the device the boot loader (e.g: GRUB) will be installed onto'''. It is a very advanced/manual/expert setting but you have to find it somewhere. The default is hd0 most of the times which has to be changed. If you install the boot loader to the wrong place you risk data loss, system corruption and you will not be able to boot your pendrive Linux in other computers or at all. It is a critical step, abort the installation and ask for help if you are unsure. (This setting can be done in the last step of Ubuntu 9.04-like installations, for example. There is a small 'Advanced...' button below the summary of settings.) . '''6.5. Let the installation go'''. Follow the instructions of your Linux distribution. = 7. Checking the result = . '''7.1. Shut down the computer and remove the Linux live CD'''. Set the USB pendrive as the first boot device in the computer's BIOS menu and reboot from the pendrive. The Linux you have installed should boot. (Go to the last chapter if your original operating system comes up.) . '''7.2. Get an internet connection and start a system update''' after successfully booting from your pendrive. It can take a while. . '''7.3. Reboot your computer without the pendrive and the Linux CD''' to be sure you did not mess up anything on it. The computer's original operating system has to come up. . '''7.4. Try to use the pendrive under Windows''' or other operating systems. The Fat32 partition has to be usable as a normal pendrive. . '''7.5. Enjoy. It's a really cool stuff.''' = 8. Troubleshooting = * '''If you cannot access your pendrive under Windows or other operating systems''', you most probably did something wrong with the partitioning. Try to erase all partitions from the pendrive and create a new Fat32 partition with maximum size. Plug it in a computer running Windows and format it. It should help in most of the cases. You can now go back to the first step and start the whole thing again. WARNING: this will erase everything from your pendrive! * '''If your partition editor cannot resize partitions''', try an other one, GParted, for example. * '''If you cannot find where to set the pendrive as the device the boot loader will be installed to''', abort the installation immediately and ask for help. You risk the data on your computer's hard disk otherwise. * '''If you cannot boot your Linux form the pendrive:''' * Be sure that you have removed the Linux live CD * Try to set the USB pendrive as the first boot device in your computer's BIOS menu. Sometimes it is called USB disk or USB floppy disk or something like this. Try them all. * Try it with an other, newer computer. Older computers cannot boot from USB pendrive. * '''If your pendrive Linux is extremely slow''' try to use a faster pendrive. Pendrive speed can be compared to the speed of a CD-ROM with copying the same files from them. Pendrive has to be several times faster.