Re: Some good bash and bash alias tricks.
Posted: 2021-01-04 11:38
Hey, cool ... all good suggestions so thanks Head_on. Was hoping some folks would improve on the idea. Been advocating that this type of thing would make a good addition to hybrid/live media and finally got around to playing with it myself. Could just be a nice touch to add to live media as part of rescue tool-kit or tool on the ISO. Definitely has tons of room for improvement or expansion ...
Are already polished tools to make reinstalling a borked bootloader easy and/or automagic, adding things to detect or automount an ESP or separate /boot wouldn't be overly difficult ( that trick you/@Head_on posted looks good) and same should be said for dealing with encryption in this mess if the user happens to be one of those nixers who encrypts everything.
For myself, when I modded the ISO, created permanent/predictable mount points on it, so don't need to create /mnt/chroot or use those lines in the chroot.script. Still BIG +1 on why not just use /mnt ... hadn't thought of that ... Though was playing with a couple other refinements of this thing and went ahead and tried them out so want to share findings on it.
The thing about copying resolv.conf from the live session to one of my bare-metal installs crapping things up, decided to go with this to handle it.
Just added that line to the script to make a backup of any resolv.conf file that's on the target partition and rename it resolv.conf.bak. So it'd be easier to restore the thing afterwards ... Also ended up tweaking the cleanup.sh script a bit too, its contents are now as follows ...
Added another dialogue to it, so that the script asks which drive/partition should be unmounted. I was talking about unmount everything cleanly, blahblahblah and forgot to include unmounting the actual target itself. So in the above there, it asks which drive-partition that is, saves what's entered to the variable UNMT and again used the Y/y prompt so a user can confirm it, otherwise again ... the script just exits.
Can see a lot of potentially useful junk that could be integrated into this type of thing but don't have all the needed hardware on hand to test everything, honestly am not the best qualified to sort all of it out either. Plus all this works perfectly as is for me personally, don't want to try too hard in even attempting to make everything imaginable work for every configuration people may have or want. It's a good idea overall, got things working for me, proof of concept. Though again Head_on thanks for the tips and input on this, good stuff.
Are already polished tools to make reinstalling a borked bootloader easy and/or automagic, adding things to detect or automount an ESP or separate /boot wouldn't be overly difficult ( that trick you/@Head_on posted looks good) and same should be said for dealing with encryption in this mess if the user happens to be one of those nixers who encrypts everything.
For myself, when I modded the ISO, created permanent/predictable mount points on it, so don't need to create /mnt/chroot or use those lines in the chroot.script. Still BIG +1 on why not just use /mnt ... hadn't thought of that ... Though was playing with a couple other refinements of this thing and went ahead and tried them out so want to share findings on it.
The thing about copying resolv.conf from the live session to one of my bare-metal installs crapping things up, decided to go with this to handle it.
Code: Select all
sudo cp /mnt/chroot/etc/resolv.conf /mnt/chroot/etc/resolv.conf.bak # Make a backup of targets resolv.conf if present.
sudo cp /etc/resolv.conf /mnt/chroot/etc/ # Live session needs to be online for this to matter but won't hurt anyway.
Code: Select all
#!/bin/bash
sudo umount -l /mnt/chroot/dev/pts
sudo umount -l /mnt/chroot/dev
sudo umount -l /mnt/chroot/proc
sudo umount -l /mnt/chroot/sys
echo "Enter the drive and partition to unmount now ... Check your typing."
read UNMT && echo "preparing to unmount $UNMT"
read -p "Press y to continue. " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo umount /dev/$UNMT
fi
exit 0
Can see a lot of potentially useful junk that could be integrated into this type of thing but don't have all the needed hardware on hand to test everything, honestly am not the best qualified to sort all of it out either. Plus all this works perfectly as is for me personally, don't want to try too hard in even attempting to make everything imaginable work for every configuration people may have or want. It's a good idea overall, got things working for me, proof of concept. Though again Head_on thanks for the tips and input on this, good stuff.