Optimized chroot procedures

This commit is contained in:
Kevin Veen-Birkenbach 2020-05-21 19:22:14 +02:00
parent 7fb733a0a8
commit 49f5bddbea
4 changed files with 32 additions and 32 deletions

View File

@ -84,15 +84,15 @@ To pase the configuration to the program use this syntax:
```bash ```bash
( (
echo "$USER" # | The username echo "$USER" # | The username
echo "sdX" # | The device echo "mmcblk1" # | The device
echo "64_bit" # | The architecture type; arm or 64_bit echo "arm" # | The architecture type; arm or 64_bit
echo "manjaro" # | The operation system echo "arch" # | The operation system
echo "gnome" # | The version echo "3" # | The version
#echo "n" # ├── If arch: Should a encrypted setup be used? (y/n) #echo "n" # ├── If arch: Should a encrypted setup be used? (y/n)
echo "n" # | Should the image download be forced?(y/n) echo "n" # | Should the image download be forced?(y/n)
echo "y" # | Should the image be transfered to $device_path?(y/n) echo "n" # | Should the image be transfered to $device_path?(y/n)
echo "n" # ├── Overwrite device before copying? (y/n) echo "n" # ├── Overwrite device before copying? (y/n)
echo "n" # | Should the ssh-key be copied to the image?(y/N) echo "n" # | Should the password be changed?(y/N)
#echo "test12345" # ├── The user password_1 #echo "test12345" # ├── The user password_1
#echo "test12345" # ├── The user password_2 #echo "test12345" # ├── The user password_2
echo "n" # | Should the ssh-key be copied to the image?(y/N) echo "n" # | Should the ssh-key be copied to the image?(y/N)

View File

@ -50,7 +50,7 @@ mount_partitions(){
error error
} }
mount_binds(){ mount_chroot_binds(){
info "Mount chroot environments..." && info "Mount chroot environments..." &&
chroot_sys_mount_path="$root_mount_path""sys/" && chroot_sys_mount_path="$root_mount_path""sys/" &&
chroot_proc_mount_path="$root_mount_path""proc/" && chroot_proc_mount_path="$root_mount_path""proc/" &&
@ -63,3 +63,15 @@ mount_binds(){
mount --bind /dev/pts "$chroot_dev_pts_mount_path" || mount --bind /dev/pts "$chroot_dev_pts_mount_path" ||
error error
} }
copy_qemu(){
info "Copy qemu binary..." &&
cp -v /usr/bin/qemu-arm-static "$root_mount_path""usr/bin/" ||
error
}
copy_resolve_conf(){
info "Copy resolve.conf..." &&
cp -v /etc/resolv.conf "$root_mount_path""etc/" ||
warning "Failed. Propably there is no internet connection available."
}

View File

@ -16,32 +16,16 @@ set_partition_paths
mount_partitions mount_partitions
mount_binds mount_chroot_binds
info "ld.so.preload fix" && copy_qemu
sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" ||
warning "Failed."
info "Copy qemu binary..." && copy_resolve_conf
cp -v /usr/bin/qemu-arm-static "$root_mount_path""usr/bin/" ||
error
info "Copy resolve.conf..." info "Bash shell starts..." &&
cp -v /etc/resolv.conf "$root_mount_path""etc/" &&
warning "Failed. Propably there is no internet connection available."
info "You will be transferred to the bash shell now." &&
info "Issue 'exit' when you are done." &&
info "Issue 'su pi' if you need to work as the user pi." &&
info "chroot to raspbian" &&
chroot "$root_mount_path" /bin/bash || chroot "$root_mount_path" /bin/bash ||
error error
info "Clean up" &&
info "revert ld.so.preload fix" &&
sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload" ||
warning "Failed."
info "unmount everything" && info "unmount everything" &&
umount "$root_mount_path"/{dev/pts,dev,sys,proc,boot,} || umount "$root_mount_path"/{dev/pts,dev,sys,proc,boot,} ||
error error

View File

@ -10,7 +10,6 @@ info "Setupscript for images started..."
info "Define functions..." info "Define functions..."
destructor(){ destructor(){
info "Cleaning up..." info "Cleaning up..."
sed -i 's/^#CHROOT //g' "$root_mount_path""etc/ld.so.preload" || warning "sed failed."
umount -v "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!" umount -v "$chroot_dev_pts_mount_path" || warning "Umounting $chroot_dev_pts_mount_path failed!"
umount -v "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!" umount -v "$chroot_dev_mount_path" || warning "Umounting $chroot_dev_mount_path failed!"
umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!" umount -v "$chroot_proc_mount_path" || warning "Umounting $chroot_proc_mount_path failed!"
@ -110,9 +109,12 @@ case "$os" in
"1") "1")
imagename="ArchLinuxARM-rpi-latest.tar.gz" imagename="ArchLinuxARM-rpi-latest.tar.gz"
;; ;;
"2" | "3") "2")
imagename="ArchLinuxARM-rpi-2-latest.tar.gz" imagename="ArchLinuxARM-rpi-2-latest.tar.gz"
;; ;;
"3")
imagename="ArchLinuxARM-rpi-3-latest.tar.gz"
;;
"4") "4")
imagename="ArchLinuxARM-rpi-4-latest.tar.gz" imagename="ArchLinuxARM-rpi-4-latest.tar.gz"
;; ;;
@ -314,12 +316,14 @@ if [ "$copy_ssh_key" == "y" ]
else else
info "Skipped SSH-key copying.." info "Skipped SSH-key copying.."
fi fi
info "Start chroot procedures..." info "Start chroot procedures..."
mount_binds mount_chroot_binds
sed -i 's/^/#CHROOT /g' "$root_mount_path""etc/ld.so.preload" || warning "sed failed." copy_qemu
cp -v /usr/bin/qemu-arm-static "$root_mount_path""/usr/bin/" || error "Copy qemu-arm-static failed. The following packages are neccessary: qemu qemu-user-static binfmt-support."
copy_resolve_conf
question "Should the image password of the standart user \"$target_username\" be changed?(y/N)" && read -r change_password question "Should the image password of the standart user \"$target_username\" be changed?(y/N)" && read -r change_password
if [ "$change_password" == "y" ] if [ "$change_password" == "y" ]