# Récuperer grub avec un live cd Debian

**URL:** <https://www.debian-fr.org/t/recuperer-grub-avec-un-live-cd-debian/71138>\
**Category:** Trucs et Astuces\
**Created:** [Septembre 29, 2016, 3:48 UTC](https://www.debian-fr.org/t/recuperer-grub-avec-un-live-cd-debian/71138 "2016-09-29T15:48:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grandtoubab](https://www.debian-fr.org/user_avatar/www.debian-fr.org/grandtoubab/32/4505_2.png) [@grandtoubab](https://www.debian-fr.org/u/grandtoubab)\
**Post date:** [Septembre 29, 2016, 3:48 UTC](https://www.debian-fr.org/t/recuperer-grub-avec-un-live-cd-debian/71138/1 "2016-09-29T15:48:37Z")

</div>

Salut  
Suite a une tentative de multi-boot Debian/Opensuse qui s’est mal terminée il a fallu que je chroot et je me suis aperçu de certains pb dans les mode d’emploi que je trouvais sur internet ( via mon smartphone, ça sert bien 😀 )

1- je considère que vous avez la connaissance de votre installation existante, exemple je sais que Debian est sur /dev/sda1 de mon disque dur  
2- le Live cd Debian que j’ai utilisé est un Jessie 8.3

- Le live cd a bien booté, vous réussissez à ouvrir un terminal dont le prompt est  
user@debian:~$

- Ah dans la précipitation, vous n’avez pas pensé au clavier et vous vous retrouvez en qwerty

`user@debian:~$ setxkbmap fr`

pour cela il faut appuyer sur les touches setxkb,qp fr

- Vérification de l’état des partitions

```nohighlight
user@debian:~$ sudo fdisk -l

Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00038c4c

Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 19531775 19529728 9.3G 83 Linux
/dev/sda2 * 19533822 625141759 605607938 288.8G 5 Extended
/dev/sda5 19533824 35237887 15704064 7.5G 82 Linux swap / Solaris
/dev/sda6 35239936 594421759 559181824 266.7G 83 Linux
/dev/sda7 594423808 625141759 30717952 14.7G 83 Linux

Disk /dev/loop0: 829.6 MiB, 869924864 bytes, 1699072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

```

- Dans mon cas le flag boot n’est pas sur la bonne partition, je le veux sur /dev/sda1

```nohighlight
user@debian:~$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00038c4c

Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 19531775 19529728 9.3G 83 Linux
/dev/sda2 * 19533822 625141759 605607938 288.8G 5 Extended
/dev/sda5 19533824 35237887 15704064 7.5G 82 Linux swap / Solaris
/dev/sda6 35239936 594421759 559181824 266.7G 83 Linux
/dev/sda7 594423808 625141759 30717952 14.7G 83 Linux

Command (m for help): a
Partition number (1,2,5-7, default 7): 1

The bootable flag on partition 1 is enabled now.

```

- on revérifie

```nohighlight
Command (m for help): p
Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00038c4c

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 19531775 19529728 9.3G 83 Linux
/dev/sda2 * 19533822 625141759 605607938 288.8G 5 Extended
/dev/sda5 19533824 35237887 15704064 7.5G 82 Linux swap / Solaris
/dev/sda6 35239936 594421759 559181824 266.7G 83 Linux
/dev/sda7 594423808 625141759 30717952 14.7G 83 Linux

```

- On le retire de /dev/sda2

```nohighlight
Command (m for help): a
Partition number (1,2,5-7, default 7): 2

The bootable flag on partition 2 is disabled now.

Command (m for help): p
Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00038c4c

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 19531775 19529728 9.3G 83 Linux
/dev/sda2 19533822 625141759 605607938 288.8G 5 Extended
/dev/sda5 19533824 35237887 15704064 7.5G 82 Linux swap / Solaris
/dev/sda6 35239936 594421759 559181824 266.7G 83 Linux
/dev/sda7 594423808 625141759 30717952 14.7G 83 Linux

```

- Nickel on écrit ça sur le disque

```nohighlight
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

user@debian:~$ sudo fdisk -l

Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00038c4c

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 19531775 19529728 9.3G 83 Linux
/dev/sda2 19533822 625141759 605607938 288.8G 5 Extended
/dev/sda5 19533824 35237887 15704064 7.5G 82 Linux swap / Solaris
/dev/sda6 35239936 594421759 559181824 266.7G 83 Linux
/dev/sda7 594423808 625141759 30717952 14.7G 83 Linux

Disk /dev/loop0: 829.6 MiB, 869924864 bytes, 1699072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

```

- On verifie le MBR

```nohighlight
user@debian:~$ sudo dd if=/dev/sda bs=512 count=1 | strings
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000385737 s, 1.3 MB/s
RPf1
Missing operating system.
f`f1
|fRfP
Ht[y9Y[
Multiple active partitions.
|XFSBu	f
Operating system load error.

```

- C’est pas bon c’est pas marqué GRUB dedans
- On chroot

```nohighlight
user@debian:~$ sudo mkdir /mnt/chroot

user@debian:~$ sudo mount /dev/sda1 /mnt/chroot
user@debian:~$ sudo mount --bind /dev/ /mnt/chroot/dev
user@debian:~$ sudo mount -t proc /proc /mnt/chroot/proc

user@debian:~$ sudo mount -t sysfs /sys /mnt/chroot/sys

user@debian:~$ sudo chroot /mnt/chroot
root@debian:/# 

```

- Là vous notez que le prompt à changé, c’est devenu root@debian:/#

- On réinstalle grub

```nohighlight
root@debian:/# grub-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
root@debian:/# 

```

- Et voilà!

- si besoin est vous pouvez verifier /boot/grub/grub.cfg et si vous ne le trouvez pas saisfaisant faire update-grub

- On relit le MBR

```nohighlight
root@debian:/boot/grub# dd if=/dev/sda bs=512 count=1 | strings
1+0 records in
1+0 records out
512 bytes copied, 0.000205447 s, 2.5 MB/s
RPf1
ZRr=
`|f	
\|f1
GRUB 
Geom
Hard Disk
Read
 Error

```

- c’est bien écrit GRUB, ça sent meilleur 😂

En tout cas ça ma sauvé et j’ai rebooter tranquille sur Debian

---

<div class="post-metadata">

**Author:** ![anon29980398](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/a/f4b2a3/32.png) [@anon29980398](https://www.debian-fr.org/u/anon29980398)\
**Post date:** [Novembre 1, 2016, 3:59 UTC](https://www.debian-fr.org/t/recuperer-grub-avec-un-live-cd-debian/71138/2 "2016-11-01T15:59:08Z")

</div>

Bonjour **grandtoubab**

J’utilise un fichier image ISO netinstall : `debian-8.6.0-amd64-netinst.iso`

Comme il s’agit d’une machine virtuelle utilisant un fichier image disque QCow2,  
le nom du fichier de périphérique associé au disque est **/dev/vda**  
et la partition hébergeant le système de fichiers racine est **/dev/vda1**

Mais la méthode est la même que pour un disque SATA, IDE, ou autre.

[![](https://www.debian-fr.org/uploads/default/original/2X/c/c2f0c0339e2458114bf6fd266c9806a2b754a651.png)](http://pix.toile-libre.org/?img=1478014619.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/f/f76cd7f2b2015203ff293b9869b3659698d0fcc4.png)](http://pix.toile-libre.org/?img=1478014687.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/c/c16d8584081b30b6fee36a8e9cdbfccbff32fc66.png)](http://pix.toile-libre.org/?img=1478014776.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/b/bcd1c8fc3fab9d999ad1e16e2d19fe3d3b881649.png)](http://pix.toile-libre.org/?img=1478014811.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/3/3f8f7a1bb1512fa8ec599d7934b36be15769ef89.png)](http://pix.toile-libre.org/?img=1478014838.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/3/35e89d057263199062760dd9a397d66c806a48d4.png)](http://pix.toile-libre.org/?img=1478014863.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/7/7f42f0b1690a188f00cec9bf25f03826a2971173.png)](http://pix.toile-libre.org/?img=1478014904.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/a/ab4d511883cf849b95073706e8c5a2b8a70ad6b9.png)](http://pix.toile-libre.org/?img=1478014927.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/c/cd71e99aa654f6a5c5a21ffeb9e44a75b527a61e.png)](http://pix.toile-libre.org/?img=1478014952.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/2/2d20df70dde7e1799a8cff0b009586f4d11241b2.png)](http://pix.toile-libre.org/?img=1478014980.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/3/3abb58155d958cdbbf3d44474e52d3408a118828.png)](http://pix.toile-libre.org/?img=1478015030.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/9/9b8c2e6a3b2889c30ca9344a260ed2a9aaa5408e.png)](http://pix.toile-libre.org/?img=1478015061.png)

[![](https://www.debian-fr.org/uploads/default/original/2X/2/2bfcbde525a140f5068468a8a5acb8c66f95a007.png)](http://pix.toile-libre.org/?img=1478015086.png)

* * *

**Une petite remarque :** Pour ceux qui utiliseraient une partition séparée pour **/boot/**  
vous devrez d’abord mounter le système de fichiers de cette partition avant de réinstaller le chargeur de boot GRUB  
Le menu : `Exécuter un shell dans /dev/xxxx`  
vous permettra de monter le système de fichiers de **/boot** afin de pouvoir réinstaller **GRUB**
