You are not logged in.

#51 2012-04-20 00:01:40

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved]The linux kernel with build in bootloader?

so after a lot of time wasted trying to get this work on another machine of mine, I came to the conclusion that you don't actually need this patch... big_smile
On my Intel board I just had to create "/boot/efi/boot/bootx64.efi" and I could automatically boot from the SATA drive. On my ASUS board however, this works only for external devices (I guess bootx64.efi is actually only meant for external devices but my Intel board does it for internal devices anyway!?). So it turned out I had to write the boot entry manually into the UEFI firmware with efibootmgr (available in [extra]). Going through the man page I noticed this option:

-@ | --append-binary-args
              append extra variable args from file (use - to read from stdin).
              Data  in  file is appended as command line arguments to the boot
              loader command, with no modification to the  data,  so  you  can
              pass any binary or text data necessary.

so wait a minute? I can write the kernel parameters directly into the UEFI firmware? Wish I would have known this sooner... -.- Well, this stuff happens when you try to boot your kernel with UEFI without having a good understanding of how UEFI works. big_smile
At this point I finally realized how you are actually supposed to set this up (at least I hope so):

ls -l /boot/efi/arch/
total 15429
-rwxr-xr-x 1 root root 8383484 Apr 20 01:14 initramfs-linux-fallback.img
-rwxr-xr-x 1 root root 4091692 Apr 20 01:14 initramfs-linux.img
-rwxr-xr-x 1 root root 3322896 Apr 20 01:28 vmlinuz-linux.efi

So I first tried:

echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

Didn't work, the kernel crashed, probably because it didn't get the initrd parameter. Then I remember that there was something about character conversion in the archiso commit.
So I tried:

echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

Works!
You can now also easily create another entry for the fallback image:

echo "initrd=\efi\arch\initramfs-linux-fallback.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux (Fallback)" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

The stupid thing about this is that you have to boot via UEFI to be able to modify the UEFI bootloader with efibootmgr. I simply booted with an UEFI based USB stick to do this.

Offline

#52 2012-04-20 00:10:02

dhave
Arch Linux f@h Team Member
From: Outside the matrix.
Registered: 2005-05-15
Posts: 1,110

Re: [Solved]The linux kernel with build in bootloader?

@65kid,

This info should probably go at the top of its own thread. Thanks *very* much for working it out, and thanks doubly for documenting it for the rest of us.

I was deep into compiling a custom kernel with two manually patched files. Now it looks like there's no need.


Donate to Arch!

Tired? There's a nap for that. --anonymous

Offline

#53 2012-04-20 00:13:04

dhave
Arch Linux f@h Team Member
From: Outside the matrix.
Registered: 2005-05-15
Posts: 1,110

Re: [Solved]The linux kernel with build in bootloader?

65kid wrote:
echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

Is that a trailing hyphen after "--append-binary-args"?


Donate to Arch!

Tired? There's a nap for that. --anonymous

Offline

#54 2012-04-20 09:56:31

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved]The linux kernel with build in bootloader?

dhave wrote:
65kid wrote:
echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

Is that a trailing hyphen after "--append-binary-args"?

Just a normal dash - . This tells efibootmgr to read the boot parameters from stdin.

Offline

#55 2012-04-20 16:32:55

radiomist
Member
From: superposicion
Registered: 2009-11-27
Posts: 62

Re: [Solved]The linux kernel with build in bootloader?

65kid wrote:

so after a lot of time wasted trying to get this work on another machine of mine, I came to the conclusion that you don't actually need this patch... big_smile
On my Intel board I just had to create "/boot/efi/boot/bootx64.efi" and I could automatically boot from the SATA drive. On my ASUS board however, this works only for external devices (I guess bootx64.efi is actually only meant for external devices but my Intel board does it for internal devices anyway!?). So it turned out I had to write the boot entry manually into the UEFI firmware with efibootmgr (available in [extra]). Going through the man page I noticed this option:

-@ | --append-binary-args
              append extra variable args from file (use - to read from stdin).
              Data  in  file is appended as command line arguments to the boot
              loader command, with no modification to the  data,  so  you  can
              pass any binary or text data necessary.

so wait a minute? I can write the kernel parameters directly into the UEFI firmware? Wish I would have known this sooner... -.- Well, this stuff happens when you try to boot your kernel with UEFI without having a good understanding of how UEFI works. big_smile
At this point I finally realized how you are actually supposed to set this up (at least I hope so):

ls -l /boot/efi/arch/
total 15429
-rwxr-xr-x 1 root root 8383484 Apr 20 01:14 initramfs-linux-fallback.img
-rwxr-xr-x 1 root root 4091692 Apr 20 01:14 initramfs-linux.img
-rwxr-xr-x 1 root root 3322896 Apr 20 01:28 vmlinuz-linux.efi

So I first tried:

echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

Didn't work, the kernel crashed, probably because it didn't get the initrd parameter. Then I remember that there was something about character conversion in the archiso commit.
So I tried:

echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

Works!
You can now also easily create another entry for the fallback image:

echo "initrd=\efi\arch\initramfs-linux-fallback.img root=/dev/mapper/crypt cryptdevice=/dev/sda3:crypt ro quiet" | iconv -f ascii -t ucs2 | efibootmgr --create --gpt --disk /dev/sda --part 1  --label "Arch Linux (Fallback)" --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -

The stupid thing about this is that you have to boot via UEFI to be able to modify the UEFI bootloader with efibootmgr. I simply booted with an UEFI based USB stick to do this.



Works Great on a Macbook Pro 8.1!!

i copy the kernel to /EFI_PART/Efi/boot/bootx64.efi
then run efibootmgr

but is not perfect, When i boot to OSX, OSX change the boot order :S. So Archlinux is set to second entry, How can i prevent this?



* Added to Archwiki (macbook pro 8.1) https://wiki.archlinux.org/index.php/Ma … Efistub.29

Last edited by radiomist (2012-04-20 17:02:00)

Offline

#56 2012-04-20 17:05:18

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved]The linux kernel with build in bootloader?

radiomist wrote:

When i boot to OSX, OSX change the boot order :S. So Archlinux is set to second entry, How can i prevent this?

I have no idea if you can prevent OS X from doing this. Do you have efibootmgr available in OSX? maybe as a workaround you could set the boot order back in OSX with efibootmgr -o or set the BootNext parameter with efibootmgr -n (see efibootmgr man page). If this works you could then put this in the OSX equivalent to /etc/rc.local.shutdown (whatever this is, I don't know that much about OS X).

Offline

#57 2012-04-20 18:27:07

the.ridikulus.rat
Member
From: Indiana, USA
Registered: 2011-10-04
Posts: 765

Re: [Solved]The linux kernel with build in bootloader?

65kid wrote:
radiomist wrote:

When i boot to OSX, OSX change the boot order :S. So Archlinux is set to second entry, How can i prevent this?

I have no idea if you can prevent OS X from doing this. Do you have efibootmgr available in OSX? maybe as a workaround you could set the boot order back in OSX with efibootmgr -o or set the BootNext parameter with efibootmgr -n (see efibootmgr man page). If this works you could then put this in the OSX equivalent to /etc/rc.local.shutdown (whatever this is, I don't know that much about OS X).

Thats totally strange (not the efibootmgr's args support), but efibootmgr is NOT SUPPOSED to be running properly in a Mac. There have been reports of it bricking the Mac firmware (in Ubuntu and Fedora forums, not here AFAIK), so its generally not recommended to use efibootmgr for Macs.

Offline

#58 2012-04-21 14:09:16

radiomist
Member
From: superposicion
Registered: 2009-11-27
Posts: 62

Re: [Solved]The linux kernel with build in bootloader?

the.ridikulus.rat wrote:
65kid wrote:
radiomist wrote:

When i boot to OSX, OSX change the boot order :S. So Archlinux is set to second entry, How can i prevent this?

I have no idea if you can prevent OS X from doing this. Do you have efibootmgr available in OSX? maybe as a workaround you could set the boot order back in OSX with efibootmgr -o or set the BootNext parameter with efibootmgr -n (see efibootmgr man page). If this works you could then put this in the OSX equivalent to /etc/rc.local.shutdown (whatever this is, I don't know that much about OS X).

Thats totally strange (not the efibootmgr's args support), but efibootmgr is NOT SUPPOSED to be running properly in a Mac. There have been reports of it bricking the Mac firmware (in Ubuntu and Fedora forums, not here AFAIK), so its generally not recommended to use efibootmgr for Macs.



Wow, i don't know i could break my firmware..
Maybe Apple is fixing Efi to support windows 8?
I think i will change the boot method to linux.conf patch and use bless to set the linux kernel as default Efi entry.

But, looks like efibootmgr works poperly on my mac:

[lepton@Potato ~]$ sudo efibootmgr
BootCurrent: 0000
Timeout: 5 seconds
BootOrder: 0000
Boot0000* Archlinux
Boot0080* Mac OS X
Boot0082* 
BootFFFF* 

Last edited by radiomist (2012-04-21 14:15:15)

Offline

#59 2012-04-22 03:39:27

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 230

Re: [Solved]The linux kernel with build in bootloader?

I converted an existing  system encrypted install according to the instructions here by creating the /boot/efi/arch/ directory and copying the existing initramfs images and kernel there and updating the NVRAM accordingly with efibootmgr. The initramfs boots, the RAID array starts and even though lvm2 starts no volume groups are found and I don't get prompted to enter the passphrase for the encrypted root like I do when I boot using GRUB. The stub boot fails.

Since I'm using an exact copy of the initramfs in both cases I can't quite figure out what could have changed when not using GRUB.

See below for the modules and hooks I used to create the initramfs:

modules ==> nouveau dm_mod dm_crypt aes_x86_64 raid0
    hooks ==> base udev autodetect sata mdadm usbinput keymap encrypt lvm2 filesystems

Any ideas?

Last edited by KairiTech (2012-04-22 05:41:37)


-=[ LIVE enabled UEFI with redundant syslinux pure systemd detached LUKS header partitionless encrypted GPT SSDx3 RAID0 because I can.  ]=-

Backward compatibility is for the masses. There's no dual-boot here...

Offline

#60 2012-04-22 10:22:59

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved]The linux kernel with build in bootloader?

since the initramfs boots, all I can think of is a typo in the boot parameters (wrong device name)!?
Any error messages?

Offline

#61 2012-04-22 19:13:53

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 230

Re: [Solved]The linux kernel with build in bootloader?

There was only the 'no volume groups found' error.

Progress! I had remove the 'quiet' parameter because I wanted to see the progress of the STUB boot. On a whim I included it again and then I got the passphrase prompt just like when I boot GRUB but this time the boot failed with the message:

mount: unknown filesystem type 'LVM2_member'

...and this is what it was referring to:

blkid | grep LVM2_member

/dev/mapper/vg64SSDx3: UUID="8021vs-RmtM-N0as-FbCF-EdX5-it8m-JGsm9F" TYPE="LVM2_member"

...the solution...

I noticed in my existing /boot/grub.cfg that the command line parameter for root= has the logical volume appended to the volume group so (using the instructions from above as an example) I changed...

root=/dev/mapper/crypt

to...

root=/dev/mapper/crypt-root

...where "crypt" is the LVM2 volume group and 'root' is the logical volume. And it worked! I am now officially GRUBless (sort of).


Since the current version of Archboot does not have the kernel with the STUB patch I'll have to continue installing GRUB so I can boot after the install, update the kernel, then remove GRUB.

Unless there is a simple way to update Archboot to the current kernel and boot into the STUB version directly and not need to install GRUB at all.

Last edited by KairiTech (2012-04-23 15:53:27)


-=[ LIVE enabled UEFI with redundant syslinux pure systemd detached LUKS header partitionless encrypted GPT SSDx3 RAID0 because I can.  ]=-

Backward compatibility is for the masses. There's no dual-boot here...

Offline

#62 2012-04-25 07:24:40

the.ridikulus.rat
Member
From: Indiana, USA
Registered: 2011-10-04
Posts: 765

Re: [Solved]The linux kernel with build in bootloader?

Offline

#63 2012-04-28 07:11:36

the.ridikulus.rat
Member
From: Indiana, USA
Registered: 2011-10-04
Posts: 765

Re: [Solved]The linux kernel with build in bootloader?

Archboot 2012.04-2 iso has support for setting up rEFInd+EFISTUB in the UEFISYS partition.

And http://releng.archlinux.org/isos/2012.04.27_11-37-49/ boots in UEFI mode via Archiso EFISTUB booting.

Last edited by the.ridikulus.rat (2012-04-28 07:58:54)

Offline

#64 2012-04-29 15:47:29

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 230

Re: [Solved]The linux kernel with build in bootloader?

Complete success with the new Archboot 2012.04-2 iso ...  look here for the details.

Thanks again for your great work.


-=[ LIVE enabled UEFI with redundant syslinux pure systemd detached LUKS header partitionless encrypted GPT SSDx3 RAID0 because I can.  ]=-

Backward compatibility is for the masses. There's no dual-boot here...

Offline

#65 2012-05-03 00:08:31

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 230

Re: [Solved]The linux kernel with build in bootloader?

See below for my unredacted script.

Several things to note:

1. I have converted almost everything to variables with self-explanatory names

2. You can set up the variables to install a test system as well as a production system without having to change the code

3. There is no GRUB of any kind - my boot partition is tiny because I move instead of copy the kernel and initramfs.

4. There are lots of onscreen messages to keep you informed about what's going on - you can Ctrl-C at these points if you notice error messages that need fixing

5. You can select your timezone, date and time

6. You can select your location

7. The test variables create/assembles a forced single-disk RAID array

8. The RAID array is encrypted

9. LVM is on top pf the RAID array

10. You can re-install ARCH on existing volumes you created in a previous run without re-partitioning

11. There is only one post_install - it sets up the boot entry in the UEFI motherboard's NVRAM

12. Just like in the original the Archboot install media must be mounted (there's a variable for that too) and the script should have been saved to the install media

13. There is a check for my updating scripts and configurations - I can have a fully functioning desktop will all my apps in under 25 minutes and never have to reconfigure anything.

14. There may be some comment artifacts remaining from the original "Arch by Hand" script.

Enjoy!

#!/bin/bash
#
# myArchbyhand-01-install.sh
#
# https://bbs.archlinux.org/viewtopic.php?id=129885
# https://bbs.archlinux.org/viewtopic.php?pid=1090040#p1090040

# This script is designed to be run in conjunction with a UEFI boot using Archboot intall media.

 INSTALL_MOUNT="/tmp/src"

INSTALL_SOURCE="/tmp/archboot"

INSTALL_TARGET="/tmp/install"
  
      FILE_URL="file:///packages/core-$(uname -m)/pkg"

       FTP_URL='ftp://mirror.csclub.uwaterloo.ca/archlinux/$repo/os/$arch'

      HTTP_URL='http://mirror.its.dal.ca/archlinux/$repo/os/$arch'
           
getTESTsetup () {
# ===============
# ------------------------------------------------------------------------
# Install settings for testing
# ------------------------------------------------------------------------
    INSTALL_NAME="TEST"

      BOOT_DRIVE="d"
      
       UEFI_PART="1"

  UEFI_PART_SIZE="25M"

  LUKS_PART_SIZE="60G"
 
   ROOT_VOL_SIZE="3G"

      RAID_LEVEL="0"

      RAID_COUNT="1"

     RAID_DRIVES="d"
    
      RAID_PARTS="/dev/sdd2"

     RAID_DEVNUM="33"

        LVM_NAME="TESTDrive"

        HOSTNAME="KairiTech-TEST"      
# ========================================================================
}
getPRODUCTIONsetup () {
# =====================
# ------------------------------------------------------------------------
# Install settings for PRODUCTION
# ------------------------------------------------------------------------
     INSTALL_NAME="my Arch by hand"
 
       BOOT_DRIVE="a"
       
        UEFI_PART="1"

   UEFI_PART_SIZE="25M"

   LUKS_PART_SIZE="55G"
  
   ROOT_VOL_SIZE="6G"
         
      RAID_LEVEL="0"

      RAID_COUNT="3"

     RAID_DRIVES="a b c"
    
      RAID_PARTS="/dev/sda2 /dev/sdb2 /dev/sdc2"

     RAID_DEVNUM="2"

        LVM_NAME="64SSDx3"

        HOSTNAME="KairiTech-TOArch"
# ========================================================================
}

SAY="   |||   "
HR="_______________________________________________________________________________"
PROMPT=" : "

set -o nounset
# set -o errexit

# ------------------------------------------------------------------------
echo -e "\n${SAY}Checking for archboot media...\n$HR"
# ------------------------------------------------------------------------
ls -l ${INSTALL_MOUNT}/

# ------------------------------------------------------------------------
echo -e "\n${SAY}Checking for myINSTALL...\n$HR"
# ------------------------------------------------------------------------
ls -l ${INSTALL_MOUNT}/myLinux/myINSTALL/

# ------------------------------------------------------------------------
echo -e "\n${SAY}Checking for myConfigs...\n$HR"
# ------------------------------------------------------------------------
ls -l ${INSTALL_MOUNT}/myLinux/myINSTALL/myConfigs/

# ------------------------------------------------------------------------
echo -e "\n${SAY}Archboot media & myINSTALL Okay?   ...\n$HR"
# ------------------------------------------------------------------------
read -p "${SAY}${PROMPT}? " RESP

# ------------------------------------------------------------------------
echo -e "\n${SAY}test or PROD   ...\n$HR"
# ------------------------------------------------------------------------
read -p "${SAY}${PROMPT}? " TARGET
if [ $TARGET == "test" ]
   then
   	getTESTsetup
elif [ $TARGET == "PROD" ]
   then
   	getPRODUCTIONsetup
else
   # ------------------------------------------------------------------------
   echo -e "\n${SAY}Yikes!...\n$HR"
   # ------------------------------------------------------------------------
   exit
fi
                   
partitionDRIVE () {
# =================
echo -e "\n${SAY}Partitioning disk...\n$HR"
# ------------------------------------------------------------------------
sgdisk -Z                                                   /dev/sd${SDD} # zap all on disk
sgdisk -a 2048 -o                                           /dev/sd${SDD} # new gpt disk 2048 alignment
# create partitions
sgdisk -n 1:0:+${UEFI_PART_SIZE} -t 1:EF00 -c 1:"UEFI Boot" /dev/sd${SDD}
sgdisk -n 2:0:+${LUKS_PART_SIZE} -t 2:FD00 -c 2:"LUKS"      /dev/sd${SDD} 
echo -e "\n${SAY}Partitioning done...\n$HR"
sgdisk -p                                                   /dev/sd${SDD}
# ========================================================================
}

# ------------------------------------------------------------------------
# Globals
# ------------------------------------------------------------------------
# We don't need to set these here but they are used repeatedly throughout
# so it makes sense to reuse them and allow an easy, one-time change if we
# need to alter values such as the install target mount point.

       PACMAN="pacman --noconfirm --config /tmp/pacman.conf"
TARGET_PACMAN="pacman --noconfirm --config /tmp/pacman.conf -r ${INSTALL_TARGET}"
CHROOT_PACMAN="pacman --noconfirm --cachedir /var/cache/pacman/pkg --config /tmp/pacman.conf -r ${INSTALL_TARGET}"

# ------------------------------------------------------------------------
# Functions
# ------------------------------------------------------------------------
# I've avoided using functions in this script as they aren't required and
# I think it's more of a learning tool if you see the step-by-step
# procedures even with minor duplciations along the way, but I feel that
# these functions clarify the particular steps of setting values in config
# files.

SetValue () {
# ===========
# EXAMPLE: SetValue VARIABLENAME '\"Quoted Value\"' /file/path
VALUENAME="$1" NEWVALUE="$2" FILEPATH="$3"
sed -i "s+^#\?\(${VALUENAME}\)=.*$+\1=${NEWVALUE}+" "${FILEPATH}"
# ========================================================================
}

CommentOutValue () {
# ==================
VALUENAME="$1" FILEPATH="$2"
sed -i "s/^\(${VALUENAME}.*\)$/#\1/" "${FILEPATH}"
# ========================================================================
}

UncommentValue () {
# =================
VALUENAME="$1" FILEPATH="$2"
sed -i "s/^#\(${VALUENAME}.*\)$/\1/" "${FILEPATH}"
# ========================================================================
}

# ------------------------------------------------------------------------
# Initialize
# ------------------------------------------------------------------------
# Warn the user about impending doom, set up the network on eth0, mount
# the squashfs images (Archboot does this normally, we're just filling in
# the gaps resulting from the fact that we're doing a simple scripted
# install). We also create a temporary pacman.conf that looks for packages
# locally first before sourcing them from the network. It would be better
# to do either *all* local or *all* network but we can't for two reasons.
# 1. The Archboot installation image might have an out of date kernel
# (currently the case) which results in problems when chrooting
# into the install mount point to modprobe efivars. So we use the
# package snapshot on the Archboot media to ensure our kernel is
# the same as the one we booted with.
# 2. Ideally we'd source all local then, but some critical items,
# notably grub2-efi variants, aren't yet on the Archboot media.

# ------------------------------------------------------------------------
echo -e "\n${SAY}Exit now and stop all active RAID arrays you don't need...\n$HR"
# ------------------------------------------------------------------------
cat /proc/mdstat
read -p "${SAY}${PROMPT}? " RESP

## ------------------------------------------------------------------------
# Warn
# ------------------------------------------------------------------------
for Drive in ${RAID_DRIVES}
do
    SDD=${Drive}
    echo -e "\n${SAY}WARNING! WARNING! WARNING! Danger Will Robinson.\n$HR"
    sgdisk -p /dev/sd${SDD}
done
echo -e "\n${SAY}This procedure may completely format "${RAID_PARTS}" (see above)..."
echo -e "\n${SAY}Okay? You can stop now if not or just press [Enter] to continue   ...\n$HR"
read -p "${SAY}${PROMPT}? " RESP

echo "STARTING"

# ------------------------------------------------------------------------
echo -e "\n${SAY}Starting network...\n$HR"
# ------------------------------------------------------------------------
echo -n "Waiting for network address.."
#dhclient eth0
dhcpcd -p eth0
echo -e "\n${SAY}Network address acquired...\n$HR"

# ------------------------------------------------------------------------
echo -e "\n${SAY}Press [Enter] to set the time zone for your location...\n$HR"
# ------------------------------------------------------------------------
tz

# Mount packages squashfs images
# ------------------------------------------------------------------------
umount "/packages/core-$(uname -m)"
umount "/packages/core-any"
rm -rf "/packages/core-$(uname -m)"
rm -rf "/packages/core-any"

mkdir -p "/packages/core-$(uname -m)"
mkdir -p "/packages/core-any"

modprobe -q loop
modprobe -q squashfs
mount -o ro,loop -t squashfs "${INSTALL_MOUNT}/packages/archboot_packages_$(uname -m).squashfs" "/packages/core-$(uname -m)"
mount -o ro,loop -t squashfs "${INSTALL_MOUNT}/packages/archboot_packages_any.squashfs" "/packages/core-any"

# ------------------------------------------------------------------------
echo -e "\n${SAY}Creating temporary pacman.config...\n$HR"
# ------------------------------------------------------------------------
#///////////////////////////////////////////////////////////////////////////////////
cat > /tmp/pacman.conf << EOF
[options]

SigLevel = Never

Architecture = auto
CacheDir = ${INSTALL_TARGET}/var/cache/pacman/pkg
CacheDir = /packages/core-$(uname -m)/pkg
CacheDir = /packages/core-any/pkg

[core]
Server = ${FILE_URL}
Server = ${FTP_URL}
Server = ${HTTP_URL}

[extra]
Server = ${FILE_URL}
Server = ${FTP_URL}
Server = ${HTTP_URL}

EOF
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

[[ ! -d "${INSTALL_TARGET}/var/cache/pacman/pkg" ]] && mkdir -m 755 -p "${INSTALL_TARGET}/var/cache/pacman/pkg"
# ------------------------------------------------------------------------
echo -e "\n${SAY}Downloading system updates...\n$HR"
# ------------------------------------------------------------------------
${PACMAN} -Sy

[[ ! -d "${INSTALL_TARGET}/var/lib/pacman" ]] && mkdir -m 755 -p "${INSTALL_TARGET}/var/lib/pacman"
# ------------------------------------------------------------------------
echo -e "\n${SAY}Downloading system updates for NEW install...\n$HR"
# ------------------------------------------------------------------------
${TARGET_PACMAN} -Sy

# ------------------------------------------------------------------------
# configure Host
# ------------------------------------------------------------------------
# Here we create three partitions:
# 1. efi and /boot (one partition does double duty)
# 3. our encrypted root
# Note that all of these are on a GUID partition table scheme. This proves
# to be quite clean and simple since we're not doing anything with MBR
# boot partitions and the like.

# ------------------------------------------------------------------------
echo -e "\n${SAY}Repartition RAID_DRIVES (uppercase 'yes'/n)?   ...\n$HR"
# ------------------------------------------------------------------------
read -p "${SAY}${PROMPT}? " REPARTITION
if [ "$REPARTITION" = "YES" ]
then
	for Drive in ${RAID_DRIVES}
	do
	    SDD=$Drive ; partitionDRIVE
	done
	
	# ------------------------------------------------------------------------
	echo -e "\n${SAY}Building RAID0...\n$HR"
	# ------------------------------------------------------------------------
	modprobe raid0
	mdadm --stop   /dev/md127
	mdadm --stop   /dev/md${RAID_DEVNUM}
	mdadm --create /dev/md${RAID_DEVNUM} --metadata=0.90 --level=${RAID_LEVEL} --raid-devices=${RAID_COUNT} --force ${RAID_PARTS} 
	
	# ------------------------------------------------------------------------
	echo -e "\n${SAY}Encrypting with LUKS...\n$HR"
	# ------------------------------------------------------------------------
	cryptsetup --cipher=aes-xts-plain --verify-passphrase --key-size=512 luksFormat /dev/md${RAID_DEVNUM}
	echo -e "\n${SAY}Opening encrypted device...\n$HR"
	cryptsetup luksOpen /dev/md${RAID_DEVNUM} pv${LVM_NAME}
	
	# ------------------------------------------------------------------------
	echo -e "\n${SAY}Creating physical volume...\n$HR"
	# ------------------------------------------------------------------------
	pvcreate /dev/mapper/pv${LVM_NAME}
	echo -e "\n${SAY}Creating volume group...\n$HR"
	vgcreate vg${LVM_NAME} /dev/mapper/pv${LVM_NAME} 
	echo -e "\n${SAY}Creating logical volumes...\n$HR"
	lvcreate --contiguous y --size ${ROOT_VOL_SIZE} --name lvRoot vg${LVM_NAME} 
	lvcreate --extents +100%FREE --name lvMyStuff vg${LVM_NAME} 
	echo -e "\n${SAY}LVM Okay? You can stop now if not or just press [Enter]   ...\n$HR"
	read -p "${SAY}${PROMPT}? " RESP
else
	# ------------------------------------------------------------------------
	echo -e "\n${SAY}Repartitioning aborted by you so I'm going to try opening existing encrypted volumes...\n$HR"
	# ------------------------------------------------------------------------
	mdadm --assemble /dev/md${RAID_DEVNUM} ${RAID_PARTS}
	cryptsetup luksOpen /dev/md${RAID_DEVNUM} pv${LVM_NAME}
	vgchange -ay
	echo -e "\n${SAY}Physical volumes...\n$HR"
	pvdisplay --short
	echo -e "\n${SAY}Volume groups...\n$HR"
	vgdisplay --short
	echo -e "\n${SAY}Logical volume...\n$HR"
	lvdisplay --colon
	echo -e "\n${SAY}LVM Okay? You can stop now if not or just press [Enter]   ...\n$HR"
	read -p "${SAY}${PROMPT}? " RESP	
fi

# ------------------------------------------------------------------------
echo -e "\n${SAY}Creating filesystems...\n$HR"
# ------------------------------------------------------------------------
mkfs.vfat /dev/sd${BOOT_DRIVE}${UEFI_PART}
mkfs.ext4 /dev/mapper/vg${LVM_NAME}-lvRoot
if [ "$REPARTITION" = "YES" ]
	then
		mkfs.ext4 /dev/mapper/vg${LVM_NAME}-lvMyStuff
fi
# mount target
rm -r ${INSTALL_TARGET}
mkdir ${INSTALL_TARGET}
mount /dev/mapper/vg${LVM_NAME}-lvRoot ${INSTALL_TARGET}
mkdir ${INSTALL_TARGET}/boot
mount -t vfat /dev/sd${BOOT_DRIVE}${UEFI_PART} ${INSTALL_TARGET}/boot
mkdir -p ${INSTALL_TARGET}/media/myStuff
mount -t ext4 /dev/mapper/vg${LVM_NAME}-lvMyStuff ${INSTALL_TARGET}/media/myStuff

# ------------------------------------------------------------------------
echo -e "\n${SAY}Downloading and installing base...\n$HR"
# ------------------------------------------------------------------------
mkdir -p ${INSTALL_TARGET}/var/lib/pacman
${TARGET_PACMAN} -Sy
${TARGET_PACMAN} -Su base

rm -rf ${INSTALL_TARGET}/boot/grub
${TARGET_PACMAN} -S efibootmgr

# ------------------------------------------------------------------------
# Configure new system
# ------------------------------------------------------------------------
SetValue LOCALE        "en_US.UTF-8"            ${INSTALL_TARGET}/etc/rc.conf
SetValue HARDWARECLOCK "UTC"                    ${INSTALL_TARGET}/etc/rc.conf
SetValue TIMEZONE      "America/Toronto"        ${INSTALL_TARGET}/etc/rc.conf
SetValue KEYMAP        "us"                     ${INSTALL_TARGET}/etc/rc.conf
SetValue USECOLOR      "yes"                    ${INSTALL_TARGET}/etc/rc.conf
SetValue USEDMRAID     "yes"                    ${INSTALL_TARGET}/etc/rc.conf
SetValue USELVM        "yes"                    ${INSTALL_TARGET}/etc/rc.conf
SetValue HOSTNAME      ${HOSTNAME}              ${INSTALL_TARGET}/etc/rc.conf
SetValue interface     "eth0"                   ${INSTALL_TARGET}/etc/rc.conf
sed -i "s/^\(127\.0\.0\.1.*\)$/\1 ${HOSTNAME}/" ${INSTALL_TARGET}/etc/hosts

# ------------------------------------------------------------------------
# You can use UUID's or whatever you want here, of course. This is just
# the simplest approach and as long as your RAID_DRIVES aren't changing values
# randomly it should work fine.
# ------------------------------------------------------------------------
echo -e "\n${SAY}Creating fstab...\n$HR"
# ------------------------------------------------------------------------
#///////////////////////////////////////////////////////////////////////////////////
cat > ${INSTALL_TARGET}/etc/fstab << EOF
#
# /etc/fstab: static file system information
#
# <file system>                     <dir>          <type> <options>        <dump> <pass>
tmpfs                               /tmp           tmpfs  nodev,nosuid     0      0
/dev/sd${BOOT_DRIVE}${UEFI_PART}    /boot          vfat   defaults         0      0
/dev/mapper/vg${LVM_NAME}-lvRoot    /              ext4   defaults,noatime 0      1
/dev/mapper/vg${LVM_NAME}-lvMyStuff /media/myStuff ext4   defaults,noatime 0      0

EOF
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

# ------------------------------------------------------------------------
# copy configs we want to carry over to target from install environment
# ------------------------------------------------------------------------

# ------------------------------------------------------------------------
echo -e "\n${SAY}Saving configurations...\n$HR"
# ------------------------------------------------------------------------

mv ${INSTALL_TARGET}/etc/resolv.conf ${INSTALL_TARGET}/etc/resolv.conf.orig
cp /etc/resolv.conf ${INSTALL_TARGET}/etc/resolv.conf

mkdir -p ${INSTALL_TARGET}/tmp
cp /tmp/pacman.conf ${INSTALL_TARGET}/tmp/pacman.conf

# ------------------------------------------------------------------------
# mount proc, sys, dev in install root
# ------------------------------------------------------------------------

mount -t proc proc ${INSTALL_TARGET}/proc
mount -t sysfs sys ${INSTALL_TARGET}/sys
mount -o bind /dev ${INSTALL_TARGET}/dev

# we have to remount /boot from inside the chroot
umount ${INSTALL_TARGET}/boot

# ------------------------------------------------------------------------
echo -e "\n${SAY}Creating post install script...\n$HR"
# ------------------------------------------------------------------------
#///////////////////////////////////////////////////////////////////////////////////
cat > ${INSTALL_TARGET}/post_install << EOF
#!/bin/bash
#
# post_install
#
set -o errexit
set -o nounset

SAY="   ||||||   "
HR="_______________________________________________________________________________"
PROMPT=" : "

# ------------------------------------------------------------------------
echo -e "\n${SAY}Entering new install...\n$HR"
# ------------------------------------------------------------------------

# functions (these could be a library, but why overcomplicate things)
# ------------------------------------------------------------------------
SetValue () {
# ===========
VALUENAME="\$1" NEWVALUE="\$2" FILEPATH="\$3"
sed -i "s+^#\?\(\${VALUENAME}\)=.*\$+\1=\${NEWVALUE}+" "\${FILEPATH}"
# ========================================================================
}
CommentOutValue () {
# ==================
VALUENAME="\$1" FILEPATH="\$2"
sed -i "s/^\(\${VALUENAME}.*\)\$/#\1/" "\${FILEPATH}"
# ========================================================================
}
UncommentValue () {
# =================
VALUENAME="\$1" FILEPATH="\$2"
sed -i "s/^#\(\${VALUENAME}.*\)\$/\1/" "\${FILEPATH}"
# ========================================================================
}

# remount here or grub et al gets confused
# ------------------------------------------------------------------------
mount -t vfat /dev/sd${BOOT_DRIVE}${UEFI_PART} /boot

# ------------------------------------------------------------------------
echo -e "\n${SAY}Saving RAID configuration...\n$HR"
# ------------------------------------------------------------------------
mdadm --examine --scan > /etc/mdadm.conf

# ------------------------------------------------------------------------
echo -e "\n${SAY}Press [Enter] to remove any RAID arrays you do not need...\n$HR"
# ------------------------------------------------------------------------
read -p "${SAY}${PROMPT}? " RESP
nano /etc/mdadm.conf

# ------------------------------------------------------------------------
echo -e "\n${SAY}Making boot image...\n$HR"
# ------------------------------------------------------------------------

SetValue MODULES '\\"nouveau dm_mod dm_crypt aes_x86_64 raid0\\"'                                 /etc/mkinitcpio.conf
SetValue HOOKS   '\\"base udev autodetect sata mdadm usbinput keymap encrypt lvm2 filesystems\\"' /etc/mkinitcpio.conf
mkinitcpio -p linux

# locale-gen
# ------------------------------------------------------------------------
UncommentValue en_US /etc/locale.gen
locale-gen

# kernel modules for EFI install
# ------------------------------------------------------------------------
modprobe efivars
modprobe dm-mod

# ------------------------------------------------------------------------
echo -e "\n${SAY}Installing Linux STUB...\n$HR"
# ------------------------------------------------------------------------
mkdir -p                     /boot/efi/arch/
mv /boot/vmlinuz-linux       /boot/efi/arch/vmlinuz-linux.efi
mv /boot/initramfs-linux.img /boot/efi/arch/
echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/vg${LVM_NAME}-lvRoot cryptdevice=/dev/md${RAID_DEVNUM}:vg${LVM_NAME} add_efi_memmap pcie_aspm=force quiet" | iconv -f ascii -t ucs2  |   efibootmgr --create --gpt --disk /dev/sd${BOOT_DRIVE} --part 1  --label "${INSTALL_NAME} (STUB) $(date +%x) $(date +%X)"          --loader '\efi\arch\vmlinuz-linux.efi' --append-binary-args -
echo "initrd=\efi\arch\initramfs-linux.img root=/dev/mapper/vg${LVM_NAME}-lvRoot cryptdevice=/dev/md${RAID_DEVNUM}:vg${LVM_NAME} add_efi_memmap pcie_aspm=force quiet" > /boot/efi/arch/linux.conf ; efibootmgr --create --gpt --disk /dev/sd${BOOT_DRIVE} --part 1  --label "${INSTALL_NAME} (CONF) $(date +%x) $(date +%X)"  --loader '\efi\arch\vmlinuz-linux.efi'

# ------------------------------------------------------------------------
echo -e "\n${SAY}New password for root...\n$HR"
# ------------------------------------------------------------------------
passwd

# ------------------------------------------------------------------------
echo -e "\n${SAY}Press [Enter] to uncomment the mirrors closest to you...\n$HR"
# ------------------------------------------------------------------------
read -p "${SAY}${PROMPT}? " RESP
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.original
nano /etc/pacman.d/mirrorlist

# ------------------------------------------------------------------------
echo -e "\n${SAY}Remove entries you don't need with efibootmgr -b X -B  -and-  set your default with efibootmge -o X\n$HR"
# ------------------------------------------------------------------------
efibootmgr

exit

EOF
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
chmod a+x ${INSTALL_TARGET}/post_install

# ------------------------------------------------------------------------
echo -e "\n${SAY}Running post install...\n$HR"
# ------------------------------------------------------------------------
chroot ${INSTALL_TARGET} /post_install
rm ${INSTALL_TARGET}/post_install

-=[ LIVE enabled UEFI with redundant syslinux pure systemd detached LUKS header partitionless encrypted GPT SSDx3 RAID0 because I can.  ]=-

Backward compatibility is for the masses. There's no dual-boot here...

Offline

#66 2012-05-03 14:30:06

fschiff
Member
Registered: 2011-10-06
Posts: 71

Re: [Solved]The linux kernel with build in bootloader?

I find this utterly fascinating.

q:

Why no SWAP?

What have you put on the myConfig directory, etc?  Is that supposed to be on the mastered ArchBoot disk?

Offline

#67 2012-05-03 16:20:04

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 230

Re: [Solved]The linux kernel with build in bootloader?

@fschiff

I have 8GB of RAM and in all the years I have monitored swap usage I have never seen anything I've done use it.

The Archboot media is installed to INSTALL_MOUNT="/tmp/src"

The myConfig directory has scripts that I run after the first boot into the new system for system configuration - things like CPU scaling, app installation and configuration - I rely on a few standards, user configuration - desktop environment. I like to know that I can boot successfully before I set everything up the way I like so my install script gives me the absolute barebones. The config scripts makes it really easy to replicate a system I've spent months tweaking just so. Might almost be called a pseudo-distribution. Almost!

Last edited by KairiTech (2012-05-03 16:28:25)


-=[ LIVE enabled UEFI with redundant syslinux pure systemd detached LUKS header partitionless encrypted GPT SSDx3 RAID0 because I can.  ]=-

Backward compatibility is for the masses. There's no dual-boot here...

Offline

#68 2012-05-06 22:20:48

Tasqa
Member
Registered: 2012-04-27
Posts: 14

Re: [Solved]The linux kernel with build in bootloader?

litemotiv wrote:

Update: i am now succesfully booting the stock Arch 3.3 kernel from rEFInd with EFI_STUB. The main tweaks i had to make were:

Rename the kernel and initramfs files to include version numbers:

$ ls /efi/linux
vmlinuz-linux-3.3.0.efi 
initrd.img-3.3.0
linux.conf

Other filenames might work too, but the autodetection mechanism is not 100% yet. For instance using the filename initramfs-linux.img didn't work.

linux.conf contains the kernel parameters:

$ cat linux.conf
"Default" "root=/dev/sda5 ro"

Hey i've been trying to get this going on my macbook for 3 days now.. No luck so far.
I've been messing around with a gazillion root parameters but the boot still hangs on loading uevents sad
Any idea what might be causing this?

Offline

#69 2012-05-08 22:54:22

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [Solved]The linux kernel with build in bootloader?

Tasqa wrote:

Hey i've been trying to get this going on my macbook for 3 days now.. No luck so far.
I've been messing around with a gazillion root parameters but the boot still hangs on loading uevents sad
Any idea what might be causing this?

Sorry for the late reply Tasqa. You might be missing some kernel modules since EFI booting will provide more extensive hardware access to your machine. If you have not done so yet, try adding 'ahci' to the modules line in /etc/mkinitcpio.conf and then issue:

# mkinitcpio -p linux

Then copy the new kernel and initramfs to the appropriate location. You won't need to include the version numbers anymore in the kernel and initramfs filenames, updated instructions are in the wiki:

https://wiki.archlinux.org/index.php/Un … h_EFI_STUB


ᶘ ᵒᴥᵒᶅ

Offline

#70 2012-05-09 13:19:46

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved]The linux kernel with build in bootloader?

While changing /etc/mkinitcpio.d/linux.preset might take care of the intramfs, I was a little annoyed that I still had to copy the kernel to /boot/efi/arch/vmlinuz-linux.efi after every kernel update. With initscripts I probably would just have put a "cp" into etc/rc.local.shutdown, but there is an imho much more elegant way with systemd, I thought I might share it here. wink

/etc/systemd/system/efikernel.path

[Unit]
Description=Copy kernel to EFI folder

[Path]
PathChanged=/boot/vmlinuz-linux

[Install]
WantedBy=boot.mount

/etc/systemd/system/efikernel.service

[Unit]
Description=Copy kernel to EFI folder

[Service]
Type=oneshot
ExecStart=/bin/cp /boot/vmlinuz-linux /boot/efi/arch/vmlinuz-linux.efi
systemctl enable efikernel.path

systemd will then watch /boot/vmlinuz-linux and copy it to /boot/efi/arch/vmlinuz-linux.efi everytime it changes. The *.path unit will automatically be activated when /boot is mounted.

Last edited by 65kid (2012-05-16 12:31:01)

Offline

#71 2012-05-09 13:40:44

the.ridikulus.rat
Member
From: Indiana, USA
Registered: 2011-10-04
Posts: 765

Re: [Solved]The linux kernel with build in bootloader?

65kid wrote:

While changing /etc/mkinitcpio.d/linux.preset might take care of the intramfs, I was a little annoyed that I still had to copy the kernel to /boot/efi/arch/vmlinuz-linux.efi after every kernel update. With initscripts I probably would just have put a "cp" into /etc/rc.local, but there is an imho much more elegant way with systemd, I thought I might share it here. wink

/etc/systemd/system/efikernel.path

[Unit]
Description=Copy kernel to EFI folder

[Path]
PathChanged=/boot/vmlinuz-linux

[Install]
WantedBy=boot.mount

/etc/systemd/system/efikernel.service

[Unit]
Description=Copy kernel to EFI folder

[Service]
Type=OneShot
ExecStart=/bin/cp /boot/vmlinuz-linux /boot/efi/arch/vmlinuz-linux.efi
systemctl enable efikernel.path

systemd will then watch /boot/vmlinuz-linux and copy it to /boot/efi/arch/vmlinuz-linux.efi everytime it changes. The *.path unit will automatically be activated when /boot is mounted.

Nice, what about initramfs files?

Offline

#72 2012-05-09 13:43:16

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved]The linux kernel with build in bootloader?

the.ridikulus.rat wrote:

Nice, what about initramfs files?

as mentioned, just edit the paths in /etc/mkinitcpio.d/linux.preset

Offline

#73 2012-05-16 12:02:45

the.ridikulus.rat
Member
From: Indiana, USA
Registered: 2011-10-04
Posts: 765

Re: [Solved]The linux kernel with build in bootloader?

Offline

#74 2012-05-16 12:06:35

the.ridikulus.rat
Member
From: Indiana, USA
Registered: 2011-10-04
Posts: 765

Re: [Solved]The linux kernel with build in bootloader?

65kid wrote:
the.ridikulus.rat wrote:

Nice, what about initramfs files?

as mentioned, just edit the paths in /etc/mkinitcpio.d/linux.preset

Since initramfs files are always updated when kernel package is updated and in cases where the user updates only the initramfs files, I suggest keeping track of the initramfs-fallback file alone. If that file is changed, copy the updated kernel and both the initramfs files to UEFISYS partition.

Offline

#75 2012-05-16 12:25:26

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: [Solved]The linux kernel with build in bootloader?

the.ridikulus.rat wrote:
65kid wrote:
the.ridikulus.rat wrote:

Nice, what about initramfs files?

as mentioned, just edit the paths in /etc/mkinitcpio.d/linux.preset

Since initramfs files are always updated when kernel package is updated and in cases where the user updates only the initramfs files, I suggest keeping track of the initramfs-fallback file alone. If that file is changed, copy the updated kernel and both the initramfs files to UEFISYS partition.

Sorry, I don't quite understand what you mean. Why would I want to keep track of the initramfs when I can adjust the path the initramfs is written to in /etc/mkinitcpio.d/linux.preset? the initramfs will then always be written directly to the UEFI partition by mkinitcpio and then I only have to worry about the kernel.

IMHO the most simple way would actually be if the linux package would write the kernel to /boot/vmlinuz-linux.efi instead of /boot/vmlinuz-linux. I would then mount the UEFI partition to /efi and symlink /boot to /efi/efi/arch/ . In this case you wouldn't even have to modify the initramfs path in linux.preset and updating the kernel would "just work".
But I don't think the devs would consider changing this (yet) since EFI stub is still quite new and only used by a handful of people.

Offline

Board footer

Powered by FluxBB