PDA

View Full Version : [ubuntu] grub and rsync



pjmlmas
January 1st, 2012, 09:50 PM
DR exercise
i backed-up ubuntu[orig] on /dev/sda9 to exthd using rsync
i restored ubuntu[bu] from exthd to new partition on /dev/sda8
i modified fstab of ubuntu[bu] on /dev/sda8 to point to sda8
i ran grub-update on ubuntu[control] /dev/sda7
i now have three instances of ubuntu[control, orig, bu]. However, when I choose sda8[bu], sda9[orig] ubuntu instance is loaded.

What else needs to be modified on ubuntu[bu] /dev/sda8 ?

oldfred
January 1st, 2012, 10:40 PM
Both grub & fstab have entries to partitions, but device, label, or UUID. So you also need to update grub. But if booting from one install it should let you directly boot into the other installs.

Post this to see entire configuration. This is a new test version of the boot script to try. It will download the script directly. Post the results.txt inside code tags. Copy & highlight the contents of the script and click on # in the edit panel above your post to auto add the code tags.


wget -O bootinfoscript 'http://bootinfoscript.git.sourceforge.net/git/gitweb.cgi?p=bootinfoscript/bootinfoscript;a=blob_plain;f=bootinfoscript;hb=HE AD'

chmod a+x bootinfoscript

sudo bash bootinfoscript

Standard version:
Boot Info Script courtesy of forum members meierfra & Gert Hulselmans
Page with instructions and download:
http://bootinfoscript.sourceforge.net/
Paste contents of results.txt in a New Reply, then highlight entire file and click on # in edit panel(code tags) to make it easier to read.
Or You can generate the tags first by pressing the # icon in the New Reply Edit toolbar and then paste the contents between the generated [ code] paste here [ /code] tags.
V60 has improved formating and requires code tags to make it legible. New Version is a zip file that you have to extract to get .sh to run.
Install these before running script:
sudo apt-get install gawk
sudo apt-get install xz-utils

pjmlmas
January 2nd, 2012, 03:44 PM
I believe I see the problem...
w/o posting entire txt file (bear with me)

The menu entry that was generated by sudo update-grub for dev/sda8 (ubuntu bu restored instance):
set root = hd0 8 <- good sda8
search --uuid = uuid of sda8 <-good sda8
linux boot vm linuz root=uuid of sda9 <-bad sda9
??? why

Easy enough editing the file, but there must be something wrong with restored ubuntu instance? Where does update-grub get information for linux root info?

additional info. dev/sda7 - grub.cfg - this is used by mbr.
dev/sda8 and dev/sda9 also have their own old grub.cfg, but not used, at least not by mbr.

pjmlmas
January 2nd, 2012, 03:48 PM
I am pondering
booting to sda7 (Ubuntu control)
removing/renaming grub.cfg on dev/sda8 (Ubuntu testing)
re-run sudo update-grub...

The reasoning is that perhaps update-grub is "reading" bad/old grub.cfg from /dev/sda8 (Ubuntu Testing) to retrieve information.
When I read about moving partitions, see some info about grub and grub.cfg come up, especially uuid and set root in grub.cfg...even if not being used by mbr, still...

oldfred
January 2nd, 2012, 07:44 PM
I believe the os-prober looks first for grub menu files, menu.lst, grub.cfg or others from other systems. Then if not found may try to create a boot stanza. So if you boot stanza was wrong in the other install it probably picked up that data.

You need to run the sudo update-grub in the install with the issue. You should be able to manually edit the grub boot stanza to boot the first time. Then boot into the install that you boot from, run the update-grub, and it should correct the entry.

To avoid all the rebooting & grub updates I turn off the os-prober and just boot to the partition. This works for Ubuntu, not sure about other installs as Ubuntu updates a link in / to the newest install on every kernel update.

gksudo gedit /etc/grub.d/40_custom
sudo update-grub

I first saw this from Ranch hand
Note that this does not define the kernel. It defines the partition. It boots the newest bootable kernel that it finds at that partition.

menuentry "Daily on sda13" {
set root=(hd0,13)
linux /vmlinuz root=/dev/sda13 ro quiet splash
initrd /initrd.img
}

After I know the above works, I turn off os-prober.

In /etc/default/grub I added this:
gksudo gedit /etc/default/grub
GRUB_DISABLE_OS_PROBER=true
or
sudo chmod a-x /etc/grub.d/30_os-prober

pjmlmas
January 2nd, 2012, 11:15 PM
Thanks about os-probe information, makes sense now.

I performed the ops that I thought about. For others who may see thread.

Loaded /dev/sda7 Ubuntu control instance.
Mounted /dev/sda8 Ubuntu bu.
Removed grub.cfg from Ubuntu bu on /dev/sda8 (/media/)
Ran sudo update-grub. This gave me similar setup in grub.cfg as oldfred. No more uuid, just /dev/sda8.
(Note grub.cfg from update-grub will no longer be quiet)
Restart
Pick /dev/sda8 Ubuntu BU instance.
Lots of noise...
sudo grub-mkconfig -o /boot/grub/grub.cfg (on dev/sda8)
Restart
Pick /dev/sda7 Ubuntu control instance
sudo update-grub ... it does use grub.cfg from /dev/sda8 (os-prober?)

pjmlmas
January 2nd, 2012, 11:27 PM
In case anyone stumbles upon this thread

Full partition BU:
sudo rsync --archive --one-file-system --hard-links --human-readable --delete --delete-excluded --progress --exclude-from=backup.lst /media/WhatUWant2BU/ /media/exthd/sometest/FULLBUWhatUWant2BU

Full partition restore:
sudo rsync --archive --one-file-system --hard-links --human-readable --progress /media/exthd/sometest/FULLBUWhatUWant2BU /media/testing

Note: Trailing SLASHES MATTER, copy form exactly!!!

backup.lst
cat backup.lst
# Include
+ /dev/console
+ /dev/initctl
+ /dev/null
+ /dev/zero

# Exclude
- /dev/*
- /proc/*
- /sys/*
- /tmp/*
- lost+found/
- /media/backup/*
- /mnt/*

On restored partition:
sudo gedit /media/testing/etc/fstab &
Make uuids correct by looking here:
ls /dev/disk/by-uuid/

Remove grub.cfg.

On a running control instance.
Run sudo update-grub.
Reboot into restored partion.
sudo grub-mkconfig -o /boot/grub/grub.cfg
Reboot into control instance.
run sudo update-grub.


What is this for ...
Following above procedures, one can restore a partition.
With rsync allowing hardlink magic, hopefully, one can restore a partition from any point in time. To be tested.

Would like to try from a fresh hard drive, but not that comfortable as-is.

I performed fsck, seems ok. Any other check to see the restored partition is really ok (everything seems to be running fine)

pjmlmas
January 2nd, 2012, 11:29 PM
THANKS oldfred! \\:D/

oldfred
January 2nd, 2012, 11:48 PM
Glad you got it working. Nice to include the info on all the folders to include or exclude. I will save that.

I just use rsync to backup /home and some other info as I just will do a new clean install. I do like to include a list of installed packages & a new run of bootinfoscript just to document system - I have lots of partitions and have reorganized many times, so testdisk would present me with a long list, if I ever had to use it. Knowing partition layout in detail I could manually rebuild partition table.

If you have multiple installs and each installed grub to sda (or backup of one that did), you may want to change the parameter on where grub reinstalls or else each version when grub has a update will rewrite the MBR.

#to get grub to remember where to reinstall on updates:
sudo dpkg-reconfigure grub-pc
#Enter thru first pages,spacebar to choose/unchoose drive, enter to accept, do not choose partitions
#To see what drive grub2 uses see this line - grub-pc/install_devices:
sudo debconf-show grub-pc

this was a quote from a user with an external install who had grub installed to the internal & it overwrote his Windows on the internal on an update.


I finally found out how to prevent the MBR to be overwritten.
I ran dpkg-reconfigure grub-pc and deselected /dev/sda which meant that the values field for grub-pc/install_devices in /var/cache/debconf/config.dat is now empty. Then nothing is written to the MBR or the boot sector when grub-pc gets updated. Occasionally I should probably rerun manually grub-install /dev/sda2 after grub-pc package updates to keep 'stage1' install in sync.