Difference between revisions of "Create a Bootable USB"

From Alpine Linux
Jump to: navigation, search
(syslinux.cfg edit not needed for 1.9)
(Alpine on USB: updated to match CF card document using template)
Line 1: Line 1:
= Alpine on USB =
+
= Installing Alpine on a USB Stick - Manual Process =
== Manual Process ==
 
=== What you will need ===
 
* USB memory stick
 
* Computer
 
* Alpine Linux CD
 
CD images can be downloaded from the Alpine Linux Web site (http://wiki.alpinelinux.org).
 
=== Prepare to modify USB Stick ===
 
* Insert the Alpine Linux CD into a computer.
 
* Boot the computer from the Alpine Linux CD.
 
This step may require changes to the BIOS settings to select booting from CD.
 
* Login with the username '''root'''. No password is needed.
 
* Insert the USB stick into the computer.
 
* Determine the name Alpine Linux uses for your USB stick. The following step is one way to do this.
 
  
After inserting the USB stick, run the command: '''dmesg'''. At the end of this command you should see the name of your USB stick, likely starting with '''sd'''.
+
This process applies to Alpine Linux 1.9.0 or later. See also: [[Installing Alpine on USB Automated]]
  
The remainder of these instructions will assume that your USB device is called '''/dev/sda'''
+
=== Requirements ===
=== Modify partitions ===
+
In order to follow this document, you will need:
'''fdisk /dev/sda'''
+
* Alpine Linux CD-ROM ([[Downloads|Download]] a .iso file containing an Alpine release.)
* '''p''' Print list of partitions
+
* Computer with CF card reader
* '''d''' Delete all partitions (this may take a few steps)
+
* CF card
* '''n''' Create a new partition
 
* '''p''' A primary partition
 
* '''1''' Partition number 1
 
* Use defaults for first and last cylinder (just press [Enter]).
 
* '''t''' Change partition type
 
* '''c''' Type: Win95 FAT32 (LBA)
 
* '''a''' Make the partition bootable (set boot flag)
 
* '''1''' Partition number 1
 
* '''w''' Write your changes to the device
 
  
* Remove and reinsert your USB stick
+
If you already have a running Linux system (Alpine Linux 1.8.x, Debian, Gentoo, RedHat, etc.), log in as root, insert the Alpine Linux CD-ROM into the running Linux computer, and skip the next section.
  
=== Install Syslinux on device ===
+
== Boot Alpine Linux CD-ROM ==
'''apk add syslinux dosfstools'''
+
# Insert the Alpine Linux CD into a computer.
'''dd if=/usr/share/syslinux/mbr.bin of=/dev/sda'''
+
# Boot the computer from the Alpine Linux CD-ROM.
'''mkdosfs -F32 /dev/sda1'''
+
#* This step may require changes to the BIOS settings to select booting from CD.  
'''syslinux /dev/sda1'''
+
# Login with the username ''root''. No password is needed.
=== Copy Alpine Linux to device ===
 
'''mount -t vfat /dev/sda1 /media/usb'''
 
'''cd /media/cdrom
 
'''cp -a * .alpine-release /media/usb'''
 
'''sync'''
 
=== Modify the syslinux.cfg file ===
 
* If installing alpine 1.8 or earlier, change the line "default generic-hd" to say "default generic-usb".
 
  
== Automated Process ==
+
{{Copying Alpine to Flash|USB stick}}
Starting (and apparently ending) with Alpine 1.9 alpha 13 we distribute both a .img file and a exe file containing USB images.
 
 
 
Please note that writing the Alpine 1.9 image to your USB stick will overwrite all its existing content.
 
 
 
The images are premade the same size as the .iso image + 8MB for an apk overlay. This means that no matter wither you have an 8GB memory stick or a 512MB memory stick, you will only have 8MB free when booting from it.
 
 
 
Download the latest Alpine 1.9:
 
* Linux users: [[Downloads|download]] .img file  containing Alpine ''(e.g. {{Latest_1.9_alpine_gz-mirror}}{{Latest_1.9_alpine_img-filename}})''
 
* Windows users: [[Downloads|download]] .img file  containing Alpine ''(e.g. {{Latest_1.9_alpine_gz-mirror}}{{Latest_1.9_alpine_exe-filename}})''
 
* Get a USB-mem with at least 400MB of free space
 
 
 
=== Installing to media ===
 
==== Linux users ====
 
* Run the following command:
 
  dd if=/path/to/img/file of=/dev/sdX
 
* Where sdX is your USB devive. You can find your USB device by inserting it into your computer and run the following command:
 
  dmesg
 
* This command will tell you the device name of your newly inserted USB device.
 
* Please note that most desktop environments automatically mounts inserted USB devices. You should unmount it before running the "dd" command above
 
 
 
==== Windows users ====
 
[[{{ns:image}}:USB-extract.png]]
 
* Download the self extracting exe file (packaged with 7zip), and run it as administrator
 
* It will self exctract to a temporary location and launch an image writing program
 
[[{{ns:image}}:USB-write.png]]
 
* Select the removable drive letter you want to use, and click the "Write" button
 
* Wait until its finished, and you will have your usb drive ready to use.
 
 
 
== Boot Alpine ==
 
Put your AlpineLinux-USB in a computer that can boot from USB.<BR>
 
'''''Note:''' You might need to change boot-order in your BIOS-settings in order to boot from USB.''
 
 
 
When your computer has booted you will get prompted for a username.<BR>
 
On a clean AlpineLinux you just enter ''root'' and no password and you will get logged on to your Alpine linux.
 
  
 
{{Installing_Alpine_see_also}}
 
{{Installing_Alpine_see_also}}

Revision as of 14:59, 9 October 2009

Installing Alpine on a USB Stick - Manual Process

This process applies to Alpine Linux 1.9.0 or later. See also: Installing Alpine on USB Automated

Requirements

In order to follow this document, you will need:

  • Alpine Linux CD-ROM (Download a .iso file containing an Alpine release.)
  • Computer with CF card reader
  • CF card

If you already have a running Linux system (Alpine Linux 1.8.x, Debian, Gentoo, RedHat, etc.), log in as root, insert the Alpine Linux CD-ROM into the running Linux computer, and skip the next section.

Boot Alpine Linux CD-ROM

  1. Insert the Alpine Linux CD into a computer.
  2. Boot the computer from the Alpine Linux CD-ROM.
    • This step may require changes to the BIOS settings to select booting from CD.
  3. Login with the username root. No password is needed.

Boot Alpine Linux CD-ROM

  1. Insert the Alpine Linux CD-ROM into a computer.
  2. Boot the computer from the Alpine Linux CD-ROM.
    • This step may require changes to the BIOS settings to select booting from CD.
  3. Login with the username root. No password is needed.
Tip: If you're not able to boot from the CD, then another option is to boot from a regular Alpine installation, and manually mount the ISO image to /media/cdrom.

Determine the Device Name of the USB stick

Determine the name your computer uses for your USB stick. The following step is one way to do this.

  1. After inserting the USB stick, run the command:
    • dmesg

    • At the end of this command you should see the name of your USB stick, likely starting with "sd". (For example: "sda").
    • The remainder of this document will assume that your USB stick is called /dev/sda
  2. Use "fdisk -l" or "blkid" to check the device name by size or label

Format USB stick

Run fdisk (replacing sdX with your USB stick name):

fdisk /dev/sdX

  1. (Optional) - Create new partition table with one FAT32 partition
    • d Delete all partitions (this may take a few steps)
    • n Create a new partition
    • p A primary partition
    • 1 Partition number 1
      • Use defaults for first and last cylinder (just press [Enter] twice).
    • t Change partition type
    • c Partition type (Win95 FAT32/LBA)
  2. Verify that the primary partition is bootable
    • p Print list of partitions
    • If there is no '*' next to the first partition, follow the next steps:
      • a Make the partition bootable (set boot flag)
      • 1 Partition number 1
  3. w Write your changes to the device

Format the new partition with:

mkfs.vfat /dev/sdX1

Add Alpine Linux to the USB stick

To boot from your USB stick you need to copy the contents of the CDROM to the USB stick and make it bootable. Those two operations can be automated with the setup-bootable tool or can be done manually.

See also notes to create an Alpine Linux USB stick from within KVM with setup-bootable.

Note: If the following commands fail due to 'No such file or directory', you may have to remove and reinsert the USB stick, or even reboot, to get /dev/sda1 to appear

Automated

Tip: If using Alpine Linux 1.10.4 or newer, you can use this section to complete the install. Otherwise, follow the Manual steps below.
Note: The target partition has to be formatted. Use the mkdosfs command from the Manual steps below if needed.
  1. Run the setup-alpine script to setup network(Alpine Linux 3.3 not contain syslinux), answer the last three questions as 'none'
    1. Which disk(s) would you like to use: none
    2. Enter where to store configs: none
    3. Enter apk cache directory: none
  2. Run "apk add syslinux" to install syslinux package
  3. Run "modprobe vfat" to load vfat kernel module
  4. Run the setup-bootable script to add Alpine Linux to the USB stick and make it bootable (replacing sda with your USB stick name):

    setup-bootable /media/cdrom /dev/sda1

    1. if "Resource busy" occurs, maybe the old files on /media/sda1, "rm /media/sda1/.alpine-release" and "reboot" to try again.
Note: If you get something like 'Failed to mount /dev/sda1 on /media/sda1' when running the above setup-bootable command, you might want to try running:

modprobe vfat

and then try re-run the setup-bootable command as described above.
Tango-dialog-warning.png
Warning: If you are installing to a USB Stick, you may need to modify the syslinux.cfg file to say usbdisk as described below, or you will face possible problems booting and definite problems with the package cache. Recent versions of setup-bootable will specify the alpine_dev using a UUID instead, so it should work properly by default.


Manual

  1. (Optional) - If you created a new partition above, format the USB stick with a FAT32 filesystem (replacing sda with your USB stick name):

    apk add dosfstools
    mkdosfs -F32 /dev/sda1

  2. Install syslinux and MBR (replacing sda with your USB stick name):

    apk add syslinux
    dd if=/usr/share/syslinux/mbr.bin of=/dev/sda
    syslinux /dev/sda1

  3. Copy the files to the USB stick (replacing sda with your USB stick name):

    mkdir -p /media/sda1 mount -t vfat /dev/sda1 /media/sda1 cd /media/cdrom cp -a .alpine-release * /media/sda1/ umount /media/sda1

  4. (Optional) Remove any apkovl files that were transfered as part of the copy process. This should be done if you wish to have a fresh install. Replace sda with your USB stick name)

    mount -t vfat /dev/sda1 /media/sda1 rm /media/sda1/*.apkovl.tar.gz umount /media/sda1

Troubleshooting

Wrong Device Name

If you cannot boot from the USB stick and you see something like:

Mounting boot media failed.
initramfs emergency recovery shell launched. Type 'exit' to continue boot

then it is likely that the device name in syslinux.cfg is wrong. You should replace the device name in this line:

append initrd=/boot/grsec.gz alpine_dev=usbdisk:vfat modules=loop,cramfs,sd-mod,usb-storage quiet

with the proper device name.

  • For boot from USB, the device name should be 'usbdisk' (as shown above)
  • For other options, you can run cat /proc/partitions to see the available disks (i.e. 'sda' or 'sdb')

Non-FAT32 Filesystems

When your USB stick is formatted with a filesystem other than FAT32, you might have to specify the necessary filesystem modules in the boot parameters.

To do so, mount the USB stick and change the syslinux.cfg file line from

append initrd=/boot/grsec.gz alpine_dev=usbdisk:vfat modules=loop,cramfs,sd-mod,usb-storage quiet

to

append initrd=/boot/grsec.gz alpine_dev=usbdisk:ext3 modules=loop,cramfs,sd-mod,usb-storage,ext3 quiet

in the case of an ext3 formatted partition. A similar procedure might apply to other filesystems (if they are supported by syslinux and the Alpine Linux kernel).

Alpine Linux has some special applications that helps you to use it in the way you want.
Some of the first scripts you are suggested to use is:

  • setup-alpine (Configures all basic things on your Alpine Linux)
  • setup-acf (was named setup-webconf before Alpine 1.9 beta 4) (Configures ACF (webconfiguration) so you can manage your box through https)
Note: Just type any of the above commands on your console and hit Enter to execute the script.

Other useful pages