Classic install or sys mode on Raspberry Pi: Difference between revisions
The default (talk | contribs) m (his -> it's: grammar error?) |
(make update boot partition(keep system partition/setup-alpine layout) section step to step correct) |
||
(18 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
{{TOC right}} | {{TOC right}} | ||
A | A how-to for classic ("sys mode") installation. | ||
This method works with a desktop PC under Ubuntu and other Linuxes. | This method works with a desktop PC under Ubuntu and other Linuxes. | ||
Line 7: | Line 7: | ||
= Preparation = | = Preparation = | ||
[https://alpinelinux.org/downloads/ Download] the Alpine for Raspberry Pi tarball. Use the [[Raspberry_Pi#Compability_list|compatibility list]] when choosing image/file to download. | |||
'''Sha256''' and '''GPG''' links appear next to the link to check the download. | '''Sha256''' and '''GPG''' links appear next to the link to check the download. | ||
Create an MBR partition table with two partitions on an 8 GB (or larger) class 10 sd-card: | |||
* First | * First one, a '''fat16''' type, of 256MB. You may have to set <code>boot</code> and <code>lba</code> flags | ||
* | * The second one, an '''ext4''' type, occupying the remaining space on the media | ||
Eject and insert your SD card | Eject and re-insert your SD card to ensure recognition of all the partitions. | ||
Go into the first partition ('''fat16'''). | |||
Untar the archive with {{pkg|tar}}: | Untar the archive with {{pkg|tar|arch=}}: | ||
tar zxvf ~/Download/alpine-rpi- | tar zxvf ~/Download/alpine-rpi-{{AlpineLatest}}-armhf.tar.gz | ||
If using the UART is required, add a file named <code>usercfg.txt</code> into the partition containing the following single line: | |||
enable_uart=1 | enable_uart=1 | ||
For headless use, you can add the following parameters to maximize available memory (32 megs is required for the rpi bootloader): | |||
gpu_mem=32 | gpu_mem=32 | ||
to enable audio support: | |||
dtparam=audio=on | dtparam=audio=on | ||
Eject the SD card properly | Eject the SD card properly. Insert it into the Raspberry Pi. Plug in a usb keyboard as well as the HDMI and network cables. Power on. | ||
When | When the command prompt displays, log in as root. (no password) | ||
== OSX Preparation: creating a FAT16 partition on microSD == | == OSX Preparation: creating a FAT16 partition on microSD == | ||
Line 41: | Line 41: | ||
To create a FAT16 partition with OSX, use the diskutil program and a USB microSD card reader (I used an older version of this: https://www.bestbuy.com/site/insignia-usb-3-0-memory-card-reader/5787406.p?skuId=5787406). | To create a FAT16 partition with OSX, use the diskutil program and a USB microSD card reader (I used an older version of this: https://www.bestbuy.com/site/insignia-usb-3-0-memory-card-reader/5787406.p?skuId=5787406). | ||
Put the microSD card in reader | Put the microSD card in the reader. Connect the reader to a USB port and type <code>ls -1 /Volumes</code> in a terminal. Note the name of the microSD volume; for example, VOL1 in the output below: | ||
$ ls -1 /Volumes | $ ls -1 /Volumes | ||
Macintosh HD | Macintosh HD | ||
Line 48: | Line 48: | ||
$ | $ | ||
Unmount the reader | Unmount the reader. Disconnect it and re-run <code>ls -1 /Volumes</code>. Verify the microSD volume name is no longer listed, then re-insert the USB reader. | ||
Find the mount point of your microSD volume | Find the mount point of your microSD volume. For example, disk3 in the output below: | ||
$ diskutil list VOL1 | $ diskutil list VOL1 | ||
/dev/disk3 (external, physical): | /dev/disk3 (external, physical): | ||
Line 60: | Line 60: | ||
$ | $ | ||
(For help | (For help with the diskutil command, type <code>diskutil</code> to list all command verbs. For help on a specific verb, add the verb. For example, <code>diskutil partitionDisk</code>) | ||
Destroy all the existing partitions on the microSD card and create two new ones: | Destroy all the existing partitions on the microSD card and create two new ones: | ||
Line 80: | Line 80: | ||
#: TYPE NAME SIZE IDENTIFIER | #: TYPE NAME SIZE IDENTIFIER | ||
0: FDisk_partition_scheme *31.4 GB disk3 | 0: FDisk_partition_scheme *31.4 GB disk3 | ||
1: DOS_FAT_16 VOL1 256.0 MB disk3s1 | |||
$ | $ | ||
Change your current working directory to the new FAT16 partition | Change your current working directory to the new FAT16 partition then continue with the untar instruction in the parent prep section. | ||
$ cd /Volumes/VOL1/ | $ cd /Volumes/VOL1/ | ||
Line 93: | Line 93: | ||
setup-alpine | setup-alpine | ||
Set the | Set the keyboard map, the timezone, how to connect to the network ('''dhcp''' is the best method), say '''none''' at <code>save config</code> and <code>save cache</code>. | ||
apk update | apk update | ||
Line 99: | Line 99: | ||
If the extra space in the sd card was left empty, a partition must be created now: | If the extra space in the sd card was left empty, a partition must be created now: | ||
apk add cfdisk | apk add {{pkg|cfdisk|arch=*}} {{pkg|e2fsprogs|arch=*}} # or the tool of your choice | ||
cfdisk /dev/mmcblk0 # create the new partition with the free space | cfdisk /dev/mmcblk0 # create the new partition with the free space | ||
mkfs.ext4 /dev/mmcblk0p2 # create the ext4 filesystem in the new partition | mkfs.ext4 /dev/mmcblk0p2 # create the ext4 filesystem in the new partition | ||
Raspberry Pi has no | Raspberry Pi has no hardware clock, so synchronize with an ntp server: | ||
apk add chrony | apk add {{pkg|chrony|arch=a*}} | ||
service chronyd restart | service chronyd restart | ||
{{warning | 22 June 2021 - There is | {{warning | 22 June 2021 - There is a bug in Alpine 3.12.x and older that causes setup-disk to fail on ext4 mounts on Raspberry Pi. The work around is marked in the instructions below. <br />{{Issue|12353}} }} | ||
mount /dev/mmcblk0p2 /mnt | mount /dev/mmcblk0p2 /mnt # The second partition, in ext4 format, where Alpine Linux is installing in sys mode | ||
export FORCE_BOOTFS=1 # work around for issue 12353 | export FORCE_BOOTFS=1 # work around for issue 12353 | ||
setup-disk -m sys /mnt | setup-disk -m sys /mnt | ||
mount -o remount,rw /media/mmcblk0p1 # An update in the first partition is required for the next reboot. | mount -o remount,rw /media/mmcblk0p1 # An update in the first partition is required for the next reboot. | ||
You may get some warning about syslinux when you run setup-disk. You can safely ignore this. | You may get some warning about syslinux when you run setup-disk. You can safely ignore this. | ||
== Update boot partition (keep alpine-rpi* image layout) == | |||
From here we can either update boot partition to keep the alpine-rpi* image layout | |||
or to keep the system partition/setup-alpine's layout (see next section). | |||
We only need one of the two. Not both. | |||
Clean up the boot folder in the first partition to drop unused files: | Clean up the boot folder in the first partition to drop unused files: | ||
Line 122: | Line 126: | ||
rm -f /media/mmcblk0p1/boot/* | rm -f /media/mmcblk0p1/boot/* | ||
cd /mnt # We are in the second partition | cd /mnt # We are in the second partition | ||
rm boot/boot # Drop the unused | rm boot/boot # Drop the unused symbolic link | ||
Move the image and | Move the image and initramfs for Alpine Linux into the right place: | ||
mv boot/* /media/mmcblk0p1/boot/ | mv boot/* /media/mmcblk0p1/boot/ | ||
Line 130: | Line 134: | ||
mkdir media/mmcblk0p1 # It's the mount point for the first partition on the next reboot | mkdir media/mmcblk0p1 # It's the mount point for the first partition on the next reboot | ||
Don't worry about the error | Don't worry about the error when you execute the following: | ||
ln -s media/mmcblk0p1/boot boot | ln -s media/mmcblk0p1/boot boot | ||
== Update boot partition (keep system partition/setup-alpine layout) == | |||
It turns out that the system partition created by setup-alpine has a working boot layout. To keep this, perform the following steps '''instead''' of the steps in the previous chapter. | |||
Clean up the boot / first partition to drop unused files: | |||
rm -Rf /media/mmcblk0p1/* | |||
cd /mnt # We are in the second partition | |||
rm boot/boot # Drop the unused symbolink link | |||
Move the boot folder created by setup-alpine into the right place: | |||
cd /media/mmcblk0p1 | |||
mkdir boot | |||
cd /mnt | |||
mv boot/* /media/mmcblk0p1/ | |||
rm -Rf boot | |||
mkdir media/mmcblk0p1 # It's the mount point for the first partition on the next reboot | |||
Don't worry about the error when you execute the following: | |||
ln -s media/mmcblk0p1 boot | |||
== End of update boot partition - continue here in both cases == | |||
Update <code>/etc/fstab</code>: | Update <code>/etc/fstab</code>: | ||
Line 141: | Line 170: | ||
cd /media/mmcblk0p1 | cd /media/mmcblk0p1 | ||
If you want to | If you want to activate the edge repository: | ||
sed -i '/edge/s/^#//' etc/apk/repositories # But enable the repository for community if you want vim, mc, php, apache, nginx, etc. | sed -i '/edge/s/^#//' etc/apk/repositories # But enable the repository for community if you want vim, mc, php, apache, nginx, etc. | ||
Line 147: | Line 176: | ||
contains a line that starts with <code>/root</code>, then use sed: | contains a line that starts with <code>/root</code>, then use sed: | ||
sed -i 's/$/root=\/dev\/mmcblk0p2 /' /media/mmcblk0p1/cmdline.txt | sed -i 's/$/ root=\/dev\/mmcblk0p2 /' /media/mmcblk0p1/cmdline.txt | ||
reboot | reboot | ||
That works on '''Raspberry Pi 3B''' and '''1B''', but if you have the '''1B''' version, | That works on '''Raspberry Pi 3B''' and '''1B''', but if you have the '''1B''' version, you'll need to be very, very patient (several tens of minutes). | ||
If a hard disk is connected via '''usb''', you can replace the <code>/dev/mmcblk0p2</code> above with <code>/dev/sda1</code>, for example. | If a hard disk is connected via '''usb''', you can replace the <code>/dev/mmcblk0p2</code> above with <code>/dev/sda1</code>, for example. | ||
If you don't | If you don't want to use '''sed''', you can use the nano editor instead, after executing the following command: | ||
apk add nano | apk add {{pkg|nano|arch=a*}} | ||
= Post-installation = | = Post-installation = | ||
See the [[Raspberry_Pi#Post_Installation]] for common post-installation steps. | |||
Additionally, the following may be of value on a sys mode installation: | |||
If you want a cool editor ({{Pkg|vim}}), a file manager ({{Pkg|mc}}), and to determine which tasks are running and which services are starting on boot ({{Pkg|htop}}), | If you want a cool editor ({{Pkg|vim}}), a file manager ({{Pkg|mc}}), and to determine which tasks are running and which services are starting on boot ({{Pkg|htop}}), install the packages with this command: | ||
apk add vim mc htop | apk add {{pkg|vim|arch=a*}} {{pkg|mc|arch=a*}} {{pkg|htop|arch=a*}} | ||
The '''RPI 3B''' has wifi on board | The '''RPI 3B''' has wifi on board. To start the service for the encrypted key using wpa2 protocol: | ||
apk add wpa_supplicant | apk add {{pkg|wpa_supplicant|arch=a*}} | ||
rc-update add wpa_supplicant boot | rc-update add wpa_supplicant boot | ||
service wpa_supplicant start | service wpa_supplicant start | ||
setup-interfaces | setup-interfaces | ||
Replace the IP address by dhcp for all the interfaces if necessary; select the SSID network for wifi | Replace the IP address by dhcp for all the interfaces if necessary; select the SSID network for wifi, add the password. | ||
ip addr # to | ip addr # to find the IP address for all interfaces | ||
If you want to connect | If you want to connect to your RPI via <code>ssh</code>, an additional user (''foo'') and the {{Pkg|sudo|arch=*}} package are required because it's forbidden to connect as root: | ||
apk add sudo | apk add sudo | ||
Line 198: | Line 217: | ||
= Troubleshooting = | = Troubleshooting = | ||
Following the | Following the preparation instructions for setting up the boot partition as outlined, using the armv7 image (3.10.3), my rpi2 would not even boot, and I was trapped at the dreaded rainbow screen, with the green led blinking a few times in a row, repeatedly. | ||
The rpi2 I had appears to require '''fat32''' for the boot partition, NOT '''fat16''' as suggested in | The rpi2 I had appears to require '''fat32''' for the boot partition, NOT '''fat16''' as suggested in the instructions. Use linux fdisk to set the boot partition type as "c" (for fat32/lba) and set the '''lba''' and '''boot''' flags for the partition as suggested. Create the boot partition filesystem as fat32 with: | ||
mkdosfs -F 32 /dev/sdX1 | mkdosfs -F 32 /dev/sdX1 | ||
Mount and | Mount and unpacke the tarball to that, and everything should work as documented after the prep instructions. | ||
After booting you may | After booting, you may find less system memory available than you expect. Currently the Pi requires a minimum of 32 megs of memory for the gpu, to boot unless you have the cut down boot loader installed, in which case you can use 16. However, you may find more gpu memory is still being used, even if you configure it for less, if you enable audio or camera support. To find out how your system is actually split: | ||
apk add raspberrypi | {{Note|Directions below are for Alpine versions older than 3.18... Help wanted: Is there something equivalent in current versions?}} | ||
apk add {{pkg|raspberrypi|arch=*|branch=v3.17}} | |||
/opt/vc/bin/vcgencmd get_mem gpu | /opt/vc/bin/vcgencmd get_mem gpu | ||
/opt/vc/bin/vcgencmd get_mem arm | /opt/vc/bin/vcgencmd get_mem arm |
Latest revision as of 11:33, 6 September 2024
A how-to for classic ("sys mode") installation.
This method works with a desktop PC under Ubuntu and other Linuxes.
Preparation
Download the Alpine for Raspberry Pi tarball. Use the compatibility list when choosing image/file to download. Sha256 and GPG links appear next to the link to check the download.
Create an MBR partition table with two partitions on an 8 GB (or larger) class 10 sd-card:
- First one, a fat16 type, of 256MB. You may have to set
boot
andlba
flags - The second one, an ext4 type, occupying the remaining space on the media
Eject and re-insert your SD card to ensure recognition of all the partitions.
Go into the first partition (fat16).
Untar the archive with tar:
tar zxvf ~/Download/alpine-rpi-3.20.3-armhf.tar.gz
If using the UART is required, add a file named usercfg.txt
into the partition containing the following single line:
enable_uart=1
For headless use, you can add the following parameters to maximize available memory (32 megs is required for the rpi bootloader):
gpu_mem=32
to enable audio support:
dtparam=audio=on
Eject the SD card properly. Insert it into the Raspberry Pi. Plug in a usb keyboard as well as the HDMI and network cables. Power on.
When the command prompt displays, log in as root. (no password)
OSX Preparation: creating a FAT16 partition on microSD
To create a FAT16 partition with OSX, use the diskutil program and a USB microSD card reader (I used an older version of this: https://www.bestbuy.com/site/insignia-usb-3-0-memory-card-reader/5787406.p?skuId=5787406).
Put the microSD card in the reader. Connect the reader to a USB port and type ls -1 /Volumes
in a terminal. Note the name of the microSD volume; for example, VOL1 in the output below:
$ ls -1 /Volumes Macintosh HD Preboot VOL1 $
Unmount the reader. Disconnect it and re-run ls -1 /Volumes
. Verify the microSD volume name is no longer listed, then re-insert the USB reader.
Find the mount point of your microSD volume. For example, disk3 in the output below:
$ diskutil list VOL1 /dev/disk3 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *31.4 GB disk3 1: DOS_FAT_16 VOL1 256.0 MB disk3s1 2: Linux 30.0 GB disk3s2 3: Linux_Swap 1.2 GB disk3s3 $
(For help with the diskutil command, type diskutil
to list all command verbs. For help on a specific verb, add the verb. For example, diskutil partitionDisk
)
Destroy all the existing partitions on the microSD card and create two new ones:
- a 256MB, FAT16, DOS-compatible partition and
- a free space gap for the rest of the card
$ diskutil partitionDisk disk3 MBR "MS-DOS FAT16" VOL1 256MB "Free Space" VOL2 R Started partitioning on disk3 Unmounting disk Creating the partition map Waiting for partitions to activate Formatting disk3s1 as MS-DOS (FAT16) with name VOL1 512 bytes per physical sector /dev/rdisk3s1: 499472 sectors in 62434 FAT16 clusters (4096 bytes/cluster) bps=512 spc=8 res=1 nft=2 rde=512 mid=0xf8 spf=244 spt=32 hds=32 hid=2 drv=0x80 bsec=500000 Mounting disk Finished partitioning on disk3 /dev/disk3 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *31.4 GB disk3 1: DOS_FAT_16 VOL1 256.0 MB disk3s1 $
Change your current working directory to the new FAT16 partition then continue with the untar instruction in the parent prep section.
$ cd /Volumes/VOL1/
Installation
Execute the following commands. Make sure there is an internet connection available otherwise setting up the apk mirrors will fail.
setup-alpine
Set the keyboard map, the timezone, how to connect to the network (dhcp is the best method), say none at save config
and save cache
.
apk update
If the extra space in the sd card was left empty, a partition must be created now:
apk add cfdisk e2fsprogs # or the tool of your choice cfdisk /dev/mmcblk0 # create the new partition with the free space mkfs.ext4 /dev/mmcblk0p2 # create the ext4 filesystem in the new partition
Raspberry Pi has no hardware clock, so synchronize with an ntp server:
apk add chrony
service chronyd restart
#12353
mount /dev/mmcblk0p2 /mnt # The second partition, in ext4 format, where Alpine Linux is installing in sys mode export FORCE_BOOTFS=1 # work around for issue 12353 setup-disk -m sys /mnt mount -o remount,rw /media/mmcblk0p1 # An update in the first partition is required for the next reboot.
You may get some warning about syslinux when you run setup-disk. You can safely ignore this.
Update boot partition (keep alpine-rpi* image layout)
From here we can either update boot partition to keep the alpine-rpi* image layout or to keep the system partition/setup-alpine's layout (see next section). We only need one of the two. Not both.
Clean up the boot folder in the first partition to drop unused files:
rm -f /media/mmcblk0p1/boot/* cd /mnt # We are in the second partition rm boot/boot # Drop the unused symbolic link
Move the image and initramfs for Alpine Linux into the right place:
mv boot/* /media/mmcblk0p1/boot/ rm -Rf boot mkdir media/mmcblk0p1 # It's the mount point for the first partition on the next reboot
Don't worry about the error when you execute the following:
ln -s media/mmcblk0p1/boot boot
Update boot partition (keep system partition/setup-alpine layout)
It turns out that the system partition created by setup-alpine has a working boot layout. To keep this, perform the following steps instead of the steps in the previous chapter.
Clean up the boot / first partition to drop unused files:
rm -Rf /media/mmcblk0p1/* cd /mnt # We are in the second partition rm boot/boot # Drop the unused symbolink link
Move the boot folder created by setup-alpine into the right place:
cd /media/mmcblk0p1 mkdir boot
cd /mnt mv boot/* /media/mmcblk0p1/ rm -Rf boot mkdir media/mmcblk0p1 # It's the mount point for the first partition on the next reboot
Don't worry about the error when you execute the following:
ln -s media/mmcblk0p1 boot
End of update boot partition - continue here in both cases
Update /etc/fstab
:
echo "/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0" >> etc/fstab sed -i '/cdrom/d' etc/fstab # Of course, you don't have any cdrom or floppy on the Raspberry Pi sed -i '/floppy/d' etc/fstab cd /media/mmcblk0p1
If you want to activate the edge repository:
sed -i '/edge/s/^#//' etc/apk/repositories # But enable the repository for community if you want vim, mc, php, apache, nginx, etc.
For the next boot, indicate that the root filesystem is on the second partition. If the cmdline.txt file
contains a line that starts with /root
, then use sed:
sed -i 's/$/ root=\/dev\/mmcblk0p2 /' /media/mmcblk0p1/cmdline.txt reboot
That works on Raspberry Pi 3B and 1B, but if you have the 1B version, you'll need to be very, very patient (several tens of minutes).
If a hard disk is connected via usb, you can replace the /dev/mmcblk0p2
above with /dev/sda1
, for example.
If you don't want to use sed, you can use the nano editor instead, after executing the following command:
apk add nano
Post-installation
See the Raspberry_Pi#Post_Installation for common post-installation steps.
Additionally, the following may be of value on a sys mode installation:
If you want a cool editor (vim), a file manager (mc), and to determine which tasks are running and which services are starting on boot (htop), install the packages with this command:
apk add vim mc htop
The RPI 3B has wifi on board. To start the service for the encrypted key using wpa2 protocol:
apk add wpa_supplicant
rc-update add wpa_supplicant boot
service wpa_supplicant start
setup-interfaces
Replace the IP address by dhcp for all the interfaces if necessary; select the SSID network for wifi, add the password.
ip addr # to find the IP address for all interfaces
If you want to connect to your RPI via ssh
, an additional user (foo) and the sudo package are required because it's forbidden to connect as root:
apk add sudo adduser foo adduser foo wheel visudo
Uncomment line #82 with wheel ALL=(ALL) ALL
. If vim is installed, save the changes by typing Esc :x
Troubleshooting
Following the preparation instructions for setting up the boot partition as outlined, using the armv7 image (3.10.3), my rpi2 would not even boot, and I was trapped at the dreaded rainbow screen, with the green led blinking a few times in a row, repeatedly.
The rpi2 I had appears to require fat32 for the boot partition, NOT fat16 as suggested in the instructions. Use linux fdisk to set the boot partition type as "c" (for fat32/lba) and set the lba and boot flags for the partition as suggested. Create the boot partition filesystem as fat32 with:
mkdosfs -F 32 /dev/sdX1
Mount and unpacke the tarball to that, and everything should work as documented after the prep instructions.
After booting, you may find less system memory available than you expect. Currently the Pi requires a minimum of 32 megs of memory for the gpu, to boot unless you have the cut down boot loader installed, in which case you can use 16. However, you may find more gpu memory is still being used, even if you configure it for less, if you enable audio or camera support. To find out how your system is actually split:
apk add raspberrypi
/opt/vc/bin/vcgencmd get_mem gpu
/opt/vc/bin/vcgencmd get_mem arm