User:Txnintn: Difference between revisions

From Alpine Linux
mNo edit summary
mNo edit summary
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
Title:  Alpine Linux install: LVM over Raid1 with a Micro SD spare.
Title:  Alpine Linux install: LVM over Raid1 with a Micro SD spare.<br>
 
<br>
Alpine Linux setup-alpine scripts when executed with two disks and the install medium, if both disks are selected, i.e., sda and sdb, the script will automatically configure a RAID1 installation. /https://wiki.alpinelinux.org/wiki/Setting_up_the_build_environment_on_HDD#Basic_setup
Discussion:<br>
 
<br>
Additionally, LVM with a 'sys' install can be selected during the setup-alpine script.
Alpine Linux setup-alpine scripts when executed with two disks and the install medium, if both disks are selected, i.e., sda and sdb, the script will automatically configure a RAID1 installation.<br>
 
https://wiki.alpinelinux.org/wiki/Setting_up_the_build_environment_on_HDD#Basic_setup<br>
The Raspberry Pi requires fat 16 / 32 boot partition with boot and LBA flags enabled.  The Raspberry PI will boot from either a USB or a Micro SD port. By having a Micro SD RAID1 spare, if the primary USB drive fails the Micro SD should be able to boot the system.  LVM requires the Micro SD spare partition to be the same size as USB RAID1 partitions.  A larger capacity Micro SD drive 2nd partition can easily resized to match the USB partition.  During the install the setup-alpine script will maximize the size of 2nd partition on RAID1 drives.
<br>
 
Additionally, LVM with a 'sys' install can be selected during the setup-alpine script.<br>
Tech Tip, not all Micro SD and USB drives are the same size.
<br>
 
The Raspberry Pi requires fat 16 / 32 boot partition with boot and LBA flags enabled.  The Raspberry PI will boot from the USB or the Micro SD port. By having a Micro SD RAID1 spare, if the primary USB drive fails, the Micro SD should be able to boot the system.<br>
16GB
<br>
 
NOTE: A mirrored RAID array (level 1 or 5) protects you against hardware failure. It doesn't protect against rm -rf /, software errors, exploits, earthquakes, fire. Don't rely on RAID as a backup strategy.<br>
SanDisk Industrial Micro SD 14.84GB
https://wiki.alpinelinux.org/wiki/Setting_up_a_software_RAID_array#Advice<br>
 
<br>
SanDisk Ultra Ultra Fit USB 3.1 14.34GB
<br>
 
LVM requires the Micro SD spare partition to be the same size as USB RAID1 partitions.  A larger capacity Micro SD drive 2nd partition can easily resized to match the USB partition.  During the install the setup-alpine script will maximize the size of 2nd partition on RAID1 drives<br><br>
SanDisk Ultra USB 3.0     14.91GB
<br>
 
Tech Tip, not all Micro SD and USB drives are the same size.<br>
SanDisk Cruzer Glide USB 2.0 14.91GB
<br>
 
{| class="wikitable"
 
|+ 16GB Drives
32GB
|-
 
! MFG / Model !! Size
Samsung SD Pro Endurance Micro SD 29.81GB
|-
 
| SanDisk Industrial Micro SD || 14.84GB
SanDisk Ultra SD 29.72GB
|-
 
| SanDisk Ultra Ultra Fit USB 3.1 || 14.34GB
SanDisk Ultra Fit USB 3.1 Gen1 28.67GB
|-
 
| SanDisk Ultra USB 3.0 || 14.91GB
Silicon Power 5 USB 3.2 28.85GB
|-
 
| SanDisk Cruzer Glide USB 2.0 || 14.91GB
SanDisk Ultra 3.0 OTG 28.85GB
|}
 
{| class="wikitable"
 
|+32GB Drives
64GB
! MFG / Model !! Size
 
|-
Samsung EVO Select Micro SD 59.69GB
| Samsung SD Pro Endurance Micro SD || 29.81GB
 
|-
Samsung Fit USB 3.1 59.75GB
| SanDisk Ultra SD || 29.72GB
 
|-
 
| SanDisk Ultra Fit USB 3.1 Gen1 || 28.67GB
Requirements:
|-
Raspberry PI 4
| Silicon Power 5 USB 3.2 || 28.85GB
Two Identical USB Drives - fit style drives recommended based on physical clearance issues.
|-
One Micro SD Drive with the same or larger capacity then the USB drives
| SanDisk Ultra 3.0 OTG || 28.85GB
One USB drive for the installation files.
|}
 
{| class="wikitable"
Preparation
|+ 64GB Drive
Created the following on the USB RAID disks:
|-
sdx1 a 300MB Fat32 Oc Partition, with boot and lba flags as required by Raspberry PI.
! MFG / Model !! Size
sdx2 using the rest of the disk with a fd linux raid partition, formatted ext4
|-
 
| Samsung EVO Select Micro SD || 59.69GB
mmcblkx, sdx1 a 300MB Fat32 Oc Partition, with boot and lba flags as required by Raspberry PI.
|-
sdx2 sized to match USB RAID partition, Linux 83 and formatted Ext4.  Do not use Linux Raid.
| Samsung Fit USB 3.1 || 59.75GB
 
|} <br>
The USB installation drive single partition fat 32 0c with boot and LBA flags.
Extract the contents of alpine-rpi-3.x.x-aarch.tar.gz to sdc1 (spare USB) partition.
 
The Raspberry Pi eprom must be set to boot USB port first and SD port second.
 
Installation
 
Insert the "sda" USB disk into the bottom USB 3.0 port and the "sdb" USB drive into the upper USB 3.0 port.  Power up the system, after the system has failed to boot to the installed USB drives, the screen will change from white and red to black and white text, insert the installation USB (sdc) to start the install process. This will set the drive assignments properly.
 
 
After logging in as root.
To start the install,
TYPE:  setup-alpine and PRESS:  enter.
 
 
At, Select keyboard layout: [none], prompt.
TYPE:  us and PRESS:  enter.
At, Select variant (or 'abort'):, prompt.
TYPE:  us and PRESS:  enter.
 
 
At, Enter system hostname (fully qualified form, e.g. 'foo.example.org') [localhost] prompt.
TYPE:  the localhost name, for example, rpi44gb and PRESS: enter.
 
 
At, Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done' [eth0], prompt.
PRESS: enter, to use the default, ethernet0 connection.
 
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp], prompt.
PRESS:  enter to use the default, dhcp.
 
At the second,  Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done' [wlan0], prompt.
TYPE: done and PRESS: enter.
 
Then at, Do you want to do and manual network configuration? (y/n) [n], prompt.
PRESS enter for the default, [n], for no.
 
 
At, Change password for root, prompt.
TYPE: the root password, and PRESS:  enter.
At, Retype password, prompt.
TYPE: the root password and PRESS:  enter.
 
 
At, Which timezone are you in? ('?' for a list) [UTC]. prompt.
TYPE:  America, with a capital A, and press enter.
 
At, What sub-timezone of 'America' are you in? ('?' for list), prompt.
TYPE:  Chicago, with a capital C, and press enter.
 
At, HTTP/FTP proxy URL? (e.g. /http://proxy:8000', or 'none') [none], prompt.
PRESS:  enter for the default, none.
 
 
At, Which NTP Client to run? ('busybox', 'openntpd', 'chrony' or 'none') [chrony], prompt.
PRESS:  enter for the default, chrony.
 
 
When the list of mirrors stop and at --More--, prompt
PRESS: the letter "r".
 
r) Add random from the above list
f) Detect and add the fastest mirror from above list
e) Edit /etc/apk/repositories with text editor
 
At, Enter mirror number (1-72) or URL to add (or r/f/e/done) [1], prompt.
PRESS:  enter for the default number 1.
 
 
At, Setup a user? (enter a lower-case loginname, or 'no') [no], prompt.
PRESS: enter for the default no.
 


Requirements:<br>
<br>
Raspberry PI 4<br>
<br>
Two Identical USB Drives - fit style drives recommended based on physical clearance issues.<br>
<br>
One Micro SD Drive with the same or larger capacity then the USB drives<br>
<br>
One USB drive for the installation files.<br>
<br>
Preparation:<br>
<br>
Created the following for the USB RAID disks:<br>
sdx1 a 300MB Fat32 Oc Partition, with boot and lba flags as required by Raspberry PI.<br>
sdx2 using the rest of the disk with a fd linux raid partition, formatted ext4<br>
<br>
mmcblkx, sdx1 a 300MB Fat32 Oc Partition, with boot and lba flags as required by Raspberry PI.<br>
sdx2 sized to match USB RAID partition, Linux 83 and formatted Ext4.  Do not use Linux Raid.<br>
<br>
The USB installation drive single partition fat 32 0c with boot and LBA flags.<br>
Extract the contents of alpine-rpi-3.x.x-aarch.tar.gz to sdc1 (spare USB) partition.<br>
<br>
The Raspberry Pi eprom must be set to boot USB port first and SD port second.<br>
<br>
Installation:<br>
<br>
Insert the "sda" USB disk into the bottom USB 3.0 port and the "sdb" USB drive into the upper USB 3.0 port.  Power up the system, after the system has failed to boot to the installed USB drives, the screen will change from white and red to black and white text, insert the installation USB (sdc) to start the install process. This will set the drive assignments properly.<br>
<br>
<br>
After logging in as root.<br>
To start the install, <br>
TYPE:  setup-alpine and PRESS:  enter.<br>
<br>
<br>
At, Select keyboard layout: [none], prompt.<br>
TYPE:  us and PRESS:  enter.<br>
At, Select variant (or 'abort'):, prompt. <br>
TYPE:  us and PRESS:  enter.<br>
<br>
<br>
At, Enter system hostname (fully qualified form, e.g. 'foo.example.org') [localhost] prompt.<br>
TYPE:  the localhost name, for example, rpi44gb and PRESS: enter.<br>
<br>
<br>
At, Enter '?' for help on bridges, bonding and vlans.<br>
Which one do you want to initialize? (or '?' or 'done' [eth0], prompt. <br>
PRESS: enter, to use the default, ethernet0 connection.<br>
<br>
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp], prompt. <br>
PRESS:  enter to use the default, dhcp.<br>
<br>
At the second,  Enter '?' for help on bridges, bonding and vlans.<br>
Which one do you want to initialize? (or '?' or 'done' [wlan0], prompt.<br>
TYPE: done and PRESS: enter.<br>
<br>
Then at, Do you want to do and manual network configuration? (y/n) [n], prompt.<br>
PRESS enter for the default, [n], for no.<br>
<br>
<br>
At, Change password for root, prompt.<br>
TYPE: the root password, and PRESS:  enter.<br>
At, Retype password, prompt.<br>
TYPE: the root password and PRESS:  enter.<br>
<br>
<br>
At, Which timezone are you in? ('?' for a list) [UTC]. prompt.<br>
TYPE:  America, with a capital A, and press enter.<br>
<br>
At, What sub-timezone of 'America' are you in? ('?' for list), prompt.<br>
TYPE:  Chicago, with a capital C, and press enter.<br>
<br>
At, HTTP/FTP proxy URL? (e.g. /http://proxy:8000', or 'none') [none], prompt.<br>
PRESS:  enter for the default, none.<br>
<br>
<br>
At, Which NTP Client to run? ('busybox', 'openntpd', 'chrony' or 'none') [chrony], prompt.<br>
PRESS:  enter for the default, chrony.<br>
<br>
<br>
When the list of mirrors stop and at --More--, prompt <br>
PRESS: the letter "r". <br>
<br>
r) Add random from the above list <br>
f) Detect and add the fastest mirror from above list <br>
e) Edit /etc/apk/repositories with text editor <br>
<br>
At, Enter mirror number (1-72) or URL to add (or r/f/e/done) [1], prompt. <br>
PRESS:  enter for the default number 1. <br>
<br>
<br>
At, Setup a user? (enter a lower-case loginname, or 'no') [no], prompt. <br>
PRESS: enter for the default no. <br>
<br>
<br>
At, which ssh server? ('openssh', 'dropbear' or 'none'), prompt.
At, which ssh server? ('openssh', 'dropbear' or 'none'), prompt.
TYPE: none and PRESS:  enter to continue.
TYPE: none and PRESS:  enter to continue.
 
<br>
At, Available disks are:
At, Available disks are: <br>
         sda (15.4 GB USB SanDisk 3.2Gen1)                 
         sda (15.4 GB USB SanDisk 3.2Gen1) <br>                
         sdb (15.4 GB USB SanDisk 3.2Gen1)
         sdb (15.4 GB USB SanDisk 3.2Gen1) <br>
       
<br>     
At Which disk(s) would you like to use? (or '?' for help or 'none') [none], prompt.
At Which disk(s) would you like to use? (or '?' for help or 'none') [none], prompt. <br>
TYPE: sda sdb and PRESS:  enter to continue.
TYPE: sda sdb and PRESS:  enter to continue. <br>
 
<br>
The following disks are selected:
The following disks are selected: <br>
         sda (15.4 GB USB SanDisk 3.2Gen1)                 
         sda (15.4 GB USB SanDisk 3.2Gen1) <br>                
         sdb (15.4 GB USB SanDisk 3.2Gen1)
         sdb (15.4 GB USB SanDisk 3.2Gen1) <br>
How would you like to use it? ('sys', 'data', 'crypt', 'lvm' or '?' for help) [?], prompt.
<br>
TYPE:  lvm and PRESS: enter to continue.
How would you like to use it? ('sys', 'data', 'crypt', 'lvm' or '?' for help) [?], prompt. <br>
 
TYPE:  lvm and PRESS: enter to continue. <br>
 
<br>
The following disks are selected (with LVM):
<br>
         sda (15.4 GB USB SanDisk 3.2Gen1)              
The following disks are selected (with LVM): <br>
         sdb (15.4 GB USB SanDisk 3.2Gen1)
         sda (15.4 GB USB SanDisk 3.2Gen1) <br>             
How would you like to use it? ('sys', 'data', or '?' for help) [?], prompt.
         sdb (15.4 GB USB SanDisk 3.2Gen1) <br>
TYPE:  sys for system disk and PRESS enter to continue.
<br>
 
How would you like to use it? ('sys', 'data', or '?' for help) [?], prompt. <br>
 
TYPE:  sys for system disk and PRESS: enter to continue. <br>
At, WARNING: Erase the above disk(s) and continue? (y/n) [n], prompt.
<br>
         sda (15.4 GB USB SanDisk 3.2Gen1)              
<br>
         sdb (15.4 GB USB SanDisk 3.2Gen1)
At, WARNING: Erase the above disk(s) and continue? (y/n) [n], prompt. <br>
TYPE: y, for yes AMD PRESS: enter to continue.
         sda (15.4 GB USB SanDisk 3.2Gen1) <br>             
 
         sdb (15.4 GB USB SanDisk 3.2Gen1) <br>
 
<br>
Partition #1 contains a vfat signature.
TYPE: y, for yes and PRESS: enter to continue. <br>
Partition #2 contains a ext4 signature.
<br>
Partition #1 contains a vfat signature.
<br>
Partition #2 contains a ext4 signature.
Partition #1 contains a vfat signature.<br>
Creating file systems
Partition #2 contains a ext4 signature.<br>
mkfs.fat 4.2 ((2021-01-31)
Partition #1 contains a vfat signature.<br>
         Physical volume "/dev/md1" successfully created.
Partition #2 contains a ext4 signature.<br>
         Logical volume "lv_root" created.
Creating file systems<br>
* service lvm added to runlevel boot
mkfs.fat 4.2 ((2021-01-31)<br>
Installing system on /dev/vg0/lv_root"
         Physical volume "/dev/md1" successfully created. <br>
100% ######################################
         Logical volume "lv_root" created. <br>
=> initframfs: creating /boot/initramfs-rpi4
* service lvm added to runlevel boot <br>
 
Installing system on /dev/vg0/lv_root" <br>
 
100% ###################################### <br>
Installation is complete.  Please reboot.  DO NOT REBOOT!!!
=> initframfs: creating /boot/initramfs-rpi4 <br>
 
<br>
 
<br>
Alpine installed the boot drive as a FD linux raid autodetect, IT WILL NOT BOOT on a Raspberry Pi.  
Installation is complete.  Please reboot.  DO NOT REBOOT!!! <br>
The Raspberry Pi can only boot from fat16 or fat32 partition with boot and lba flags enabled.  
<br>
 
<br>
TYPE:  watch  cat /proc/mdstat
Alpine installed the boot drive as a FD linux raid autodetect, IT WILL NOT BOOT on a Raspberry Pi. The Raspberry Pi can only boot from fat16 or fat32 partition with boot and lba flags enabled. <br>
 
<br>
 
TYPE:  watch  cat /proc/mdstat<br>
<br>
Personalities : [raid1]
Personalities : [raid1]
md1 : active raid1 sdb2[1] sda2[0]
md1 : active raid1 sdb2[1] sda2[0]
Line 187: Line 208:
           {>....................] resyc - 2.7% (397521/14723072) finish=22.1min speed=8768K/sec
           {>....................] resyc - 2.7% (397521/14723072) finish=22.1min speed=8768K/sec
md0 : active raid1 sdb1[1] sda1[0]
md0 : active raid1 sdb1[1] sda1[0]
           307136 blocks [2/2] [UU]  
           307136 blocks [2/2] [UU]
 
<br>
The Raid MD1 is still resycing. Take a break, the drives should be finished in 20 to 30 minutes.
<br>
 
The Raid MD1 is still resycing. Take a break, the drives should be finished in 20 to 30 minutes.<br>
PRESS: ctrl + c to exit watch cat /proc/mtstat
<br>
 
PRESS: ctrl + c to exit watch cat /proc/mdstat<br>
 
<br>
 
<br>
Backup the boot raid partition first
Backup the boot raid partition first<br>
Insert mmcblk0
Insert mmcblk0<br>
TYPE:  dd if=/dev/sda1 of=/dev/mmcblk0p1 bs=512
TYPE:  dd if=/dev/sda1 of=/dev/mmcblk0p1 bs=512<br>
 
<br>
 
<br>
Reboot
Reboot<br>
 
<br>
 
<br>
Unmount the RAID 1 filesystem
Unmount the RAID 1 filesystem<br>
TYPE:  umount /dev/md0
TYPE:  umount /dev/md0<br>
 
<br>
 
<br>
Stop the madam raid device
Stop the madam raid device <br>
TYPE:  mdadm --stop /dev/md0
TYPE:  mdadm --stop /dev/md0 <br>
 
<br>
 
<br>
Remove the Superblocks
Remove the Superblocks <br>
TYPE:  mdadm --zero-superblock /dev/sda1 /dev/sdb1 /dev/mmcblk0p1 (due to dd backup copying)
TYPE:  mdadm --zero-superblock /dev/sda1 /dev/sdb1 /dev/mmcblk0p1 (due to dd backup copying) <br>
 
<br>
 
<br>
verify md0 has been removed
verify md0 has been removed <br>
TYPE:  lsblk and or cat /proc/mdstat
TYPE:  lsblk and or cat /proc/mdstat <br>
 
<br>
 
<br>
TYPE:  apk add nano or use vi to remove RAID /dev/md0 entries by editing /etc/fstab and /etc/mdadm.conf  
TYPE:  apk add nano or use vi to remove RAID /dev/md0 entries by editing /etc/fstab and /etc/mdadm.conf <br>
 
<br>
 
<br>
reboot
reboot <br>
 
<br>
apk add sfdisk
Verify partition table sizes are the same on the Micro SD card and USB Drives. <br>
 
<br>
*** Warning***  
TYPE:  fdisk -l (some entries removed for clairification) <br>
Before executing the following commands mmcblk0, sda, and sdb must be the exact same size partitons.  
<br>
**************
Disk /dev/mmcblk0: 15 GB, 15931539456 bytes, 31116288 sectors <-- <br>
   
15193 cylinders, 64 heads, 32 sectors/track <br>
sfdisk -d /dev/mmcblk0 |  sfdisk –force /dev/sda
Units: sectors of 1 * 512 = 512 bytes <br>
sfdisk -d /dev/mmcblk0 |  sfdisk –force /dev/sdb  
<br>
 
Device      Boot StartCHS    EndCHS        StartLBA    EndLBA    Sectors  Size Id Type <br>
Copy mmcblk0p1 boot partition to sda1 and sdb1
/dev/mmcblk0p1 *  1,0,1      300,63,32        2048    616447    614400  300M  c Win95 FAT32 (LBA)    ok <br>
TYPE:  dd if=/dev/mmcblk0p1 of=/dev/sda1 bs=512
/dev/mmcblk0p2    301,0,1    1023,63,32      616448  31116287  30499840 14.5G fd Linux raid autodetect <-- <br>
TYPE:  dd if=/dev/mmcblk0p1 of=/dev/sdb1 bs=512
<br>
 
Disk /dev/sda: 14 GB, 15401484288 bytes, 30081024 sectors <br>
 
14688 cylinders, 64 heads, 32 sectors/track <br>
Add mmcblk0 as a spare drive to RAID /dev/md1  
Units: sectors of 1 * 512 = 512 bytes <br>
TYPE:  madam --add /dev/md1 /dev/mmcblk0p2
<br>
 
Device  Boot StartCHS    EndCHS        StartLBA    EndLBA    Sectors  Size Id Type <br>
 
/dev/sda1 *  1,0,1      300,63,32        2048    616447    614400  300M fd Linux raid autodetect ok <br>
TYPE: mdadm --detail /dev/md1
/dev/sda2    301,0,1    1023,63,32      616448  30081023  29464576 14.0G fd Linux raid autodetect <-- <br>
/dev/md1
<br>
Disk /dev/sdb: 14 GB, 15401484288 bytes, 30081024 sectors <br>
14688 cylinders, 64 heads, 32 sectors/track <br>
Units: sectors of 1 * 512 = 512 bytes <br>
<br>
Device  Boot StartCHS    EndCHS        StartLBA    EndLBA    Sectors  Size Id Type <br>
/dev/sdb1 *  1,0,1      300,63,32        2048    616447    614400  300M fd Linux raid autodetect ok <br>
/dev/sdb2    301,0,1    1023,63,32      616448  30081023  29464576 14.0G fd Linux raid autodetect <-- <br>
<br>
If the Micro SD card is larger then /dev/sda2 and /dev/sdb2.  <br>
Resize the partion before continuing.  <br>
<br>
Disk /dev/mmcblk0: 15 GB, 15931539456 bytes, 31116288 sectors <br>
15193 cylinders, 64 heads, 32 sectors/track <br>
Units: sectors of 1 * 512 = 512 bytes <br>
<br>
Device      Boot StartCHS    EndCHS        StartLBA    EndLBA    Sectors  Size Id Type <br>
/dev/mmcblk0p1 *  1,0,1      300,63,32        2048    616447    614400  300M  c Win95 FAT32 (LBA) <br>
/dev/mmcblk0p2    301,0,1    1023,63,32      616448  30081023  29464576 14.0G fd Linux raid autodetect <br>
<br>
Disk /dev/sda: 14 GB, 15401484288 bytes, 30081024 sectors <br>
14688 cylinders, 64 heads, 32 sectors/track <br>
Units: sectors of 1 * 512 = 512 bytes <br>
<br>
Device  Boot StartCHS    EndCHS        StartLBA    EndLBA    Sectors  Size Id Type <br>
/dev/sda1 *  1,0,1      300,63,32        2048    616447    614400  300M fd Linux raid autodetect <br>
/dev/sda2    301,0,1    1023,63,32      616448  30081023  29464576 14.0G fd Linux raid autodetect <br>
<br>
Disk /dev/sdb: 14 GB, 15401484288 bytes, 30081024 sectors <br>
14688 cylinders, 64 heads, 32 sectors/track<br>
Units: sectors of 1 * 512 = 512 bytes<br>
<br>
Device  Boot StartCHS    EndCHS        StartLBA    EndLBA    Sectors  Size Id Type<br>
/dev/sdb1 *  1,0,1      300,63,32        2048    616447    614400  300M fd Linux raid autodetect<br>
/dev/sdb2    301,0,1    1023,63,32      616448  30081023  29464576 14.0G fd Linux raid autodetect<br>
<br>
Install sfdisk to copy partition table information <br>
TYPE:  apk add sfdisk <br>
<br>
*** Warning*** <br>
Before executing the following commands mmcblk0, sda, and sdb must be the exact same size partitons. <br>
**************<br>
Copy mmcblk0 disk partition table to sda and sdb<br>
<br>
TYPE: sfdisk -d /dev/mmcblk0 |  sfdisk --force /dev/sda<br>
TYPE:  sfdisk -d /dev/mmcblk0 |  sfdisk --force /dev/sdb<br>
<br>
<br>
Copy mmcblk0p1 boot partition to sda1 and sdb1<br>
TYPE:  dd if=/dev/mmcblk0p1 of=/dev/sda1 bs=512<br>
TYPE:  dd if=/dev/mmcblk0p1 of=/dev/sdb1 bs=512<br>
<br>
<br>
Add mmcblk0 as a spare drive to RAID /dev/md1<br>
TYPE:  madam --add /dev/md1 /dev/mmcblk0p2<br>
<br>
<br>
View Raid One information<br>
TYPE: mdadm --detail /dev/md1<br>
<br>
/dev/md1<br>
                         version : 1.2
                         version : 1.2
           Creation Time        : Sat Jun 24 12:50:56 2023
           Creation Time        : Sat Jun 24 12:50:56 2023
Line 252: Line 333:
           Total Devices : 3
           Total Devices : 3
             Persistence : Superblock is persistence
             Persistence : Superblock is persistence
           
         
             Update Time : Sat Jun 24 14:30:11 2023
             Update Time : Sat Jun 24 14:30:11 2023
                       State : clean
                       State : clean
Line 259: Line 340:
         Failed Devices : 0
         Failed Devices : 0
           Spare Devices : 1
           Spare Devices : 1
txnintn
txnintn<br>

Latest revision as of 14:23, 23 September 2023

Title: Alpine Linux install: LVM over Raid1 with a Micro SD spare.

Discussion:

Alpine Linux setup-alpine scripts when executed with two disks and the install medium, if both disks are selected, i.e., sda and sdb, the script will automatically configure a RAID1 installation.
https://wiki.alpinelinux.org/wiki/Setting_up_the_build_environment_on_HDD#Basic_setup

Additionally, LVM with a 'sys' install can be selected during the setup-alpine script.

The Raspberry Pi requires fat 16 / 32 boot partition with boot and LBA flags enabled. The Raspberry PI will boot from the USB or the Micro SD port. By having a Micro SD RAID1 spare, if the primary USB drive fails, the Micro SD should be able to boot the system.

NOTE: A mirrored RAID array (level 1 or 5) protects you against hardware failure. It doesn't protect against rm -rf /, software errors, exploits, earthquakes, fire. Don't rely on RAID as a backup strategy.
https://wiki.alpinelinux.org/wiki/Setting_up_a_software_RAID_array#Advice


LVM requires the Micro SD spare partition to be the same size as USB RAID1 partitions. A larger capacity Micro SD drive 2nd partition can easily resized to match the USB partition. During the install the setup-alpine script will maximize the size of 2nd partition on RAID1 drives


Tech Tip, not all Micro SD and USB drives are the same size.

16GB Drives
MFG / Model Size
SanDisk Industrial Micro SD 14.84GB
SanDisk Ultra Ultra Fit USB 3.1 14.34GB
SanDisk Ultra USB 3.0 14.91GB
SanDisk Cruzer Glide USB 2.0 14.91GB
32GB Drives
MFG / Model Size
Samsung SD Pro Endurance Micro SD 29.81GB
SanDisk Ultra SD 29.72GB
SanDisk Ultra Fit USB 3.1 Gen1 28.67GB
Silicon Power 5 USB 3.2 28.85GB
SanDisk Ultra 3.0 OTG 28.85GB
64GB Drive
MFG / Model Size
Samsung EVO Select Micro SD 59.69GB
Samsung Fit USB 3.1 59.75GB


Requirements:

Raspberry PI 4

Two Identical USB Drives - fit style drives recommended based on physical clearance issues.

One Micro SD Drive with the same or larger capacity then the USB drives

One USB drive for the installation files.

Preparation:

Created the following for the USB RAID disks:
sdx1 a 300MB Fat32 Oc Partition, with boot and lba flags as required by Raspberry PI.
sdx2 using the rest of the disk with a fd linux raid partition, formatted ext4

mmcblkx, sdx1 a 300MB Fat32 Oc Partition, with boot and lba flags as required by Raspberry PI.
sdx2 sized to match USB RAID partition, Linux 83 and formatted Ext4. Do not use Linux Raid.

The USB installation drive single partition fat 32 0c with boot and LBA flags.
Extract the contents of alpine-rpi-3.x.x-aarch.tar.gz to sdc1 (spare USB) partition.

The Raspberry Pi eprom must be set to boot USB port first and SD port second.

Installation:

Insert the "sda" USB disk into the bottom USB 3.0 port and the "sdb" USB drive into the upper USB 3.0 port. Power up the system, after the system has failed to boot to the installed USB drives, the screen will change from white and red to black and white text, insert the installation USB (sdc) to start the install process. This will set the drive assignments properly.


After logging in as root.
To start the install,
TYPE: setup-alpine and PRESS: enter.


At, Select keyboard layout: [none], prompt.
TYPE: us and PRESS: enter.
At, Select variant (or 'abort'):, prompt.
TYPE: us and PRESS: enter.


At, Enter system hostname (fully qualified form, e.g. 'foo.example.org') [localhost] prompt.
TYPE: the localhost name, for example, rpi44gb and PRESS: enter.


At, Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done' [eth0], prompt.
PRESS: enter, to use the default, ethernet0 connection.

Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp], prompt.
PRESS: enter to use the default, dhcp.

At the second, Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done' [wlan0], prompt.
TYPE: done and PRESS: enter.

Then at, Do you want to do and manual network configuration? (y/n) [n], prompt.
PRESS enter for the default, [n], for no.


At, Change password for root, prompt.
TYPE: the root password, and PRESS: enter.
At, Retype password, prompt.
TYPE: the root password and PRESS: enter.


At, Which timezone are you in? ('?' for a list) [UTC]. prompt.
TYPE: America, with a capital A, and press enter.

At, What sub-timezone of 'America' are you in? ('?' for list), prompt.
TYPE: Chicago, with a capital C, and press enter.

At, HTTP/FTP proxy URL? (e.g. /http://proxy:8000', or 'none') [none], prompt.
PRESS: enter for the default, none.


At, Which NTP Client to run? ('busybox', 'openntpd', 'chrony' or 'none') [chrony], prompt.
PRESS: enter for the default, chrony.


When the list of mirrors stop and at --More--, prompt
PRESS: the letter "r".

r) Add random from the above list
f) Detect and add the fastest mirror from above list
e) Edit /etc/apk/repositories with text editor

At, Enter mirror number (1-72) or URL to add (or r/f/e/done) [1], prompt.
PRESS: enter for the default number 1.


At, Setup a user? (enter a lower-case loginname, or 'no') [no], prompt.
PRESS: enter for the default no.


At, which ssh server? ('openssh', 'dropbear' or 'none'), prompt. TYPE: none and PRESS: enter to continue.
At, Available disks are:

       sda	(15.4 GB USB	SanDisk 3.2Gen1) 
sdb (15.4 GB USB SanDisk 3.2Gen1)


At Which disk(s) would you like to use? (or '?' for help or 'none') [none], prompt.
TYPE: sda sdb and PRESS: enter to continue.

The following disks are selected:

       sda	(15.4 GB USB	SanDisk 3.2Gen1) 
sdb (15.4 GB USB SanDisk 3.2Gen1)


How would you like to use it? ('sys', 'data', 'crypt', 'lvm' or '?' for help) [?], prompt.
TYPE: lvm and PRESS: enter to continue.


The following disks are selected (with LVM):

       sda	(15.4 GB USB	SanDisk 3.2Gen1) 
sdb (15.4 GB USB SanDisk 3.2Gen1)


How would you like to use it? ('sys', 'data', or '?' for help) [?], prompt.
TYPE: sys for system disk and PRESS: enter to continue.


At, WARNING: Erase the above disk(s) and continue? (y/n) [n], prompt.

       sda (15.4 GB USB	SanDisk 3.2Gen1) 
sdb (15.4 GB USB SanDisk 3.2Gen1)


TYPE: y, for yes and PRESS: enter to continue.


Partition #1 contains a vfat signature.
Partition #2 contains a ext4 signature.
Partition #1 contains a vfat signature.
Partition #2 contains a ext4 signature.
Creating file systems
mkfs.fat 4.2 ((2021-01-31)

       Physical volume "/dev/md1" successfully created. 
Logical volume "lv_root" created.
  • service lvm added to runlevel boot

Installing system on /dev/vg0/lv_root"
100% ######################################
=> initframfs: creating /boot/initramfs-rpi4


Installation is complete. Please reboot. DO NOT REBOOT!!!


Alpine installed the boot drive as a FD linux raid autodetect, IT WILL NOT BOOT on a Raspberry Pi. The Raspberry Pi can only boot from fat16 or fat32 partition with boot and lba flags enabled.

TYPE: watch cat /proc/mdstat

Personalities : [raid1] md1 : active raid1 sdb2[1] sda2[0]

         14723072 blocks super 1.2 [2/2] [UU]
         {>....................] resyc - 2.7% (397521/14723072) finish=22.1min speed=8768K/sec

md0 : active raid1 sdb1[1] sda1[0]

         307136 blocks [2/2] [UU]



The Raid MD1 is still resycing. Take a break, the drives should be finished in 20 to 30 minutes.

PRESS: ctrl + c to exit watch cat /proc/mdstat


Backup the boot raid partition first
Insert mmcblk0
TYPE: dd if=/dev/sda1 of=/dev/mmcblk0p1 bs=512


Reboot


Unmount the RAID 1 filesystem
TYPE: umount /dev/md0


Stop the madam raid device
TYPE: mdadm --stop /dev/md0


Remove the Superblocks
TYPE: mdadm --zero-superblock /dev/sda1 /dev/sdb1 /dev/mmcblk0p1 (due to dd backup copying)


verify md0 has been removed
TYPE: lsblk and or cat /proc/mdstat


TYPE: apk add nano or use vi to remove RAID /dev/md0 entries by editing /etc/fstab and /etc/mdadm.conf


reboot

Verify partition table sizes are the same on the Micro SD card and USB Drives.

TYPE: fdisk -l (some entries removed for clairification)

Disk /dev/mmcblk0: 15 GB, 15931539456 bytes, 31116288 sectors <--
15193 cylinders, 64 heads, 32 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk0p1 * 1,0,1 300,63,32 2048 616447 614400 300M c Win95 FAT32 (LBA) ok
/dev/mmcblk0p2 301,0,1 1023,63,32 616448 31116287 30499840 14.5G fd Linux raid autodetect <--

Disk /dev/sda: 14 GB, 15401484288 bytes, 30081024 sectors
14688 cylinders, 64 heads, 32 sectors/track
Units: sectors of 1 * 512 = 512 bytes


Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 * 1,0,1 300,63,32 2048 616447 614400 300M fd Linux raid autodetect ok
/dev/sda2 301,0,1 1023,63,32 616448 30081023 29464576 14.0G fd Linux raid autodetect <--

Disk /dev/sdb: 14 GB, 15401484288 bytes, 30081024 sectors
14688 cylinders, 64 heads, 32 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sdb1 * 1,0,1 300,63,32 2048 616447 614400 300M fd Linux raid autodetect ok
/dev/sdb2 301,0,1 1023,63,32 616448 30081023 29464576 14.0G fd Linux raid autodetect <--

If the Micro SD card is larger then /dev/sda2 and /dev/sdb2.
Resize the partion before continuing.

Disk /dev/mmcblk0: 15 GB, 15931539456 bytes, 31116288 sectors
15193 cylinders, 64 heads, 32 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/mmcblk0p1 * 1,0,1 300,63,32 2048 616447 614400 300M c Win95 FAT32 (LBA)
/dev/mmcblk0p2 301,0,1 1023,63,32 616448 30081023 29464576 14.0G fd Linux raid autodetect

Disk /dev/sda: 14 GB, 15401484288 bytes, 30081024 sectors
14688 cylinders, 64 heads, 32 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 * 1,0,1 300,63,32 2048 616447 614400 300M fd Linux raid autodetect
/dev/sda2 301,0,1 1023,63,32 616448 30081023 29464576 14.0G fd Linux raid autodetect

Disk /dev/sdb: 14 GB, 15401484288 bytes, 30081024 sectors
14688 cylinders, 64 heads, 32 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sdb1 * 1,0,1 300,63,32 2048 616447 614400 300M fd Linux raid autodetect
/dev/sdb2 301,0,1 1023,63,32 616448 30081023 29464576 14.0G fd Linux raid autodetect

Install sfdisk to copy partition table information
TYPE: apk add sfdisk

      • Warning***

Before executing the following commands mmcblk0, sda, and sdb must be the exact same size partitons.


Copy mmcblk0 disk partition table to sda and sdb

TYPE: sfdisk -d /dev/mmcblk0 | sfdisk --force /dev/sda
TYPE: sfdisk -d /dev/mmcblk0 | sfdisk --force /dev/sdb


Copy mmcblk0p1 boot partition to sda1 and sdb1
TYPE: dd if=/dev/mmcblk0p1 of=/dev/sda1 bs=512
TYPE: dd if=/dev/mmcblk0p1 of=/dev/sdb1 bs=512


Add mmcblk0 as a spare drive to RAID /dev/md1
TYPE: madam --add /dev/md1 /dev/mmcblk0p2


View Raid One information
TYPE: mdadm --detail /dev/md1

/dev/md1

                       version : 1.2
         Creation Time        : Sat Jun 24 12:50:56 2023
            Raid Level : raid 1
            Array Size : 14723072 (14.04 GiB 15.08 GB)
         Used Dev Size : 14723072 (14.04 GiB 15.08 GB)
          Raid Devices : 2
         Total Devices : 3
           Persistence : Superblock is persistence
          
           Update Time : Sat Jun 24 14:30:11 2023
                     State : clean
        Active Devices : 2
       Working Devices : 3
        Failed Devices : 0
         Spare Devices : 1

txnintn