Delicious Grub

I’ve been getting the “disk space less than 2GB” warning for a while now, which is just ridiculous since my disk is 320GB and I keep a very bare boned system with minimal stored media.

So what’s going on?

Turns out my initial disk partition was abysmal (swap not shown):

---------------------------------------------------------
| /dev/sda1  | /dev/sda3                                |
---------------------------------------------------------

/dev/sda1 was my /home partition. /dev/sda3 was my / partition. For some reason I decided / should take the majority of my disk. /home was at 98% usage (of the given 100GB), while / sits on infinite resources like Apple with its cash reserved.

Not willing to re-install, some ninja partitioning was needed…a day without my laptop.

This article was extremely informative in helping me migrate the / partition. Here are the steps I took, note that all my devices were named /dev/sdaX since I only have 1 hard drive. The partitions on a second hard drive would be /dev/sdb1, /dev/sdb2, and so on.

Step 1: Boot through SystemRescueCD

Following the Ubuntu Doc‘s step 1, download the SystemRescueCD and use the X-desktop.

Step 2: Copy and paste the /home partition

Launch GParted (from the start menu) and:
1) Make an /ext4 partition from the big unused chunk of /dev/sda3 bigger than /dev/sda1. Right click /dev/sda1 and select copy, then select the newly created partition (/dev/sda4), right click and select paste. Apply the changes, and now the partition map becomes:

------------------------------------------------
| /dev/sda1 | /dev/sda3  | /dev/sda4           |
------------------------------------------------

2) Delete /dev/sda1.
3) Reboot into Ubuntu to check things have worked. Go to System->Administration->Disk Utility to see that the partition map is now:

--------------------------------------------------
| Unallocated | /dev/sda3 | /dev/sda4            |
--------------------------------------------------

Since my /home was on its own directory, the partition copied over has the same UUID for /home recorded in the boot record within /.

Step 3: Make a clone of the root directory

1) Make a partition in the unallocated space.
2) Copy and paste /dev/sda3 into the new space.
3) Generate and update UUID for /dev/sda1 with:

/root>: tune2fs -U random /dev/sda1

Note the generated UUID.
If you reboot at this point and check the disk utility, you’ll see:

---------------------------------------------------
|/dev/sda1  | /dev/sda3 | /dev/sda4               |
---------------------------------------------------

Note that the copied /dev/sda1 is unmounted. Now we have to

Step 4: Update grub and fstab

1) Mount the cloned root partition via the Places option.
2) Edit the grub.cfg file of the clone:

pc:~$ cd /media//boot/grub; sudo vim grub.cfg 

3) Change all the set root='(/dev/sda,msdos3)' lines to set root='(/dev/sda,msdos1)'
Find all the lines containing --fs-uuid --set=root XXXXXXXXXXXXXX, where XXXXXXXX is the UUID of /dev/sda3, and replace that with the newly-generated UUID.
These setups update the grub so it knows where to find the boot files (/dev/sda1 instead of /dev/sda3).
4) Edit the cloned partition’s fstab:

pc:~$ sudo vim /media/cloneUUID/etc/fstab

Find the lines corresponding to the / partition and change the UUID to the clone’s UUID.
Save and quit.
5) Run grub-setup

pc:~$ sudo grub-setup -d /media/cloneUUID/boot/grub /dev/sda

6) Update new partition as bootable.
In disk utility, select the new partition, click on “edit partition”, check the “bootable” box and click “apply”.
7) Reboot.

Normally, this would successfully boot into the new partition. I assumed that too, so I booted into SystemRescue, deleted the old root partition, decreased the size of /dev/sda1, moved up and extended the /home partition so that the partition map is:

--------------------------------------------
| /dev/sda1 | /dev/sda4                    |
--------------------------------------------

On reboot, however, I got the prompt

Error: File not found...
grub rescue>

Oops…

The Grub2 troubleshooting documentation tells me grub can’t find the correct grub.cfg file. Mount /dev/sda1 through SystemRescue, I corrected some typos in the grub.cfg and the fstab files.

Reboot gives me the same grub rescue prompt again, checking grub folder path reveals:

grub rescue>set
...
prefix=(hd0,msdos3)/media/boot/grub
...

Way messed up…since we know the grub.cfg file is in /dev/sda1/boot/grub, so I did this:

grub rescue>set prefix=(hd0,msdos1)/boot/grub
grub rescue>set root=(hd0,msdos1)
grub rescue>insmod normal
grub rescue>normal

This gives successful booting (sometimes you may need to manually load the linux module and kernel and the initrd image, see here).

Last step

We’re not done yet, you’ll get the grub rescue prompt next time you boot again, if you don’t update the grub configuration. So do these

Advertisements

About collapsedwavefn

I have a lot of thoughts. Some of them I'd like to share.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s