Include:Copying Alpine to Flash: Difference between revisions

From Alpine Linux
(structure)
Line 1: Line 1:
=== Boot Alpine Linux CD-ROM ===
The following part describes various ways how to create bootable USB stick with Alpine Linux.
 
== Clone ISO image content to USB stick (Alpine Linux from 3.3.0 and later) ==
 
From Alpine Linux 3.3.0, the generated ISO's are a hybridISO, which means they contain a valid MBR and can be raw copied directly to the USB stick, Hard Drive (If you really know what you're doing), or burnt to a CD/DVD.
 
The following ''dd'' instructions follow helpful guidance from https://wiki.voidlinux.eu/Live_Images wholly or in part.
 
If the USB stick is in a Unix/Linux/OSX system, you will need to find out what the USB device is.  There are various utilities to determine the device name (e.g. {{Path|/dev/sdx}}) for your USB device.  One way is:
 
$ sudo fdisk -l
 
If it is still unclear which is your USB's device name, in Linux you could try <code>sudo lsblk -a</code> ;  or use {{Pkg|parted}} (<code>sudo parted -l</code>).
 
Then, in order to dd the iso, ensure that your usb drive is '''not''' mounted, as various desktop environments automatically mount usb pen drives:
 
$ sudo umount /dev/sdx
 
Next, change to the directory where your Alpine .iso file is located, for example:
 
$ cd ~/Downloads
 
{{Warning|The following instruction will '''destroy''' data on the device being written to - be sure that you have identified your USB device name correctly first!}}
 
Then you can use '''dd''' to copy the iso to it.  Change <code>alpine.iso</code> in the following command to the name of your '''.iso''' file; and change <code>/dev/sdx</code> to the name of your pen drive's device name.  The following command may take a few minutes to execute:
  $ sudo dd if=alpine.iso of=/dev/sdx && sync
 
== Setup USB stick as usual installation from ISO image ==
 
# Insert the Alpine Linux CD-ROM into a computer.
# Insert the Alpine Linux CD-ROM into a computer.
# Boot the computer from the Alpine Linux CD-ROM.
# Boot the computer from the Alpine Linux CD-ROM.
Line 61: Line 89:
{{Warning|If you are installing to a USB Stick, you may need to modify the {{Path|syslinux.cfg}} file to say <code>usbdisk</code> as [[#Wrong_Device_Name|described below]], or you will face possible problems booting and definite problems with the package cache. Recent versions of <code>setup-bootable</code> will specify the alpine_dev using a UUID instead, so it should work properly by default.}}
{{Warning|If you are installing to a USB Stick, you may need to modify the {{Path|syslinux.cfg}} file to say <code>usbdisk</code> as [[#Wrong_Device_Name|described below]], or you will face possible problems booting and definite problems with the package cache. Recent versions of <code>setup-bootable</code> will specify the alpine_dev using a UUID instead, so it should work properly by default.}}


==== Manual ====
== Copy ISO content to USB stick as individual files ==
 
# (''Optional'') - If you created a new partition above, format the {{{1|flash medium}}} with a FAT32 filesystem (replacing sda with your {{{1|flash medium}}} name):
# (''Optional'') - If you created a new partition above, format the {{{1|flash medium}}} with a FAT32 filesystem (replacing sda with your {{{1|flash medium}}} name):
#: {{Cmd|apk add dosfstools<BR>mkdosfs -F32 /dev/sda1}}
#: {{Cmd|apk add dosfstools<BR>mkdosfs -F32 /dev/sda1}}

Revision as of 12:59, 19 October 2020

The following part describes various ways how to create bootable USB stick with Alpine Linux.

Clone ISO image content to USB stick (Alpine Linux from 3.3.0 and later)

From Alpine Linux 3.3.0, the generated ISO's are a hybridISO, which means they contain a valid MBR and can be raw copied directly to the USB stick, Hard Drive (If you really know what you're doing), or burnt to a CD/DVD.

The following dd instructions follow helpful guidance from https://wiki.voidlinux.eu/Live_Images wholly or in part.

If the USB stick is in a Unix/Linux/OSX system, you will need to find out what the USB device is. There are various utilities to determine the device name (e.g. /dev/sdx) for your USB device. One way is:

$ sudo fdisk -l

If it is still unclear which is your USB's device name, in Linux you could try sudo lsblk -a ; or use parted (sudo parted -l).

Then, in order to dd the iso, ensure that your usb drive is not mounted, as various desktop environments automatically mount usb pen drives:

$ sudo umount /dev/sdx

Next, change to the directory where your Alpine .iso file is located, for example:

$ cd ~/Downloads
Warning: The following instruction will destroy data on the device being written to - be sure that you have identified your USB device name correctly first!


Then you can use dd to copy the iso to it. Change alpine.iso in the following command to the name of your .iso file; and change /dev/sdx to the name of your pen drive's device name. The following command may take a few minutes to execute:

 $ sudo dd if=alpine.iso of=/dev/sdx && sync

Setup USB stick as usual installation from ISO image

  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 Flash Medium

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

  1. After inserting the flash medium, run the command:
    • dmesg

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

Format Flash Medium

Run fdisk (replacing sdX with your flash medium 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 Flash Medium

To boot from your flash medium you need to copy the contents of the CDROM to the flash medium 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 flash medium, 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 flash medium and make it bootable (replacing sda with your flash medium 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.
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.


Copy ISO content to USB stick as individual files

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

    apk add dosfstools
    mkdosfs -F32 /dev/sda1

  2. Install syslinux and MBR (replacing sda with your flash medium name):

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

  3. Copy the files to the flash medium (replacing sda with your flash medium 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 flash medium 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 flash medium 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 flash medium 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 flash medium 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).