· 6 years ago · Mar 09, 2019, 11:52 PM
1--- !!! ---
2WARNING: THESE INSTRUCTIONS DO NOT APPLY TO EFI/UEFI SETUPS !!!
3USE THESE FOR TRADITIONAL BIOS SYSTEMS, ONLY !!!
4--- !!! ---
5
6## First Part: Converting MBR to GPT PROPERLY
7
8You will need to do all of these commands AS ROOT
9
101. Boot into a live Linux operating system.
11
12Make sure it is UP TO DATE, because, for example, if you use BTRFS, like a champ, then
13btrfs-tools needs to support ZSTD compression, etc... And most older distros do not have this.
14
152. Install the following packages (Debian-based):
16
17```
18$ sudo -i
19# apt update; apt install grub-pc gdisk gparted parted btrfs-tools
20```
21
223. In a root terminal, you can create the GPT BIOS partition using gdisk.
23Do not worry. Looks like gdisk will apparently set the "bios_grub" flag on its own.
24
25But if it DOES NOT run this:
26
27```
28# parted set X bios_grub on
29```
30
31X is the number of your partition. You can use gdisk `/dev/mydisk` and "p" to print.
32use the number under the "Number" column.
33
344. You can create the GPT BIOS partition even though "it appears" that the
35entire disk is full of partitions. The usual places to put it start from:
36
37Sector 34 to sector 2047
38
39So make sure this is the case. Rarely does it start from sector 1.
40The partition NEEDS to be AT LEAST GREATER THAN 1 MiB IN SIZE! CHECK THIS!
41
42The code name for the GPT BIOS Partition file system (in gdisk) is: EF02
43
44NOTE: Do not forget to SORT the partitions afterwards!
45The gdisk utility is fucking retarded, in that it can't create a partition
46number behind from the highest Nth partition number (as of the time of this writing).
47Maybe they will fix that restriction sometime.
48
49But... DO NOT WORRY ABOUT THIS.
50
51All you need to do is SORT IT LATER. So just press "s" in gdisk, afterwards.
52Feel free to label anything (as in names/string labels) before writing. Or feel free to use
53gparted to do it later, because gparted will always be more awesome than gdisk and parted combined.
54IDK if you're worried about alignment shit. You can fix that on your own.
55
56One more thing: You do not need to worry about having a boot/esp partition flag
57for a NON-UEFI PARTITION. That right GRUB is at least smart enough to figure out where
58the boot directory is, later on. I would say, better safe than sorry.
59The flag "boot, esp" as listed in gparted will not prevent you from booting, at least.
60They are supposed to be for UEFI, though...
61
62Finally, don't forget to write "w" all changes in gdisk!
63
64---
65
66## Second Part: Setting up GRUB on GPT from a Live Environment
67
68Now then, grub-install is a really fucking stupid utility that can't handle writing files
69directly to an unmounted /boot directory for some fucking reason, even though it can write to a
70simple partition, or a block device just fine... like /dev/sda, for example.
71
72NOTE: You should NOT, I repeat, NOT install GRUB to a PARTITION. IT JUST ISN'T DONE THIS WAY.
73This includes the GPT BIOS partition we just made. This was really confusing information, and
74hard to look up at first. The whole "stage 2" GRUB process happens in the GPT BIOS partition,
75or whatever, but you NEED to install GRUB to the protected mbr/partition table header,
76or whatever the fuck it's called.
77
78In other words, use /dev/sda, NEVER /dev/sda1 or /dev/sda2... /dev/yourmom, etc...
79
80All this being said, we are going to need to do some nigger-retarded mounting of the
81root directory, and the /boot directory (which is optional, if it exists.)
82
83This mounting is, unfortunately, a REQUIREMENT to make the GRUB installation process happy.
84There is no chrooting, so do not worry.
85
86For the below instructions, MAKE SURE you REPLACE /dev/sda with YOUR DESIGNATED STORAGE DEVICE!
87ALWAYS USE fdisk -l CONSTANTLY to CHECK which device(s) you are changing/writing to.
88
89Again, you will need to do all of these commands AS ROOT!
90
911. Create a folder on /mnt/, and mount the root folder:
92(X is the partition number for the root partition)
93
94```
95# mkdir /mnt/root
96# mount /dev/sdaY /mnt/root
97```
98
992. Mount the boot partition in the mounted root directory:
100(You should already have a boot folder in this directory. If not, create one)
101
102```
103# mount /dev/sdaX /mnt/root/boot
104```
105
1063. Now the magic begins:
107
108```
109# grub-install --boot-directory=/mnt/root/boot /dev/sda
110```
111
112Honestly, if you did these right, these instructions should only take about 5 minutes, and will
113save you hours of headache trying to figure out what went wrong...
114
115I spent 7 hours trying to figure out why my system wouldn't boot, only to find out that
116the code for my partition was not EF02, but something else. Following these instructions
117well, and consistently, is very important for success!
118
119I will note something... If you install GRUB from a shitty live distro, sometimes YMMV, because
120the grub config that the live distro uses will be applied to this new grub install.
121
122So what you really want to do, after you (hopefully) boot into your new GPT-fresh GNU/Linux OS,
123is to run this to apply your own distro's GRUB configuration:
124
125```
126# update-grub /dev/sda
127```
128
129And that's it! Have fun converting everything from awful MBR to superior GPT master race!
130
131---
132
133### Shorthand version:
134
135```
136# Try to get root access immediately without a root password
137sudo -i
138
139# Install much needed utilities. You may have more depending on what filesystem(s) you use.
140apt update; apt install grub-pc gdisk gparted parted btrfs-tools
141
142# Set up GPT, create GPT BIOS, sort partitions, FS labeling, and more
143gdisk /dev/sda
144
145# Resize partitions easily, re-label easily, etc...
146gparted /dev/sda
147
148# In case the required bios_grub flag is not set:
149parted set X bios_grub on
150
151# Proceed to install grub-pc to your disk of choice:
152mkdir /mnt/root
153mount /dev/sdaX /mnt/root
154mount /dev/sdaY /mnt/root/boot
155grub-install --boot-directory=/mnt/root/boot /dev/sda
156
157# Once booted into the converted OS ...
158
159update-grub /dev/sda
160
161```