You are not logged in.

#1 2023-06-12 12:58:39

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

My installation script

I am trying to create my own installation script and am having some issues.
This is the first one I want to ask here about.

Below is the script.
What happens is , it stops but it is still waiting for me to type exit for some reason and when I do it completes the pacman -S grub efibootmgr part.

If you have a better way I can do this let me know. I am learning on the fly.

#!/usr/bin/env bash

set -eu

drive=sda
efi=sda2
main=sda3
MNT_DIR="/mnt/usb"
TIMEZONE="/usr/share/zoneinfo/America/New_York"
LOCALE="en_US.UTF-8 UTF-8"
VARIABLE="en_US.UTF-8"
HOSTNAME="arch-linux"
ROOT_PASSWORD="root"

# Create a 10M BIOS partition, a 500M EFI partition, and a Linux partition with the remaining space:
sgdisk --zap-all /dev/$drive
sudo sgdisk -o -n 1:0:+10M -t 1:EF02 -n 2:0:+500M -t 2:EF00 -n 3:0:0 -t 3:8300 /dev/$drive

#Do not format the /dev/sdX1 block. This is the BIOS/MBR parition.
#Format the 500MB EFI system partition with a FAT32 filesystem:
#sudo umount /dev/$efi
#sudo umount /dev/$main
sudo mkfs.fat -F32 /dev/$efi

#Format the Linux partition with an ext4 filesystem:
#sudo umount /dev/$main
yes y | sudo mkfs.ext4 /dev/$main

#mount
#Mount the ext4 formatted partition as the root filesystem:
sudo mkdir -p /mnt/usb
sudo mount /dev/$main /mnt/usb

#Mount the FAT32 formatted EFI partition to /boot:
sudo mkdir /mnt/usb/boot
sudo mount /dev/$efi /mnt/usb/boot

#pacstrap
#Download and install the Arch Linux base packages:
sudo pacstrap /mnt/usb linux linux-firmware base nano

#fstab
sudo genfstab -U /mnt/usb > /mnt/usb/etc/fstab

#configure base system
#chroot into the system
#sudo arch-chroot /mnt/usb

#locale
#sudo ln -sf /user/share/zoneinfo/America/New_York /etc/location
sudo arch-chroot "${MNT_DIR}" ln -s -f "$TIMEZONE" /etc/localtime

#Generate /etc/adjtime
sudo arch-chroot "${MNT_DIR}" hwclock --systohc

#Edit /etc/locale.gen an enter locale
sudo sed -i "s/#$LOCALE/$LOCALE/" "${MNT_DIR}"/etc/locale.gen

#Generate the locale information
sudo arch-chroot "${MNT_DIR}" locale-gen

#Set the LANG variable in /etc/locale.conf to en_US.UTF-8
sudo arch-chroot "${MNT_DIR}" echo -e "$VARIABLE" >> "${MNT_DIR}"/etc/locale.conf

#hostname
sudo arch-chroot "${MNT_DIR}" echo "$HOSTNAME" >> "${MNT_DIR}"/etc/hostname

#Edit /etc/hosts to contain only the following content:
sudo arch-chroot "${MNT_DIR}" 
echo "127.0.0.1 localhost" >> "${MNT_DIR}"/etc/hosts
echo "::1  localhost" >> "${MNT_DIR}"/etc/hosts
echo "127.0.1.1 "$HOSTNAME".localdomain "$HOSTNAME"" >> "${MNT_DIR}"/etc/hosts 

#password
#printf "%s\n%s" "$ROOT_PASSWORD" "$ROOT_PASSWORD" | arch-chroot "${MNT_DIR}" passwd
#sudo arch-chroot "${MNT_DIR}" passwd

#Bootloader
#Install grub and efibootmanger
yes | arch-chroot "${MNT_DIR}" pacman -S grub efibootmgr

Thanks

Online

#2 2023-06-12 13:22:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,561
Website

Re: My installation script

1. Lines 63 + 66 are a bit misleading.  I first was going to comment that the >> redirection would not work in the chroot as I though you intended.  But then I realized you had ${MNT_DIR} as a prefix of the target of the redirection, so that should be okay.  But it highlights that the arch-chroot is completely unnecessary in both of those lines.  You are just echoing to a file under ${MNT_DIR} just as in the later lines.  Also, as variable names go, VARIABLE has to be one of the worst tongue

2. The actual source of your real problem, though, is almost certainly line 69.  There is a trailing space at the end of that line suggesting that you just forgot to finish it.  But as it, it will just run a shell in the chroot.  As that is never exited, nothing after that line is likely to happen (until you exit the subshell?)

3.  All together, this repeated use of arch-chroot for many commands is a bit complicated and error-prone.  More often one would create a script for the second half of the installation process under the mountpoint then chroot and run that, e.g.:

# after genfstab
cat << EOF > ${MNT_DIR}/install.sh
ln -sf ... #timezone stuff
hwclock --systohc
sed -i '<whataver>' /etc/locale.gen
locale-gen
# ... whatever else
EOF

arch-chroot ${MNT_DIR} /install.sh

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2023-06-12 13:26:18

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

Thanks
That's the kind of help I was looking for.
I am a newbie at bash script writing.
Let me play around with your suggestions and I will post back here how it works out.

Online

#4 2023-06-12 20:58:58

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

Ok I have added the following to the script.

#run rest of intsall from a arch-chroot script
cat << EOF > "${MNT_DIR}"/install.sh
ln -s -f "$TIMEZONE" /etc/localtime
hwclock --systohc
sed -i "s/#$LOCALE/$LOCALE/" "${MNT_DIR}"/etc/locale.gen
locale-gen
echo -e "$LANG1" >> "${MNT_DIR}"/etc/locale.conf
echo "$HOSTNAME" >> "${MNT_DIR}"/etc/hostname
echo "127.0.0.1 localhost" >> "${MNT_DIR}"/etc/hosts
echo "::1  localhost" >> "${MNT_DIR}"/etc/hosts
echo 127.0.1.1 "$HOSTNAME".localdomain "$HOSTNAME" >> "${MNT_DIR}"/etc/hosts
yes | pacman -S grub efibootmgr
EOF

arch-chroot ${MNT_DIR} /install.sh

I keep getting the error:

chroot: failed to run command '/install.sh': Permission denied

I have put sudo in front of arch-chroot
I have run the script as root

Same error each time.

Online

#5 2023-06-12 22:06:39

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,561
Website

Re: My installation script

Sorry, that was my mistake - you need to make it executable (e.g., `chmod 0755 /path/to/script`).  That or you could explicitly pass it to a shell.  So one or the other of the following:

...
EOF

chmod 0755 ${MNT_DIR}/install.sh

arch-chroot ${MNT_DIR} /install.sh

### OR ###

...
EOF

arch-chroot ${MNT_DIR} /bin/sh /install.sh

But it's probably better off it didn't run yet as there are several problems in that content.  The install.sh or whatever content you put in that here-document will be run inside the chroot, so you should not use $MNT_DIR at all.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#6 2023-06-13 13:30:59

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

I am making some progress.

Some lines of code are working and some are not.
I will be working through it to fine tune it.
I appreciate the help.

sed: can't read /mnt/usb/etc/locale.gen: No such file or directory
Generating locales...
Generation complete.
/install.sh: line 5: /mnt/usb/etc/locale.conf: No such file or directory
/install.sh: line 6: /mnt/usb/etc/hostname: No such file or directory
/install.sh: line 7: /mnt/usb/etc/hosts: No such file or directory
/install.sh: line 8: /mnt/usb/etc/hosts: No such file or directory
/install.sh: line 9: /mnt/usb/etc/hosts: No such file or directory
resolving dependencies...
looking for conflicting packages...

Packages (3) efivar-38-3  efibootmgr-18-2  grub-2:2.06.r499.ge67a551a4-1

Total Download Size:    6.95 MiB
Total Installed Size:  33.69 MiB

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 grub-2:2.06.r499.ge67a551a4-1-x86_64                   6.8 MiB   524 KiB/s 00:13 [###############################################] 100%
 efivar-38-3-x86_64                                   147.1 KiB   298 KiB/s 00:00 [###############################################] 100%
 efibootmgr-18-2-x86_64                                29.9 KiB   203 KiB/s 00:00 [###############################################] 100%
 Total (3/3)                                            7.0 MiB   506 KiB/s 00:14 [###############################################] 100%
(3/3) checking keys in keyring                                                    [###############################################] 100%
(3/3) checking package integrity                                                  [###############################################] 100%
(3/3) loading package files                                                       [###############################################] 100%
(3/3) checking for file conflicts                                                 [###############################################] 100%
(3/3) checking available disk space                                               [###############################################] 100%
:: Processing package changes...
(1/3) installing grub                                                             [###############################################] 100%
:: Install your bootloader and generate configuration with:
     $ grub-install ...
     $ grub-mkconfig -o /boot/grub/grub.cfg
Optional dependencies for grub
    freetype2: For grub-mkfont usage
    fuse2: For grub-mount usage
    dosfstools: For grub-mkrescue FAT FS and EFI support
    lzop: For grub-mkrescue LZO support
    efibootmgr: For grub-install EFI support [pending]
    libisoburn: Provides xorriso for generating grub rescue iso using grub-mkrescue
    os-prober: To detect other OSes when generating grub.cfg in BIOS systems
    mtools: For grub-mkrescue FAT FS support
(2/3) installing efivar                                                           [###############################################] 100%
(3/3) installing efibootmgr                                                       [###############################################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...
[root@archlinux demo]#

Last edited by MAYBL8 (2023-06-13 13:31:31)

Online

#7 2023-06-13 14:23:07

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,561
Website

Re: My installation script

sed: can't read /mnt/usb/etc/locale.gen: No such file or directory
...
/install.sh: line <num>: /mnt/usb/<file>: No such file or directory

Do not use ${MNT_DIR} at all from within the chroot (e.g., between the lines "cat << EOF .." and "EOF" that go into install.sh).

Last edited by Trilby (2023-06-13 14:41:43)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2023-06-13 14:45:34

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

Yep
That’s what i just figured out.

Do you mind i keep posting my progress on this project?
Hopefully it could help others with similar projects.

Online

#9 2023-06-13 15:43:02

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: My installation script

MAYBL8 wrote:

Do you mind i keep posting my progress on this project?
Hopefully it could help others with similar projects.

You are welcome to ask for help with your script as long as you are the end user. What we will not support is if you give the script to someone else and they show up here asking for help with their new "Arch" install.

Offline

#10 2023-06-15 13:37:28

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

Just wanted to give an update.
I am adding to the script to complete it for my use.
I will post the final version soon and have you guys give me some pointers on making it cleaner.
I appreciate all the help I've received so far.

Online

#11 2023-06-20 18:32:32

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

I am almost complete with my script. With something like this there always more things or options to add.

I have run into an issue.

I have tried this on a couple of different usb flash drives and it errors out on them.

One of the errors I get is invalid checksums or it crashes on boot up. I can give specific errors if needed.
Right now I have tested on usb 2.0 flash drives and they seem to work fine.
On the 3.2 / 3.1  drives I haven't been able to get one of these to work.
They seem to do fine copying files to them. I have reformatted them , recreated partitions on them.
All of that happens without errors.

Can you answer a generic question?
Does Arch Linux or maybe the commands or script have issues doing what I am attempting to do on USB 3.x drives?

Is there a specific type of usb flash drive recommended?
Thanks

Last edited by MAYBL8 (2023-06-20 18:33:46)

Online

#12 2023-06-20 18:59:33

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,789

Re: My installation script

No and no and not in general. However USB devices have limited write cycles and you might be approaching these, or you flashed incorrectly or there's a bug in your firmware with USB 3 controllers. But all of this is quite specific and not "generally an Arch issue"

Offline

#13 2023-06-21 13:20:55

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

Here is v1.00.00.
The scripts works for archlinux installs from hard drive
If you use a distro like Manjaro you might have issues. Run at your own risk.
I have tested it on arch linux install and Manjaro and Arcolinux.

At the beginning of the script there are variables you can set for yourself.
Future changes might be having this in a separate file or a question interface to set the variable before running the script.
It uses iwctl for wireless setup.
I did not test on a wired network.
Also I have a hires 4k screen on my laptop so I have nomodeset in grub so I can see the screen text.
No xorg is on this install. Just a basic Arch Install.
I got the idea for this from alis script and the arch wiki .
This is almost a copy of following this website:
https://mags.zone/help/arch-usb.html
I was tired of typing all of this everytime I wanted to create a base arch on a usb.
One of my first thoughts on this was to create a testing usb for troubleshooting computer issues and maybe something like kali linux.
This has been a fun project to learn some advanced scripting and thanks for the help from people here.

I will be glad to get comments on the script and make some improvements.

Ok here it is:

#!/usr/bin/env bash

set -eu

drive=sda
efi=sda2
main=sda3
MNT_DIR="/mnt/usb"
TIMEZONE="/usr/share/zoneinfo/America/New_York"
LOCALE="en_US.UTF-8 UTF-8"
LANG1=LANG="en_US.UTF-8"
HOSTNAME="arch-linux"
ROOT_PASSWORD="root"
USER="demo"
USER_PASSWORD="demo"

# Create a 10M BIOS partition, a 500M EFI partition, and a Linux partition with the remaining space:
sgdisk --zap-all /dev/$drive
sudo sgdisk -o -n 1:0:+10M -t 1:EF02 -n 2:0:+500M -t 2:EF00 -n 3:0:0 -t 3:8300 /dev/$drive
#sudo sgdisk -o -n 1:0:+10M -t 1:EF02 -n 2:0:+500M -t 2:EF00 -n 3:0:+8096M -t 3:8300 /dev/$drive

#Do not format the /dev/sdX1 block. This is the BIOS/MBR parition.
#Format the 500MB EFI system partition with a FAT32 filesystem:
sudo mkfs.fat -F32 /dev/$efi

#Format the Linux partition with an ext4 filesystem:
yes y | sudo mkfs.ext4 /dev/$main

#mount
#Mount the ext4 formatted partition as the root filesystem:
sudo mkdir -p /mnt/usb
sudo mount /dev/$main /mnt/usb

#Mount the FAT32 formatted EFI partition to /boot:
sudo mkdir /mnt/usb/boot
sudo mount /dev/$efi /mnt/usb/boot

#pacstrap
#Download and install the Arch Linux base packages:
sudo pacstrap /mnt/usb linux linux-firmware base nano

#fstab
sudo genfstab -U /mnt/usb > /mnt/usb/etc/fstab

#run rest of intsall from a arch-chroot script

cat << EOF > "${MNT_DIR}"/install.sh

locale
ln -s -f "$TIMEZONE" /etc/localtime

#Generate /etc/adjtime
hwclock --systohc

#Uncomment the desired Language
sed -i "s/#$LOCALE/$LOCALE/" /etc/locale.gen

#Generate the locale information
locale-gen

#Set the LANG variable in /etc/locale.conf
echo -e "$LANG1" >> /etc/locale.conf

#Create a /etc/hostname with the desired hostname
echo "$HOSTNAME" >> /etc/hostname

#Put the following in the /etc/hosts file
echo "127.0.0.1 localhost" >> /etc/hosts
echo "::1  localhost" >> /etc/hosts
echo 127.0.1.1 "$HOSTNAME".localdomain "$HOSTNAME" >> /etc/hosts

#Set the root password
printf "%s\n%s" "$ROOT_PASSWORD" "$ROOT_PASSWORD" | passwd

#Install grub and efibootmgr
yes | pacman -S grub efibootmgr

#Install grub for both BIOS and UEFI booting
grub-install --target=i386-pc --recheck /dev/$drive
grub-install --target=x86_64-efi --efi-directory /boot --recheck --removable

#Change some settings in the /etc/default/grub file
sed -i 's/GRUB_GFXMODE=auto/GRUB_GFXMODE=800x600/' /etc/default/grub
sed -i 's/#GRUB_SAVEDEFAULT=true/GRUB_SAVEDEFAULT=true/' /etc/default/grub
sed -i -E 's/GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet"/GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 nomodeset"/' /etc/default/grub
sed -i 's/#GRUB_DISABLE_OS_PROBER/GRUB_DISABLE_OS_PROBER/' /etc/default/grub

#Generate the GRUB configuration file
grub-mkconfig -o /boot/grub/grub.cfg

#Create a networkd file to get a wired connection
echo [Match] >> /etc/systemd/network/10-ethernet.network
echo Name=en* >> /etc/systemd/network/10-ethernet.network
echo Name=eth* >> /etc/systemd/network/10-ethernet.network
echo  >> /etc/systemd/network/10-ethernet.network
echo [Network] >> /etc/systemd/network/10-ethernet.network
echo DHCP=yes >> /etc/systemd/network/10-ethernet.network
echo IPv6PrivacyExtensions=yes >> /etc/systemd/network/10-ethernet.network
echo  >> /etc/systemd/network/10-ethernet.network
echo [DHCPv4] >> /etc/systemd/network/10-ethernet.network
echo RouteMetric=10 >> /etc/systemd/network/10-ethernet.network
echo  >> /etc/systemd/network/10-ethernet.network
echo [IPv6AcceptRA] >> /etc/systemd/network/10-ethernet.network
echo RouteMetric=10 >> /etc/systemd/network/10-ethernet.network

#Enable the networkd service
systemctl enable systemd-networkd.service

#Install and enable iwd for wireless setup
yes | pacman -S iwd
systemctl enable iwd.service

#Create a netword file for use with Wireless
echo [Match] >> /etc/systemd/network/20-wifi.network
echo Name=wl* >> /etc/systemd/network/20-wifi.network
echo  >> /etc/systemd/network/20-wifi.network
echo [Network] >> /etc/systemd/network/20-wifi.network
echo DHCP=yes >> /etc/systemd/network/20-wifi.network
echo IPv6PrivacyExtensions=yes >> /etc/systemd/network/20-wifi.network
echo  >> /etc/systemd/network/20-wifi.network
echo [DHCPv4] >> /etc/systemd/network/20-wifi.network
echo RouteMetric=20 >> /etc/systemd/network/20-wifi.network
echo  >> /etc/systemd/network/20-wifi.network
echo [IPv6AcceptRA] >> /etc/systemd/network/20-wifi.network
echo RouteMetric=20 >> /etc/systemd/network/20-wifi.network

#Enable the networkd wireless service
systemctl enable systemd-resolved.service

#Enable timesync service
systemctl enable systemd-timesyncd.service

#Create a new user
useradd -m "$USER"
printf "%s\n%s" "$USER_PASSWORD" "$USER_PASSWORD" | passwd "$USER"

#groupadd wheel for user
usermod -aG wheel "$USER"

#Install sudo
yes | pacman -S sudo

#Enable sudo for the sudo group
echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers.d/10-sudo

#Create sudo group and add user to the group
groupadd sudo
usermod -aG sudo "$USER"

#Install polkit
yes | pacman -S polkit

#Decrease writes to the USB by using the noatime option in fstab
sed -i 's/relatime/noatime/' /etc/fstab

#Prevent the systemd journal from writing to the USB it will use RAM
mkdir -p /etc/systemd/journal.conf.d
echo [Journal] >> /etc/systemd/journal.conf.d/10-volatile.conf
echo Storage=volatile >> /etc/systemd/journal.conf.d/10-volatile.conf
echo SystemMaxUse=16M >> /etc/systemd/journal.conf.d/10-volatile.conf
echo RuntimeMaxUse=32M >> /etc/systemd/journal.conf.d/10-volatile.conf

#interface names. Ensure names are eth0 and wlan0
ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

#modify pacman.conf for color and ILoveCandy
sed -i 's/#Color/Color/' /etc/pacman.conf
sed -i 's/#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf
sed -i '35 i ILoveCandy' /etc/pacman.conf
EOF


chmod 0755 ${MNT_DIR}/install.sh
arch-chroot ${MNT_DIR} /install.sh

#NOTE: This command must be run outside of the chroot
ln -sf /run/systemd/resolve/stub-resolv.conf /mnt/usb/etc/resolv.conf

Online

#14 2023-06-21 14:36:05

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,561
Website

Re: My installation script

Sed can accept multiple commands at once.  For example, your pacman.conf edits could be:

#modify pacman.conf for color and ILoveCandy
sed -i '/Color/s/^#//;/ParallelDownloads/s/^#//;35 i ILoveCandy' /etc/pacman.conf

But note that using the "magic number" 35 could be error prone if / when the default pacman.conf changes.  It'd be better to anchor that to one of the other lines in the same section:

sed -i '/Color/s/^#//;/ParallelDownloads/{s/^#//;i ILoveCandy;}' /etc/pacman.conf

Also note that there are several places where you could benefit from additional here-documents for much better readability.  For example:

#Create a netword file for use with Wireless
cat << EOF_NETWORK > /etc/systemd/network/20-wifi.network
[match]
Name=wl*

[Network]
DHCP=yes
IPv6PrivacyExtensions=yes

[DHCPv4]
RouteMetric=20

[IPv6AcceptRA]
RouteMetric=20
EOF_NETWORK

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#15 2023-06-22 00:33:10

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

I guess I need to learn more about EOF
Trying to modify my script with your EOF_NETWORK code stops iwctl from working properly.

I also have some error in dealing with locale that I have searched for an answer for but can't find.
I see these errors when the script is running.

locale: Cannot set LC_CTYPE to default locale: No such file or directory
This is repeated for  LC_MESSAGES and LC_ALL

Online

#16 2023-06-22 00:42:37

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,561
Website

Re: My installation script

The locale error makes sense - you called 'locale' before setting up the locales.  Why is that command there in the first place, it doesn't actually do anything?

For the iwctl issues, check errors - and check the content of the generated 20-network file.

Last edited by Trilby (2023-06-22 00:43:20)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#17 2023-06-22 01:04:40

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

Ah the locale was suppose to be a #locale

I didn’t see errors with the EOF_NETWORK

I’ll do some checking.

Found the EOF issue

Lowercase
[match]
Should have been
[Match]

All issues related to typos
I feel so foolish .

Last edited by MAYBL8 (2023-06-22 01:38:26)

Online

#18 2023-06-22 13:00:54

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

My next tasks for this script would be to have iwctl working on startup with my wireless already set.
      I accomplished this with creating a script inside the install script to run after arch is installed. (wifi.sh)

I would also like numlock key on when started.
     I added code in the script to add this line in the .bash_profile when my user is created.
       setleds -D +num

One more feature I would like to install is yay so it would be there when I start Arch.

Right now all of this is beyond my knowledge.

I tried passing the iwctl command during the install but it stalls out running giving it all the variables it needs .
Numlock looks like some kind of AUR package needs to run after reading the Arck Wiki

yay looks like i need to install base-devel and git which I can but I was trying to make this install as small as possible.

Maybe these items should just be done after initial usb is created.

Thanks for your input.

Just thought of something else.

To have my other installs on the hard drive show up in grub menu.
I probably need some additional packages installed for os-prober to see them.
    I did this by again creating a grubmenu.sh script with the OS's I new I had on my Laptop.
    Manjaro has evidently re engineered os-prober to accomplish this in their distro.

Last edited by MAYBL8 (2023-06-23 12:29:31)

Online

#19 2023-06-26 01:55:20

MAYBL8
Member
Registered: 2022-01-14
Posts: 212

Re: My installation script

Here is my latest version
Version 1.00.01

A couple of things
At the end of the script I started to add some things to do after the install.

One thing I have discovered in the use of this script it is vary usable  on a usb 3.0
I wrote this to be use in just a cli.
If you are going to install a GUI DE and or WM you need to take the nomodeset setting out or it won't boot to the
Graphical environment.

It is ready to install any packages you want after booting to it.

#!/usr/bin/env bash

#v.1.00.01

set -eu

drive=sda
efi=sda2
main=sda3
MNT_DIR="/mnt/usb"
TIMEZONE="/usr/share/zoneinfo/America/New_York"
LOCALE="en_US.UTF-8 UTF-8"
LANG1=LANG="en_US.UTF-8"
HOSTNAME="arch-linux"
ROOT_PASSWORD="root"
USER="demo"
USER_PASSWORD="demo"


# Create a 10M BIOS partition, a 500M EFI partition, and a Linux partition with the remaining space:
sgdisk --zap-all /dev/$drive
sudo sgdisk -o -n 1:0:+10M -t 1:EF02 -n 2:0:+500M -t 2:EF00 -n 3:0:0 -t 3:8300 /dev/$drive
#sudo sgdisk -o -n 1:0:+10M -t 1:EF02 -n 2:0:+500M -t 2:EF00 -n 3:0:+8096M -t 3:8300 /dev/$drive

#Do not format the /dev/sdX1 block. This is the BIOS/MBR parition.
#Format the 500MB EFI system partition with a FAT32 filesystem:
sudo mkfs.fat -F32 /dev/$efi

#Format the Linux partition with an ext4 filesystem:
yes y | sudo mkfs.ext4 /dev/$main

#mount
#Mount the ext4 formatted partition as the root filesystem:
sudo mkdir -p /mnt/usb
sudo mount /dev/$main /mnt/usb

#Mount the FAT32 formatted EFI partition to /boot:
sudo mkdir /mnt/usb/boot
sudo mount /dev/$efi /mnt/usb/boot

#pacstrap
#Download and install the Arch Linux base packages:
sudo pacstrap /mnt/usb linux linux-firmware base nano

#fstab
sudo genfstab -U /mnt/usb > /mnt/usb/etc/fstab

#run rest of install from a arch-chroot script

cat << EOF > "${MNT_DIR}"/install.sh

#locale
ln -s -f "$TIMEZONE" /etc/localtime

#Generate /etc/adjtime
hwclock --systohc

#Uncomment the desired Language
sed -i "s/#$LOCALE/$LOCALE/" /etc/locale.gen

#Generate the locale information
locale-gen

#Set the LANG variable in /etc/locale.conf
echo -e "$LANG1" >> /etc/locale.conf

#Create a /etc/hostname with the desired hostname
echo "$HOSTNAME" >> /etc/hostname

#Put the following in the /etc/hosts file
echo "127.0.0.1 localhost" >> /etc/hosts
echo "::1  localhost" >> /etc/hosts
echo 127.0.1.1 "$HOSTNAME".localdomain "$HOSTNAME" >> /etc/hosts

#Set the root password
printf "%s\n%s" "$ROOT_PASSWORD" "$ROOT_PASSWORD" | passwd

#Install grub and efibootmgr
yes | pacman -S grub efibootmgr

#Install grub for both BIOS and UEFI booting
grub-install --target=i386-pc --recheck /dev/$drive
grub-install --target=x86_64-efi --efi-directory /boot --recheck --removable

#Change some settings in the /etc/default/grub file
sed -i 's/GRUB_GFXMODE=auto/GRUB_GFXMODE=800x600/' /etc/default/grub
sed -i 's/#GRUB_SAVEDEFAULT=true/GRUB_SAVEDEFAULT=true/' /etc/default/grub
sed -i -E 's/GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet"/GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 nomodeset"/' /etc/default/grub
sed -i 's/#GRUB_DISABLE_OS_PROBER/GRUB_DISABLE_OS_PROBER/' /etc/default/grub

#install os-prober
yes | pacman -S os-prober

#install ntfs-3g and fuse so grub config can find all partitions when building grub menu
yes | pacman -S ntfs-3g

#Generate the GRUB configuration file
grub-mkconfig -o /boot/grub/grub.cfg

#Create a networkd file to get a wired connection
cat << EOF_LANNETWORK > /etc/systemd/network/10-ethernet.network
[Match]
Name=en*
Name=eth*

[Network]
DHCP=yes
IPv6PrivacyExtensions=yes

[DHCPv4]
RouteMetric=10

[IPv6AcceptRA]
RouteMetric=10
EOF_LANNETWORK

#Enable the networkd service
systemctl enable systemd-networkd.service

#Install and enable iwd for wireless setup
yes | pacman -S iwd
systemctl enable iwd.service

#Create a networkd file for use with Wireless
cat << EOF_NETWORK > /etc/systemd/network/20-wifi.network
[Match]
Name=wl*

[Network]
DHCP=yes
IPv6PrivacyExtensions=yes

[DHCPv4]
RouteMetric=20

[IPv6AcceptRA]
RouteMetric=20
EOF_NETWORK

#Enable the networkd wireless service
systemctl enable systemd-resolved.service

#Enable timesync service
systemctl enable systemd-timesyncd.service

#Create a new user
useradd -m "$USER"
printf "%s\n%s" "$USER_PASSWORD" "$USER_PASSWORD" | passwd "$USER"

#groupadd wheel for user
usermod -aG wheel "$USER"

#Add numlock into USER .bash_profile file
echo setleds -D +num >> /home/$USER/.bash_profile

#Install sudo
yes | pacman -S sudo

#Enable sudo for the sudo group
echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers.d/10-sudo

#Create sudo group and add user to the group
groupadd sudo
usermod -aG sudo "$USER"

#Install polkit
yes | pacman -S polkit

#Decrease writes to the USB by using the noatime option in fstab
sed -i 's/relatime/noatime/' /etc/fstab

#Prevent the systemd journal from writing to the USB it will use RAM
mkdir -p /etc/systemd/journal.conf.d
echo [Journal] >> /etc/systemd/journal.conf.d/10-volatile.conf
echo Storage=volatile >> /etc/systemd/journal.conf.d/10-volatile.conf
echo SystemMaxUse=16M >> /etc/systemd/journal.conf.d/10-volatile.conf
echo RuntimeMaxUse=32M >> /etc/systemd/journal.conf.d/10-volatile.conf

#Disable the fallback image generation and remove it from PRESETS
sed -i '/^PRESETS=.*/ s/(.*)/('\'default\'')/' /etc/mkinitcpio.d/*.preset

#Remove the existing fallback image
rm /boot/initramfs-linux-fallback.img

#interface names. Ensure names are eth0 and wlan0
ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

#modify pacman.conf for color and ILoveCandy
sed -i '/Color/s/^#//;/ParallelDownloads/s/^#//;35 i ILoveCandy' /etc/pacman.conf
EOF


chmod 0755 ${MNT_DIR}/install.sh
arch-chroot ${MNT_DIR} /install.sh

#NOTE: This command must be run outside of the chroot
ln -sf /run/systemd/resolve/stub-resolv.conf /mnt/usb/etc/resolv.conf

################ Added items for my own use only #############################
####################################

cat << EOF > "${MNT_DIR}"/wifi.sh
iwctl --passphrase "Linux@Home" station "wlan0" connect "Dans Cloud"

grub-mkconfig -o /boot/grub/grub.cfg


EOF

chmod 0755 ${MNT_DIR}/wifi.sh

My laptop is a 4k high resolution and any Graphic environment starts out with very small text.
I wish there was some way to have it start out in something like 1920x1080 

But that is another subject.

Have fun with the script.

Online

Board footer

Powered by FluxBB