So my linux install is broken….. what to try first
Hey all.
Have not written anything in a while and needed to write some stuff about chrooting back into a borked install.
For this article, lets assume that you will be booting from a live distro of some sort and that you need to chroot in to test and fix.
First, lets boot from the live disk. Do not install. Just boot.
Once booted, lets pull up a terminal and run “fdisk -l” to see what the disk path is to what we want to fix like so :
% sudo fdisk -l
Disk /dev/sda: 113 GiB, 121332826112 bytes, 236978176 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: C80CC162-275E-4E4A-9EF0
Device Start End Sectors Size Type
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 9242623 8192000 3.9G Linux swap
/dev/sda3 9242624 236976127 227733504 108.6G Linux filesystem
From this we can see that the path is “/dev/sdaX” to our disk.
So lets now create a mountpoint called linux:
% sudo mkdir /mnt/linux
and now, lets mount boot and the filesystem:
% sudo mount /dev/sda3 /mnt/linux
% sudo mount /dev/sda1 /mnt/linux/boot
Now we need to mount the proc, sys, and dev systems:
% sudo mount -t proc none /mnt/linux/proc
% sudo mount -o bind /sys /mnt/linux/sys
% sudo mount -o bind /dev /mnt/linux/dev
With everything mounted we can not chroot in like so:
% sudo chroot /mnt/linux /bin/bash
% source /etc/profile
And Voila… you can now access you machine.
Leave a Reply