Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
leleliu008 committed Nov 12, 2019
1 parent 7823788 commit 87aa010
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 23 deletions.
70 changes: 52 additions & 18 deletions gentoo/genfstab
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ declare -A pseudofs_types=([anon_inodefs]=1
[bdev]=1
[binfmt_misc]=1
[cgroup]=1
[cgroup2]=1
[configfs]=1
[cpuset]=1
[debugfs]=1
Expand Down Expand Up @@ -54,6 +53,52 @@ msg() { out "==>" "$@"; }
msg2() { out " ->" "$@";}
die() { error "$@"; exit 1; }

ignore_error() {
"$@" 2>/dev/null
return 0
}

in_array() {
local i
for i in "${@:2}"; do
[[ $1 = "$i" ]] && return 0
done
return 1
}

chroot_add_mount() {
mount "$@" && CHROOT_ACTIVE_MOUNTS=("$2" "${CHROOT_ACTIVE_MOUNTS[@]}")
}

chroot_maybe_add_mount() {
local cond=$1; shift
if eval "$cond"; then
chroot_add_mount "$@"
fi
}

chroot_setup() {
CHROOT_ACTIVE_MOUNTS=()
[[ $(trap -p EXIT) ]] && die '(BUG): attempting to overwrite existing EXIT trap'
trap 'chroot_teardown' EXIT

chroot_maybe_add_mount "! mountpoint -q '$1'" "$1" "$1" --bind &&
chroot_add_mount proc "$1/proc" -t proc -o nosuid,noexec,nodev &&
chroot_add_mount sys "$1/sys" -t sysfs -o nosuid,noexec,nodev,ro &&
ignore_error chroot_maybe_add_mount "[[ -d '$1/sys/firmware/efi/efivars' ]]" \
efivarfs "$1/sys/firmware/efi/efivars" -t efivarfs -o nosuid,noexec,nodev &&
chroot_add_mount udev "$1/dev" -t devtmpfs -o mode=0755,nosuid &&
chroot_add_mount devpts "$1/dev/pts" -t devpts -o mode=0620,gid=5,nosuid,noexec &&
chroot_add_mount shm "$1/dev/shm" -t tmpfs -o mode=1777,nosuid,nodev &&
chroot_add_mount run "$1/run" -t tmpfs -o nosuid,nodev,mode=0755 &&
chroot_add_mount tmp "$1/tmp" -t tmpfs -o mode=1777,strictatime,nodev,nosuid
}

chroot_teardown() {
umount "${CHROOT_ACTIVE_MOUNTS[@]}"
unset CHROOT_ACTIVE_MOUNTS
}

try_cast() (
_=$(( $1#$2 ))
) 2>/dev/null
Expand All @@ -70,7 +115,8 @@ valid_number_of_base() {

mangle() {
local i= chr= out=
local {a..f}= {A..F}=

unset {a..f} {A..F}

for (( i = 0; i < ${#1}; i++ )); do
chr=${1:i:1}
Expand All @@ -88,7 +134,8 @@ mangle() {

unmangle() {
local i= chr= out= len=$(( ${#1} - 4 ))
local {a..f}= {A..F}=

unset {a..f} {A..F}

for (( i = 0; i < len; i++ )); do
chr=${1:i:1}
Expand Down Expand Up @@ -257,13 +304,6 @@ optstring_apply_quirks() {
# one might install Arch from a Fedora environment), so let's remove it.
optstring_remove_option "$varname" seclabel

# Prune 'relatime' option for any pseudofs. This seems to be a rampant
# default which the kernel often exports even if the underlying filesystem
# doesn't support it. Example: https://bugs.archlinux.org/task/54554.
if awk -v fstype="$fstype" '$1 == fstype { exit 1 }' /proc/filesystems; then
optstring_remove_option "$varname" relatime
fi

case $fstype in
f2fs)
# These are Kconfig options for f2fs. Kernels supporting the options will
Expand All @@ -286,10 +326,9 @@ usage() {
usage: ${0##*/} [options] root
Options:
-f FILTER Restrict output to mountpoints matching the prefix FILTER
-L Use labels for source identifiers (shortcut for -t LABEL)
-p Exclude pseudofs mounts (default behavior)
-P Include pseudofs mounts
-P Include printing mounts
-t TAG Use TAG for source identifiers
-U Use UUIDs for source identifiers (shortcut for -t UUID)
Expand All @@ -306,17 +345,14 @@ if [[ -z $1 || $1 = @(-h|--help) ]]; then
exit $(( $# ? 0 : 1 ))
fi

while getopts ':f:LPpt:U' flag; do
while getopts ':LPpt:U' flag; do
case $flag in
L)
bytag=LABEL
;;
U)
bytag=UUID
;;
f)
prefixfilter=$OPTARG
;;
P)
pseudofs=1
;;
Expand Down Expand Up @@ -350,8 +386,6 @@ findmnt -Recvruno SOURCE,TARGET,FSTYPE,OPTIONS,FSROOT "$root" |
continue
fi

[[ $target = "$prefixfilter"* ]] || continue

# default 5th and 6th columns
dump=0 pass=2

Expand Down
11 changes: 6 additions & 5 deletions gentoo/install-in-chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ genLocales() {
env-update && . /etc/profile
}

##step24
#step24
configfstab() {
./genfstab -U >> /mnt/etc/fstab
./genfstab -U >> /etc/fstab
}

#step24
Expand All @@ -80,16 +80,17 @@ downloadLinuxKernelSources() {

#step25
compileLinuxKernelSources() {
cd /usr/src/linux || exit
[ -d /usr/src/linux ] || error "sys-kernel/gentoo-sources not installed"
#cd /usr/src/linux
genkernel all
}

#step26
configHostname() {
prompt "please set hostname:"
read -r hostname
sed -i "s/127.0.0.1\slocalhost/127.0.0.1\\tlocalhost ${hostname}/g" etc/hosts
sed -i "s@hostname=\"localhost\"@hostname=\"${hostname}\"@g" etc/conf.d/hostname
sed -i "s/127.0.0.1\slocalhost/127.0.0.1\\tlocalhost ${hostname}/g" /etc/hosts
sed -i "s@hostname=\"localhost\"@hostname=\"${hostname}\"@g" /etc/conf.d/hostname
}

#step27
Expand Down

0 comments on commit 87aa010

Please sign in to comment.