User:Txnintn

From Alpine Linux

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