Does anybody have a suggestion for how to move the root partition to a new drive and set up grub2 to boot on that drive? I seem to have no luck instructing grub-mkconfig what it is I want to do (e.g. chroot'int into my new root just confuses all the scripts).
Background I am running Debian Squeeze on a headless low-power NAS. My current setup is /
on sda0
and /boot
on sde0
(a CF card): I needed the separate /boot
because sd[a-d]
need to do a delayed spin-up. Now I've found an old 2.5" IDE disk to use as /
including /boot
to allow me to spin all the big disks down.
What I've tried Basically I went
mount -o rw /dev/sdf5 /mnt/newroot
cp -ax / /mnt/newroot
cp -ax /boot /mnt/newroot/boot
Then I tried
chroot /mnt/newroot
update-grub
But that failed with grub asking if root was mounted.
Then I did a half-hearted attempt at setting up /mnt/newroot/grub/grub.cfg
to find the kernel image on sdf5
, followed by a grub-install --root-directory=/mnt/newroot /dev/sdf
. But this just landed me a grub rescue prompt when I tried booting from sdf
.
My backup plan is to just reinstall, so a bonus question (no checkmarks for this one): What do I have to do to get my lvm2 and mdadm config across? Is it all stored in the filesystems (and will it be automatically discovered), or do I need to take of it myself?
Solution (thanks to Maciej Piechotka): As Maciej points out, I need to to a proper chroot for all the grub tools to work. For reference, this is how I did it:
janus@nasguld:/mnt/newroot$ sudo cp -ax / /mnt/newroot
janus@nasguld:/mnt/newroot$ sudo cp -ax /boot /mnt/newroot
All the files are now copied (see here for a discussion of copy strategies). Fix the new etc/fstab
to point to new root:
janus@nasguld:/mnt/newroot$ diff -u etc/fstab.old etc/fstab
-UUID=399b6a6d-c067-4caf-bb3e-85317d66cf46 / ext3 errors=remount-ro 0 1
-UUID=b394b614-a977-4860-bbd5-7862d2b7e02a /boot ext3 defaults 0 2
+UUID=b9d62595-e95c-45b1-8a46-2c0b37fcf153 / ext3 noatime,errors=remount-ro 0 1
Finally, mount dev
,sys
and proc
to the new root and chroot:
janus@nasguld:/mnt/newroot$ sudo mount -o bind /dev /mnt/newroot/dev
janus@nasguld:/mnt/newroot$ sudo mount -t proc none /mnt/newroot/proc
janus@nasguld:/mnt/newroot$ sudo mount -t sysfs none /mnt/newroot/sys
janus@nasguld:/mnt/newroot$ sudo parted /dev/sdb set 5 boot on
janus@nasguld:/mnt/newroot$ sudo chroot .
We are now chrooted to the future root exactly as it will look. According to Maciej, it should be ok to just call grub-install
, but I did an update-grub
first to get a look at the generated /boot/grub/grub.cfg
before installing the bootloader. I am not sure it will be automatically updated?
root@nasguld:/# update-grub
root@nasguld:/# grub-install /dev/sdb
/etc/default/grub
, and the exact transcript fromupdate-grub
./etc/fstab
in thechroot
(this would be consistent withupdate-grub
complaining that "\ isn't mounted"). Were I to do this again, I would try first without bothering to mount the special file systems in the chroot.