If you have ever installed Arch before, then you may have forgotten to install something the first time through. Rendering your fresh installation useless in a non-boot-able state or perhaps in a less than functional state. We will show you how to get back into your installation right at the arch-chroot stage of the installation to fix these errors. Arch really can be a challenging when you are new. So, why punish yourself continuously installing it after messing up? Possibly getting stuck in a loop that leaves you distribution hopping.
Today we will cover likely issues that will make arch-chroot the way to fix them. Next we will cover procuring and writing to media in case you no longer have your Arch installation media. Next, we will go over booting from media. The next thing we do is mount the partitions to prepare for arch-chroot. Then, we will arch-chroot into the user we are wishing to fix. Finally, we will go over some possible fixes to common mistakes. Now let’s learn how to make a broken system usable again.
So, why would you want to go back to an installation process for installing Arch manually? We will give you three examples today and by the end offer some fixes. It is also worth mentioning that it is worth trying on Arch derivatives provided you know the differences in said derivative.
- Forgotten Grub installation or configuration.
- Broken log in.
- Failed Kernel replacement.
If you have been using Arch long, then you may have already experienced some of these issues. It is straightforward to forget to install a bootloader during installation. Sometimes you want to try a console log in solution, or perhaps you tried changing DMs (Display Manager). Maybe you decided to run the LTS kernel over the regular rolling release kernel. There is no need to reinstall Arch again if you fail at any of these procedures. We can fix many of these things just by gaining arch-chroot.
To get started we will go over how to image a USB for Arch installation media. First we need to navigate to the Arch download page which can be found here using a Linux installation that is in working order. We will then have to make a choice, torrent or ISO direct download. We have covered torrents before, so we will go ahead and do a direct download using wget. Make sure to choose the mirror nearest to you. We will be using one in the United States, in the state of Arizona to be exact.
cd ~/Downloads && wget https://mirror.arizona.edu/archlinux/iso/2022.06.01/archlinux-2022.06.01-x86_64.iso
Now that we have our image we need to image it to a USB. First we have to take some precautions as to not lose any precious data. We will first plug in the USB.
This command should tell us what block devices are connected. Now we can deduce the correct drive to choose for imaging the Arch installation media. This is important as you do not want to overwrite anything like a gaming drive or something of importance. The dd command will obliterate all the data on the drive selected. Now let’s image a USB.
sudo dd if=archlinux-2022.06.01-x86_64.iso of=/dev/sdb bs=64K conv=noerror,sync status=progress
We will need to be root to use this command. Next we are using dd to copy if=archlinux-2022.06.01-x86_64.iso over to of=/dev/sdb. We can do this because we are in the ~/Downloads directory, so we do not need to write the full path from root. Next we are specifying the bit size with bs=64K. Making the bit size 64K. We could do something like 8M if we would like. They use 64K on the Arch wiki, so we will stick to that. Next we are asking for a conversion sync with conv=noerror,sync. Finally, we are asking for the progress with status=progress. Making it more obvious when the imaging will be completed.
Every system is different. My computers may have different boot keys than yours because there are so many brands with their own defaults. So better yet, we will search for some on Google or DuckDuckGo. As it is up to you what search engine you like. We will first need to consider our computer brand and model number. If you have a laptop that may be on top where you can see it if you don’t have stickers covering it. Otherwise, it will be located on the bottom of your laptop. For a PC tower or box it should be located there. We will need to search the terms like this for example.
Lenovo Thinkpad X260 Boot Key
So, the brand is first in your search results. The next we have to add is the model number. Next there is the part that does not change, we are looking for the boot key or combination. Let’s go through the process. We will need to hit Enter on boot giving us a boot options menu. We will then hit F12 to see our boot options menu. Furthermore, we will see all the possible options to boot from. At this point, you will boot into the appropriate installation mode for your system. Legacy or more common UEFI. Then proceed to boot into the installation media as if to install Arch manually for the first time.
Now that we are booted into our installation media we can start a modified arch-chroot procedure. We will be skipping a few steps to get to where we need. We will need to mount the partitions to gain arch-chroot. First we will mount the root partition.
mount /dev/sda2 /mnt
Now we can proceed to mount the boot partition.
mount /dev/sda1 /mnt/boot
You may recognize these steps from a manual installation. Now we have nothing left to do but chroot into our user and fix what we need to.
arch-chroot /mnt /bin/bash
You notice here you can see your command prompt will change to your username.
Now that you are back on your root user we can fix many of the issues we may be having. We can go ahead and install grub and generate the configuration file like this.
pacman -S grub && grub-install /dev/sda && grub-mkconfig -o /boot/grub/grub.cfg
Note that if you’re booting in legacy this should work just fine to fix Grub. If you missed any of the three steps you can run that command separately. If you are not booting legacy, then you will find the commands on the Arch wiki located here. Now if you are messing with your Display Manager or want to make it a console login solution you will have a chance to fix any mistakes by reversing the changes you made or trying something new. You might want to log in as a user to make changes for them only. You can do that like this.
su -- username
This way you can do changes as you replace “username” with. You will have the option to boot back in with the arch-chroot and try again if anything goes wrong. Which brings us to kernels. We have a few choices of kernel when installing Arch. Most of us probably use the rolling release kernel. We can choose from hardened, LTS, zen, standard. It is difficult to install a new kernel. It can leave you with a non-boot-able system. So let’s go over it.
sudo pacman -S linux linux-headers
sudo pacman -S linux-lts linux-lts-headers
sudo pacman -S linux-zen linux-zen-headers
sudo pacman -S linux-hardened linux-hardened-headers
To ensure that the kernel you select will be available next boot you can regenerate your Grub like this.
sudo grub-mkconfig -o /boot/grub/grub.cfg
This should give you the option to boot into any kernels you install. Rescuing your Arch installation. Now to exit all, you need to do is this.
That got us out of our user back to just regular arch-chroot on the root user of the machine we are rescuing. Now let’s do that again.
Now we can restart back to a working system if all goes right.
shutdown -r now
So, the next time you install Arch and something is just not working. You can go through what you did wrong and fix it in most cases. Troubleshooting does not always work out, but you stand to gain so much knowledge by not backing down and fixing your system. Thanks for reading.
This post first appeared on Linuxman Tech, please read the originial post: here