Skip to content

Commit

Permalink
(+) removed drive label dependency + grub update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Politzer Couto committed Sep 28, 2021
1 parent 8351d85 commit f2aa989
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 108 deletions.
35 changes: 19 additions & 16 deletions boot/grub/grub.cfg
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
source /boot/grub/script/autoiso.cfg

if loadfont unicode ; then
insmod gfxmenu
insmod gfxterm
insmod jpeg
insmod png
insmod vbe
insmod vga
set gfxmode=1920x1080,auto
set gfxpayload=text
set theme=/boot/grub/themes/starfield/theme.txt
#set theme=/boot/grub/themes/vimix/theme.txt
#set theme=/boot/grub/themes/tela/theme.txt
terminal_output gfxterm
export theme
insmod gfxmenu
insmod gfxterm
insmod jpeg
insmod png
insmod vbe
insmod vga
set gfxmode=1920x1080,auto
set gfxpayload=text
#set theme=/boot/grub/themes/starfield/theme.txt
set theme=/boot/grub/themes/vimix/theme.txt
#set theme=/boot/grub/themes/tela/theme.txt
terminal_output gfxterm
export theme
fi
scan_isos /boot/iso GIM

menuentry "Scan ISOs" "${prefix}/script/autoiso.cfg" {
set iso_dirs="/boot/iso"
export iso_dirs
configfile "$2"
}
137 changes: 73 additions & 64 deletions boot/grub/script/autoiso.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Sample GRUB script to autodetect operating systems
#
# Copyright (C) 2017 Marcelo Politzer Couto
# Copyright (C) 2021 Marcelo Politzer Couto
# Copyright (C) 2010 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
Expand All @@ -16,118 +14,126 @@
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.

function pathname { regexp -s 2:"$2" '^(\(.*\))?(/.*)$' "$1"; }
function pathname { regexp -s 2:"$2" '^(\(.*\))/*(/.*)$' "$1"; }
function devname { regexp -s "$2" '^(\(.*\)).*$' "$1"; }

function isolinux_iso_entry {
dev="$1"
iso="$2"
label="$3"

realdev="$1"
isopath="$2"
loopdev="$3"

if test -f /boot/isolinux/isolinux.cfg; then
cfg=/boot/isolinux/isolinux.cfg
cfgpath=/boot/isolinux/isolinux.cfg
elif test -f /syslinux/syslinux.cfg; then
cfg=/syslinux/syslinux.cfg
cfgpath=/syslinux/syslinux.cfg
elif test -f /isolinux/isolinux.cfg; then
cfg=/isolinux/isolinux.cfg
cfgpath=/isolinux/isolinux.cfg
elif test -f /boot/x86_64/loader/isolinux.cfg; then
cfg=/boot/x86_64/loader/isolinux.cfg
cfgpath=/boot/x86_64/loader/isolinux.cfg
else
return 1;
fi

echo isolinux based $iso: yes
menuentry "$iso (isolinux)" "$dev" "$iso" "$cfg" "$label" {
set dev="$2"
set iso="$3"
set cfg="$4"
set label="$5"
echo isolinux based $isopath: yes
probe -s label -l $realdev
menuentry "${indent}${isopath} (isolinux)" "$realdev" "$isopath" "$cfgpath" {
set device="$2"
set isopath="$3"
set cfgpath="$4"

loopback loop "${dev}${iso}"
probe -s rootuuid -u $device
loopback loop "${device}${isopath}"
set root=(loop)

# this flag requires a hacked grub!!

# language settings
set linux_extra="$langset"

# arch based
set linux_extra="${linux_extra} img_dev="/dev/disk/by-label/$label" img_loop=$iso earlymodules=loop"
set linux_extra="${linux_extra} img_dev=/dev/disk/by-uuid/$rootuuid img_loop=$isopath earlymodules=loop"

# gentoo based
set linux_extra="${linux_extra} isofrom=$isopath"

# ubuntu based, fedora, opensuse, rosa
set linux_extra="${linux_extra} iso-scan/filename=$isopath"

# antiX based
set linux_extra="${linux_extra} from=all fromiso=$isopath"

# Grml Live Linux
set linux_extra="${linux_extra} findiso=$isopath"

# sysrcd
set linux_extra="${linux_extra} isoloop=$isopath"

# MagOS Linux (UIRD)
set linux_extra="${linux_extra} uird.from=${isopath},/MagOS uird.force scantimeout=3"

# TODO: SUSE based
set linux_extra="${linux_extra} isofrom_device=/dev/disk/by-uuid/$rootuuid isofrom_system=$isopath"

# others?
set linux_extra="${linux_extra} isoboot=$isopath"

export linux_extra
syslinux_configfile $cfg
syslinux_configfile $cfgpath
}
return 0
}

# iso_path is used by the loopback target, do not change!
function loopback_iso_entry {
realdev="$1"
isopath="$2"
loopdev="$3"

if test -f /boot/grub/loopback.cfg; then
cfgpath=/boot/grub/loopback.cfg
elif test -f /grub/loopback.cfg; then
cfgpath=/grub/loopback.cfg
else
return 1;
return 1
fi

echo loopback.cfg $isopath: yes
menuentry "${isopath} (loopback)" "$realdev" "$isopath" "$cfgpath" {
probe -s label -l $realdev
menuentry "${indent}${isopath} (loopback)" "$realdev" "$isopath" "$cfgpath" {
set device="$2"
set iso_path="$3"
set cfg="$4"
set isopath="$3"
set cfgpath="$4"

export iso_path
loopback loop "${device}${iso_path}"
loopback loop "${device}${isopath}"
set root=(loop)
configfile $cfg
loopback -d loop
}
return 0
}

function bsdfamily_iso_entry {
realdev="$1"
isopath="$2"
probe -s rootuuid -u $device
set isopath="$isopath $langset"
export isopath

if test -f /FreeNAS-MANIFEST; then kpath=/boot/kernel/kernel; # FreeNAS
elif test -f /boot/zfsloader; then kpath=/boot/kernel/kernel; # FreeBSD
else return 1; fi

echo bsd-family.cfg $isopath: yes
menuentry "${isopath} (BSD family)" "$realdev" "$isopath" {
set device="$2"
set iso="$3"

export iso
loopback loop "${device}${iso}"
set root=(loop)

echo "This may take a while..."
kfreebsd /boot/kernel/kernel
kfreebsd_module "${device}${iso}" type=mfs_root
set kFreeBSD.vfs.root.mountfrom=cd9660:/dev/md0
configfile $cfgpath
loopback -d loop
}
return 0
}

function scan_isos {
isodirs="$1"
label="$2"

echo "scanning ..."
for dev in (*); do
for dir in $isodirs; do
for file in ${dev}${dir}/*.iso ${dev}${dir}/*.ISO; do
if ! test -f "$file"; then continue; fi

pathname $file isopath
if test -z "$dev" -o -z "$isopath"; then continue; fi

if ! loopback loopdev_scan "$file"; then continue; fi
saved_root=$root
set root=(loopdev_scan)

if loopback_iso_entry $dev $isopath; then true;
elif isolinux_iso_entry $dev $isopath "$label"; then true;
elif bsdfamily_iso_entry $dev $isopath; then true;
if false; then true;
elif loopback_iso_entry $dev $isopath (loopdev_scan); then true;
elif isolinux_iso_entry $dev $isopath (loopdev_scan); then true;
else true; fi

set root=$saved_root
Expand All @@ -138,12 +144,15 @@ function scan_isos {
return 0
}

# XXX Remove later
insmod serial
serial
terminal_output --append serial
# terminal_input --append serial
insmod part_gpt
insmod part_msdos
insmod regexp

langcode="$lang"

insmod regexp
regexp -s langcode '(^..)' "$lang"
langset="lang=${lang} debian-installer/language=${langcode} keyboard-configuration/layoutcode?=${langcode}"
indent=" " #indent for menu entries

scan_isos "$iso_dirs"
newdir_scan_entry
2 changes: 1 addition & 1 deletion grub
Submodule grub updated from 3ffd70 to 710cb5
72 changes: 45 additions & 27 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
![preview with vimix](doc/vimix.png?raw=true "vimix")
![preview with starfield](doc/starfield.png?raw=true "starfield")

If your pendrive is already formated to FAT, you only need to change its label
to GIM and then skip step `1`. To use different name changes to the scripts are
required, more on this later (step `3`).
If your pendrive is already formated to FAT skip to `2`

## 1. Installation Guide (clean disk)

```
export LABEL=<label-of-your-choice>
```

### 1.1 Create a partition table:
```
# fdisk /dev/sdX
Expand All @@ -29,7 +31,7 @@ w # write

### 1.2 Format to FAT
```
# mkfs.fat -n GIM /dev/sdX1
# mkfs.fat -n $LABEL /dev/sdX1
```

## Or with `gparted`
Expand All @@ -40,34 +42,46 @@ gparted /dev/sdX
# Partition -> New -> (configure options) -> Add
Create as: Primary Partition
File System: fat32
Label: GIM
Label: $LABEL
# Apply all operations
# Select partition /dev/sdX1 -> Left click -> Manage Flags -> Enable boot flag
```

## 2. Installation Guide (formated disk)


### 2.1a mount
```
mkdir -p /tmp/GIM
mount /dev/disk/by-label/GIM /tmp/GIM
grub-install --boot-directory=/tmp/GIM/boot /dev/sdX
tar xvf grub-iso-multiboot.tar.gz -C /tmp/GIM
umount /tmp/GIM
mkdir -p /tmp/$LABEL
sudo mount /dev/disk/by-label/$LABEL /tmp/$LABEL
```

## 3. Adjusts
### 2.1b mount (as a regular user)
```
pmount /dev/disk/by-label/$LABEL
# adapt destination to the created folder in /media for the following commands
# mount point will look something like this: /media/disk_by-label_$LABEL
```

### 3.1 I don't want to change the label
### 2.2 install grub & copy release files
```
grub-install --boot-directory=/tmp/$LABEL/boot /dev/sdX
tar xvf grub-iso-multiboot.tar.gz -C /tmp/$LABEL
```

If you didn't change your label to `GIM` you will need to change
`/tmp/GIM/boot/grub/grub.cfg` last line:
### 2.3a unmount
```
umount /tmp/$LABEL
```

```diff
-scan_isos /boot/iso GIM
+scan_isos /boot/iso <label>
### 2.3b unmount
```
pumount /media/disk_by-label_$LABEL
```

### 3.2 I want my GRUB to look like that
## 3. Adjusts

### 3.1 I want my GRUB to look like that

Find a [theme](https://www.gnome-look.org/browse/cat/109/ord/rating/) you would
like to use. The one from the screenshot above is
Expand All @@ -76,26 +90,25 @@ like to use. The one from the screenshot above is
Move the theme contents to the `themes` folder of the instalation, like so:

```
mount /dev/disk/by-label/GIM /tmp/GIM
mount /dev/disk/by-label/$LABEL /tmp/$LABEL
tar xvf Vimix-1080p.tar.xz -C /tmp/
mv /tmp/Vimix-1080p/Vimix /tmp/GIM/boot/grub/themes/vimix
mv /tmp/Vimix-1080p/Vimix /tmp/$LABEL/boot/grub/themes/vimix
```

Double check that you have the `theme.txt` file in the correct place
`/tmp/GIM/boot/grub/themes/vimix/theme.txt`.
`/tmp/$LABEL/boot/grub/themes/vimix/theme.txt`.

As the last step, select the theme in `/tmp/GIM/boot/grub/grub.cfg`:
As the last step, select the theme in `/tmp/$LABEL/boot/grub/grub.cfg`:

```diff
- set theme=/boot/grub/themes/starfield/theme.txt
+ set theme=/boot/grub/themes/vimix/theme.txt
scan_isos /boot/iso GIM
```

release the pendrive.

```
umount /tmp/GIM
umount /tmp/$LABEL
```

## 4. Add isos to /boot/iso/
Expand All @@ -104,11 +117,16 @@ Menu entries will be populated according to the files present during boot.
To add isos via terminal, just copy them over:

```
mount /dev/disk/by-label/GIM /tmp/GIM
cp <my-iso-file>.iso /tmp/GIM/boot/iso/
umount /tmp/GIM
mount /dev/disk/by-label/$LABEL /tmp/$LABEL
cp <my-iso-file>.iso /tmp/$LABEL/boot/iso/
umount /tmp/$LABEL
```

## 5. Contibute

### 5.1 You can contribute by requesting/testing ISOs, and also by making a
donation.

Consider donating:

```
Expand Down

0 comments on commit f2aa989

Please sign in to comment.