0

I have a Centos 6 server resided in cloud environment that I want to move the root partition from the existing harddisk to another one.

In the original harddisk(/dev/xvda1), it has other folder like /var, /usr, and I don't want to move them over, so I can't simply dd the whole old harddisk to a new one (/dev/xvdh1).

I have now rsync all the content in / (except those mentioned above) to /dev/xvdh1, and /var /usr to another harddisk (/dev/xvdg). I have modified the following file in the new harddisk to use the new UUID:

  • /etc/fstab
  • /boot/grub/grub.conf

Here is the output of blkid:

/dev/xvdh1: UUID="9b84e28c-5a12-4889-804a-753e56645333" TYPE="ext4"

line in /etc/fstab that do the / mount :

UUID="9b84e28c-5a12-4889-804a-753e56645333" /   ext4    defaults        1 1

/boot/grub/grub.conf:

default=0
timeout=1
title CentOS 6 (2.6.32-573.18.1.el6.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-573.18.1.el6.x86_64 ro root=UUID=9b84e28c-5a12-4889-804a-753e56645333 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD console=ttyS0,115200 crashkernel=auto SYSFONT=latarcyrheb-sun16  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM
        initrd /boot/initramfs-2.6.32-573.18.1.el6.x86_64.img

I have also dd the boot sector code from /dev/xvda to /dev/xvdh1:

dd if=/dev/xvda of=/dev/xvdh bs=446 count=1

Output of both harddisk metadata:

# file -s /dev/xvda
/dev/xvda: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x8cc500, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 16775168 sectors, code offset 0x48

# file -s /dev/xvda1
/dev/xvda1: Linux rev 1.0 ext4 filesystem data (needs journal recovery) (extents) (large files) (huge files)

# file -s /dev/xvdh
/dev/xvdh: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x8cc500, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 4192256 sectors, code offset 0x48

# file -s /dev/xvdh1
/dev/xvdh1: Linux rev 1.0 ext4 filesystem data (needs journal recovery) (extents) (large files) (huge files)

When all the above steps done, I detached the old harddisk and attached the new harddisk as /dev/xvda1, then boot. However when I boot the machine I stuck at the error on grub:

Booting from Hard Disk... 
Geom Error

Size of /dev/xvda1 and /dev/xvdh1 are different, and obviously their UUID is different too. So my question is: do I need to do a grub-install in order to make the modification I done on the grub.conf to goes into the boot sector code? Or there is never need to do that because the boot code is just the same and root partition info is never stored over there , where the boot code will able to read the grub.conf to get the info without extra step needed ?

Please shed some light if I need to change any other file in order to make the grub boot the server, thanks. (grub version: 0.94)

1

Yes, I believe you should run grub-install, as the location (noted below) is dependent upon the filesystem containing stage 2.

You say you copied the boot sector from the old disk (/dev/xvda) to the first partition on the new disk (/dev/xvdh1). Doesn't the code need to go in the first sector of the new disk, not the partition?

The initial stage contains a pointer to the second stage, as you suggest, and is noted in the graphic in this answer: https://unix.stackexchange.com/a/258867/216116

As well, Debian is setup to run grub-install during regular software updates, so it should be no harm with (in) your solution to execute grub-install as you please (with the proper arguments, of course).

  • These are excellent points, it makes most sense to run grub-install, or dpkg-reconfigure grub-pc to use the Debian frontend. I'd say it's hard to verify whether there's a concern specifically with stage2 on the filesystem or what (seems to me it's preferred to be installed in "free" sectors immediately after the MBR). Rather, re-running grub-install is absolutely the correct way to install grub to the new drive, whatever grub thinks it needs in order to do that. – sourcejedi Feb 15 '17 at 20:32
  • The grub2 documentation isn't particularly well-regarded anyway; best not to rely on sector-by-sector implementation details when there's no reason to. – sourcejedi Feb 15 '17 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.