Skip to content

Instantly share code, notes, and snippets.

@MahefaAbel
Last active February 6, 2023 11:52
Show Gist options
  • Save MahefaAbel/5e74241d64f5f2f4917311379cef632c to your computer and use it in GitHub Desktop.
Save MahefaAbel/5e74241d64f5f2f4917311379cef632c to your computer and use it in GitHub Desktop.
Chroot Predator + Bootable manipulation Grub + Graphic Driver

Bootable manipulation & Graphic Driver

mount /dev/sdb5 /mnt
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /boot /mnt/boot
mount -t proc /proc /mnt/proc
mount -t sysfs /sys /mnt/sys
for dir in proc dev sys etc bin sbin var usr lib lib64 tmp; do
# mkdir /mnt/$dir && \
mount --bind /$dir /mnt/$dir
done
chroot /mnt /bin/bash
@MahefaAbel
Copy link
Author

exit
umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount /mnt

@MahefaAbel
Copy link
Author

MahefaAbel commented May 7, 2022

mkdir -p /mnt/boot/efi
mount /dev/sda2 /mnt/boot/efi
chroot /mnt /bin/bash
grub-install --boot-directory=/mnt/boot --bootloader-id=ubuntu  --target=x86_64-efi --efi-directory=/mnt/boot/efi /dev/sda
grub-install --boot-directory=/boot --bootloader-id=ubuntu  --target=x86_64-efi --efi-directory=/boot/efi /dev/sda

grub-install /dev/sda

update-grub2 /dev/sda

@MahefaAbel
Copy link
Author

MahefaAbel commented Oct 22, 2022

├── Boot
│   ├── bootx64.efi
│   ├── fbx64.efi
│   └── mmx64.efi
├── Microsoft
│   ├── Boot
│   │   ├── BCD
│   │   ├── BCD.LOG
│   │   ├── BCD.LOG1
│   │   ├── BCD.LOG2
│   │   ├── bootmgfw.efi
│   │   ├── bootmgfw.efi.backup20230205-win11
│   │   ├── bootmgfw.efi.backup20230205-win11-duplicated-for-security
│   │   ├── bootmgr.efi
│   │   ├── BOOTSTAT.DAT
│   │   ├── boot.stl
│   └── Recovery
│       ├── BCD
│       ├── BCD.LOG
│       ├── BCD.LOG1
│       └── BCD.LOG2
└── ubuntu
    ├── BOOTX64.CSV
    ├── grub.cfg
    ├── grubx64.efi
    ├── mmx64.efi
    └── shimx64.efi

@MahefaAbel
Copy link
Author

MahefaAbel commented Oct 22, 2022

cd /boot/efi/EFI
cp Microsoft/Boot/bootmgfw.efi Microsoft/Boot/bootmgfw.efi.backup20220618
cp ubuntu/grubx64.efi Microsoft/Boot/bootmgfw.efi

cd /boot/efi/EFI/Microsoft/Boot
ls -lh bootmgfw.efi*

@MahefaAbel
Copy link
Author

grub-install: error: failed to get canonical path of /cow'.`

dd if=/dev/zero bs=1M count=1 of=cowfile
mkfs -t vfat cowfile
mv cowfile /cow

@MahefaAbel
Copy link
Author

grub-mkdevicemap

@MahefaAbel
Copy link
Author

nano /etc/default/grub

#GRUB_DISABLE_OS_PROBER=true
#GRUB_OS_PROBER_SKIP_LIST="69D5-AA8F 2022-10-20-07-22-49-00 a9694891-aa3f-477b-ab3b-77efbbb2b778 32e"

@MahefaAbel
Copy link
Author

MahefaAbel commented Feb 6, 2023

nano /etc/grub.d/40_custom

menuentry 'Windows 11' {
    search --fs-uuid --no-floppy --set=root A60F-5FE8
    chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi.backup20230205-win11
}
fdisk -l | grep EFI
blkid /dev/sda2

# EFI partition UUID  => A60F-5FE8
update-grub
nano /boot/grub/grub.cfg

@MahefaAbel
Copy link
Author

MahefaAbel commented Feb 6, 2023

fdisk -l

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   1085439   1083392   529M Windows recovery environment
/dev/sda2  1085440   1290239    204800   100M EFI System
/dev/sda3  1290240   1323007     32768    16M Microsoft reserved
/dev/sda4  1323008 500117503 498794496 237.8G Microsoft basic data
Device     Boot      Start        End   Sectors   Size Id Type
/dev/sdb1             2048  976760831 976758784 465.8G  7 HPFS/NTFS/exFAT
/dev/sdb2        976760832 1575153663 598392832 285.3G  7 HPFS/NTFS/exFAT
/dev/sdb3       1575155710 1953522899 378367190 180.4G  f W95 Ext'd (LBA)
/dev/sdb5       1575155712 1953522899 378367188 180.4G 83 Linux
Device         Start       End   Sectors  Size Type
/dev/sdc1       2048 120946647 120944600 57.7G Microsoft basic data
/dev/sdc2  120946648 121012183     65536   32M Microsoft basic data

blkid

/dev/mapper/ventoy: BLOCK_SIZE="2048" UUID="2022-10-20-07-22-49-00" LABEL="Ubuntu 22.10 amd64" TYPE="iso9660" PTUUID="a9694891-aa3f-477b-ab3b-77efbbb2b778" PTTYPE="gpt"

/dev/sdb2: LABEL="Data 2" BLOCK_SIZE="512" UUID="01D861845BA0ECC0" TYPE="ntfs" PARTUUID="5d7c62cf-02"
/dev/sdb5: UUID="9eaa2b5c-8461-d801-90a0-2b5c8461d801" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5d7c62cf-05"
/dev/sdb1: LABEL="Data 1" BLOCK_SIZE="512" UUID="6832DD6C32DD402C" TYPE="ntfs" PARTUUID="5d7c62cf-01"

/dev/sda4: BLOCK_SIZE="512" UUID="A2461C26461BFA2D" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="c11a57aa-201a-4d10-afda-4dd881ceea8d"
/dev/sda3: PARTLABEL="Microsoft reserved partition" PARTUUID="62a77485-477f-4563-b1fb-2680a1c936b8"
/dev/sda2: UUID="A60F-5FE8" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="283219e6-fb32-4f88-8e67-3ffd1bb581d3"
/dev/sda1: LABEL="RM-CM-)cupM-CM-)ration" BLOCK_SIZE="512" UUID="92CA0EF5CA0ED57F" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="ef424779-5fec-41e6-9522-1b570fe71b16"

/dev/sdc1: LABEL="Ventoy" UUID="69D5-AA8F" BLOCK_SIZE="512" TYPE="exfat" PTTYPE="dos" PARTLABEL="Ventoy" PARTUUID="32eb2c50-5943-6695-4fbb-d664c0737ed9"
/dev/sdc2: BLOCK_SIZE="2048" UUID="2022-10-20-07-22-49-00" LABEL="Ubuntu 22.10 amd64" TYPE="iso9660" PTUUID="a9694891-aa3f-477b-ab3b-77efbbb2b778" PTTYPE="gpt"
NAME       FSTYPE   UUID                                 PARTUUID                             LABEL        PARTLABEL
sda                                                                                                        
├─sda1     ntfs     92CA0EF5CA0ED57F                     ef424779-5fec-41e6-9522-1b570fe71b16 Récupération Basic data partition
├─sda2     vfat     A60F-5FE8                            283219e6-fb32-4f88-8e67-3ffd1bb581d3              EFI system partition
├─sda3                                                   62a77485-477f-4563-b1fb-2680a1c936b8              Microsoft reserved partition
└─sda4     ntfs     A2461C26461BFA2D                     c11a57aa-201a-4d10-afda-4dd881ceea8d              Basic data partition
sdb                                                                                                        
├─sdb1     ntfs     6832DD6C32DD402C                     5d7c62cf-01                          Data 1       
├─sdb2     ntfs     01D861845BA0ECC0                     5d7c62cf-02                          Data 2       
├─sdb3                                                   5d7c62cf-03                                       
└─sdb5     ext4     9eaa2b5c-8461-d801-90a0-2b5c8461d801 5d7c62cf-05                                       
sdc                                                                                                        
├─sdc1     exfat    69D5-AA8F                            32eb2c50-5943-6695-4fbb-d664c0737ed9 Ventoy       Ventoy
│ └─ventoy                                                                                                 
└─sdc2                                                                                                     
sdd 

parted -lm

BYT;
/dev/sda:256GB:scsi:512:512:gpt:ATA LITEON CV1-8B256:;
1:1049kB:556MB:555MB:ntfs:Basic data partition:hidden, diag;
2:556MB:661MB:105MB:fat32:EFI system partition:boot, esp;
3:661MB:677MB:16.8MB::Microsoft reserved partition:msftres;
4:677MB:256GB:255GB:ntfs:Basic data partition:msftdata;

BYT;
/dev/sdb:1000GB:scsi:512:4096:msdos:ATA ST1000LM035-1RK1:;
1:1049kB:500GB:500GB:ntfs::;
2:500GB:806GB:306GB:ntfs::;
3:806GB:1000GB:194GB:::lba;
5:806GB:1000GB:194GB:ext4::;

BYT;
/dev/sdc:62.0GB:scsi:512:512:gpt:hp x750w:;
1:1049kB:61.9GB:61.9GB::Ventoy:msftdata;
2:61.9GB:62.0GB:33.6MB:fat16:VTOYEFI:hidden, msftdata;

BYT;
/dev/mapper/ventoy:4072MB:dm:512:512:gpt:Linux device-mapper (linear):;
1:32.8kB:4067MB:4067MB::ISO9660:hidden, msftdata;
2:4067MB:4072MB:4354kB::Appended2:boot, esp;
3:4072MB:4072MB:307kB::Gap1:hidden, msftdata;

sdb5/etc/fstab

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sdb5 during installation
UUID=9eaa2b5c-8461-d801-90a0-2b5c8461d801 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda2 during installation
UUID=A60F-5FE8  /boot/efi       vfat    umask=0077      0       1
/swapfile      

@MahefaAbel
Copy link
Author

sudo chroot "/mnt/boot-sav/sdb5" dpkg --configure -a
sudo chroot "/mnt/boot-sav/sdb5" apt-get install -fy
sudo chroot "/mnt/boot-sav/sdb5" apt-get install -y mdadm
sudo chroot "/mnt/boot-sav/sdb5" mdadm --assemble --scan
sudo chroot "/mnt/boot-sav/sdb5" apt-get install -y dmraid
sudo chroot "/mnt/boot-sav/sdb5" dmraid -ay
sudo chroot "/mnt/boot-sav/sdb5" apt-get purge --allow-remove-essential -y grub-com*
sudo chroot "/mnt/boot-sav/sdb5" apt-get purge --allow-remove-essential -y grub2-com*
sudo chroot "/mnt/boot-sav/sdb5" apt-get purge --allow-remove-essential -y shim-signed
sudo chroot "/mnt/boot-sav/sdb5" apt-get purge --allow-remove-essential -y grub-common:*
sudo chroot "/mnt/boot-sav/sdb5" apt-get purge --allow-remove-essential -y grub2-common:*

@MahefaAbel
Copy link
Author

MahefaAbel commented Feb 6, 2023

Graphics Drivers issue

Issue Symptom

nvidia-settings

ERROR: NVIDIA driver is not loaded

(nvidia-settings:4676): GLib-GObject-CRITICAL **: 14:26:43.940: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

** (nvidia-settings:4676): CRITICAL **: 14:26:43.943: ctk_powermode_new: assertion '(ctrl_target != NULL) && (ctrl_target->h != NULL)' failed

ERROR: nvidia-settings could not find the registry key file or the X server is
not accessible. This file should have been installed along with this
driver at
/usr/share/nvidia/nvidia-application-profiles-key-documentation. The
application profiles will continue to work, but values cannot be
prepopulated or validated, and will not be listed in the help text.
Please see the README for possible values and descriptions.

Fixes

sudo update-initramfs -u
sudo apt install --reinstall nvidia-driver-525

Utils

sudo ubuntu-drivers autoinstall
sudo prime-select nvidia
sudo rm /lib/modprobe.d/blacklist-nvidia.conf /etc/modprobe.d/blacklist-nvidia.conf
sudo apt-get install linux-headers-`uname -r`
sudo reboot now
sudo apt-get install linux-headers-`uname -r`
sudo apt reinstall nvidia-driver-515
sudo modprobe nvidia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment