Quantcast
Channel: Linux on the mainframe » Daniel Schwarzentruber
Viewing all articles
Browse latest Browse all 19

Repairing Linux – edit files or reinstall grub (x86)

$
0
0

 Even if you're working with Linux it could happen that a system doesn't come up again. In the most cases the problem is between the monitor and the keyboard - the user itself....... Baffle.

 Let's take an example. An user is encrypting harddisks and usbsticks using LUKS (please see Good LUKS 1 and Good LUKS 2). Within the /etc/fstab entry he's working with the device names instead of the UUIDs. Usually the system wouldn't come up because the device names are not assigned in the right order. The error message could look like in the following screenshot:

Don't panic! In this case you could login as root with the appropriate password. But - you're in a read-only mode. First we've to change in a writeable mode and then modify the /etc/fstab file . To change into the writeable mode we got two possibilities. The fastest is use the mount command and to modify the /etc/fstab file immediately.

mount -o remount,rw

Sometimes it is necessary to add the option -n (--no-mtab) for example when /etc is on a read-only filesystem.

mount -n -o remount,rw

The other way is to boot up another Linux client and access the "damaged" instance (in this example I'm using KNOPPIX which is beeing installed on a 8 GB USB stick). The advantage is that you could use a lot of repair tools such as gparted, fdisk, mc....

By the way - it's recommended to determine some options at the bootmenu of KNOPPIX. Specify the appropriate values for example: knoppix64 (64 Bit mode), lang=ch (language Swiss German) and desktop=lxde (choose your preferred desktop environment). Once we're up with our KNOPPIX we open a terminal and request some information.

root@Microknoppix:/# fdisk -l |grep dev
Disk /dev/mapper/udisks-luks-uuid-88136405-0b03-4d75-ad39-483a1f46736b-uid1000 doesn't contain a valid partition table
Disk /dev/sda: 320.1 GB, 320072933376 bytes
/dev/sda1 * 2048 1050623 524288 83 Linux
/dev/sda2 1050624 625141759 312045568 83 Linux
Disk /dev/sdb: 120.0 GB, 120034123776 bytes
/dev/sdb1 2048 234441647 117219800 83 Linux
Disk /dev/sdc: 8019 MB, 8019509248 bytes
/dev/sdc1 * 1 8728979 4364489+ c W95 FAT32 (LBA)
/dev/sdc2 8728980 15650907 3460964 83 Linux
Disk /dev/sdd: 2004 MB, 2004877312 bytes
/dev/sdd1 62 3913191 1956565 83 Linux
Disk /dev/mapper/udisks-luks-uuid-88136405-0b03-4d75-ad39-483a1f46736b-uid1000: 2001 MB, 2001425408 bytes

As we know the root directory '/` is on the encrpyted device sda2. Get the UUID value of sda2.

root@Microknoppix:/# cryptsetup luksUUID /dev/sda2
708aa87a-5fa2-457e-9ddf-91a91b34598c

Now, we're able to open the encrypted disk.

root@Microknoppix:/# cryptsetup luksOpen /dev/sda2 708aa87a-5fa2-457e-9ddf-91a91b34598c
Geben Sie den Passsatz für /dev/sda2 ein:

To get detailed information then it's good idea to use dmsetup.

root@Microknoppix:/# dmsetup info 708aa87a-5fa2-457e-9ddf-91a91b34598c
Name: 708aa87a-5fa2-457e-9ddf-91a91b34598c
State: ACTIVE
Read Ahead: 256
Tables present: LIVE
Open count: 0
Event number: 0
Major, minor: 252, 2
Number of targets: 1
UUID: CRYPT-LUKS1-708aa87a5fa2457e9ddf91a91b34598c-708aa87a-5fa2-457e-9ddf-91a91b34598c

Are there some volume groups and which ones?

root@Microknoppix:/# vgscan
Reading all physical volumes. This may take a while...
Found volume group "fedora" using metadata type lvm2

Yes, we got one named 'fedora'. Activate the volume group and get the logical volumes.

root@Microknoppix:/# vgchange -a y fedora
3 logical volume(s) in volume group "fedora" now active

root@Microknoppix:/# lvscan
ACTIVE '/dev/fedora/home' [215.55 GiB] inherit
ACTIVE '/dev/fedora/root' [78.12 GiB] inherit
ACTIVE '/dev/fedora/swap' [3.91 GiB] inherit

As next step we've to mount some important directories - at minimum /root, /boot, /dev, /sys and /proc. On KNOPPIX '/mnt' is empty - so mount them into '/mnt'.

root@Microknoppix:/# mount /dev/fedora/root /mnt
root@Microknoppix:/# mount /dev/sda1 /mnt/boot/
root@Microknoppix:/# mount --bind /dev /mnt/dev
root@Microknoppix:/# mount --bind /sys /mnt/sys
root@Microknoppix:/# mount --bind /proc /mnt/proc

After the successful mount, give back the 'damaged' instance to the root - changing the root into /mnt:

root@Microknoppix:/# chroot /mnt /bin/bash

Now you're back and could modify your files or install grub again. After done all modifications leave the chroot mode entering 'exit', umount the appropriate mountpoints and reboot the whole system.

Additonal topic: Re-install grub

It may be necessary to re-install grub. 

[root@Microknoppix /]# grub2-install /dev/sda
installation beendet. Keine Fehler aufgetreten.

Usually you've to make an update typing 'update-grub'.

Within Fedora we've to use the command grub2-mkconfig:

[root@Microknoppix default]# grub2-mkconfig -o /boot/grub2/grub.cfg
grub.cfg wird erstellt …
Thema gefunden: /boot/grub2/themes/system/theme.txt
Linux-Abbild gefunden: /boot/vmlinuz-3.8.4-202.fc18.x86_64
initrd-Abbild gefunden: /boot/initramfs-3.8.4-202.fc18.x86_64.img
Linux-Abbild gefunden: /boot/vmlinuz-3.6.10-4.fc18.x86_64
initrd-Abbild gefunden: /boot/initramfs-3.6.10-4.fc18.x86_64.img
Found linux image: /boot/vmlinuz-3.8.4-202.fc18.x86_64
Found initrd image: /boot/initramfs-3.8.4-202.fc18.x86_64.img
Found linux image: /boot/vmlinuz-3.6.10-4.fc18.x86_64
Found initrd image: /boot/initramfs-3.6.10-4.fc18.x86_64.img
erledigt

The post Repairing Linux – edit files or reinstall grub (x86) appeared first on Linux on the mainframe.


Viewing all articles
Browse latest Browse all 19

Latest Images

Trending Articles





Latest Images