Debian/Grub2: Moving root partition to new drive?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
31
down vote

favorite
12












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









share|improve this question























  • Post the contents of /etc/default/grub, and the exact transcript from update-grub.
    – Gilles
    Jan 1 '11 at 17:00










  • (thoughts after adding solution): It might actually be that the problem was that I hadn't updated /etc/fstab in the chroot (this would be consistent with update-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.
    – Janus
    Jan 3 '11 at 1:12










  • just a note: do not forget to unmount /mnt/newroot before reboot!
    – Giacomo Tesio
    May 16 '13 at 20:31










  • Here are instructions on how to move your root partition / to new nvme drive, while keeping the /home on hdd. lucasmanual.com/blog/…
    – Lucas
    Sep 17 at 2:51














up vote
31
down vote

favorite
12












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









share|improve this question























  • Post the contents of /etc/default/grub, and the exact transcript from update-grub.
    – Gilles
    Jan 1 '11 at 17:00










  • (thoughts after adding solution): It might actually be that the problem was that I hadn't updated /etc/fstab in the chroot (this would be consistent with update-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.
    – Janus
    Jan 3 '11 at 1:12










  • just a note: do not forget to unmount /mnt/newroot before reboot!
    – Giacomo Tesio
    May 16 '13 at 20:31










  • Here are instructions on how to move your root partition / to new nvme drive, while keeping the /home on hdd. lucasmanual.com/blog/…
    – Lucas
    Sep 17 at 2:51












up vote
31
down vote

favorite
12









up vote
31
down vote

favorite
12






12





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









share|improve this question















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






debian grub2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 '11 at 16:30









Steven D

31.1k696108




31.1k696108










asked Jan 1 '11 at 15:38









Janus

7331715




7331715











  • Post the contents of /etc/default/grub, and the exact transcript from update-grub.
    – Gilles
    Jan 1 '11 at 17:00










  • (thoughts after adding solution): It might actually be that the problem was that I hadn't updated /etc/fstab in the chroot (this would be consistent with update-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.
    – Janus
    Jan 3 '11 at 1:12










  • just a note: do not forget to unmount /mnt/newroot before reboot!
    – Giacomo Tesio
    May 16 '13 at 20:31










  • Here are instructions on how to move your root partition / to new nvme drive, while keeping the /home on hdd. lucasmanual.com/blog/…
    – Lucas
    Sep 17 at 2:51
















  • Post the contents of /etc/default/grub, and the exact transcript from update-grub.
    – Gilles
    Jan 1 '11 at 17:00










  • (thoughts after adding solution): It might actually be that the problem was that I hadn't updated /etc/fstab in the chroot (this would be consistent with update-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.
    – Janus
    Jan 3 '11 at 1:12










  • just a note: do not forget to unmount /mnt/newroot before reboot!
    – Giacomo Tesio
    May 16 '13 at 20:31










  • Here are instructions on how to move your root partition / to new nvme drive, while keeping the /home on hdd. lucasmanual.com/blog/…
    – Lucas
    Sep 17 at 2:51















Post the contents of /etc/default/grub, and the exact transcript from update-grub.
– Gilles
Jan 1 '11 at 17:00




Post the contents of /etc/default/grub, and the exact transcript from update-grub.
– Gilles
Jan 1 '11 at 17:00












(thoughts after adding solution): It might actually be that the problem was that I hadn't updated /etc/fstab in the chroot (this would be consistent with update-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.
– Janus
Jan 3 '11 at 1:12




(thoughts after adding solution): It might actually be that the problem was that I hadn't updated /etc/fstab in the chroot (this would be consistent with update-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.
– Janus
Jan 3 '11 at 1:12












just a note: do not forget to unmount /mnt/newroot before reboot!
– Giacomo Tesio
May 16 '13 at 20:31




just a note: do not forget to unmount /mnt/newroot before reboot!
– Giacomo Tesio
May 16 '13 at 20:31












Here are instructions on how to move your root partition / to new nvme drive, while keeping the /home on hdd. lucasmanual.com/blog/…
– Lucas
Sep 17 at 2:51




Here are instructions on how to move your root partition / to new nvme drive, while keeping the /home on hdd. lucasmanual.com/blog/…
– Lucas
Sep 17 at 2:51










3 Answers
3






active

oldest

votes

















up vote
21
down vote



accepted










Mount basic filesystems and copy/modify files while chrooting like:



  • /dev (mount -o bind /dev/ /path/to/chroot/dev)

  • /proc (mount -t proc none /path/to/chroot/proc)

  • /sys (mount -t sysfs none /path/to/chroot/sys)

IIRC that worked for me while installing Grub 2 in arch and numerous times on Gentoo. Then after chroot to /path/to/chroot command was simply:



grub-install /dev/<boot_disk>



As of lvm2 (and I belive madm but I haven't used it) the configuration is stored on disk. There is configuration what should be read to discover devices. Assuming your devices are in standard locations (/dev/sd* or /dev/hd*) there should be no problem.




PS. I would not trust simple cp of live system as there are several places where it can go wrong:



  • Forgot to change /etc/fstab and other useful files

  • Files changed during access

  • Coping garbage (/tmp etc.)





share|improve this answer




















  • Thanks. So basically, you are saying I do a sloppy chroot :) I'll give it a try with a proper chroot. cp -ax should be fine (maybe after dropping to single user runlevel) according to this old howto: tldp.org/HOWTO/Hard-Disk-Upgrade/copy.html
    – Janus
    Jan 2 '11 at 14:52










  • Worked a charm! Thank you very much for the help.
    – Janus
    Jan 2 '11 at 15:50






  • 1




    @Janus: I'd copy data from Live distro to be on safe side. I'm glad however it worked.
    – Maciej Piechotka
    Jan 2 '11 at 20:37










  • I had to do update-grub before install-grub.
    – Aryeh Leib Taurog
    Aug 8 '13 at 17:08

















up vote
3
down vote













you can install grub from live distro without chrooting:



grub-install /dev/hda --root-directory=/mnt/guest/





share|improve this answer




















  • Thanks. I'm not sure this would work here: as I understand it, grub-install only updates the grub image files and writes the MBR: In particular, grub.cfg is not updated. As I commented above, mounting the special dirs might be overkill, but I still think the chroot is the way to update grub.cfg in a simple way?
    – Janus
    Jan 4 '11 at 7:23










  • Yes, this didn't work for me either. You have to get update-grub to work and that one does not have --root-directory or something, no?
    – Mitar
    Jun 30 '17 at 6:40

















up vote
0
down vote













BTW if you are adding a partition (like a windows) on which you don't want grub to write a in the boot sector, but you want grub to know about it when your computer boots, you can re-scan the partitions and generate a new grub.cfg file by using the grub_mkconfig command as follows in a terminal session




cd /boot/grub



sudo cp grub.cfg ./grub.cfg.old



sudo grub_mkconfig -o ./grub.cfg




Now when you boot off of your current linux partition (that had grub booting it) it will now know about the other partition.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f5297%2fdebian-grub2-moving-root-partition-to-new-drive%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    21
    down vote



    accepted










    Mount basic filesystems and copy/modify files while chrooting like:



    • /dev (mount -o bind /dev/ /path/to/chroot/dev)

    • /proc (mount -t proc none /path/to/chroot/proc)

    • /sys (mount -t sysfs none /path/to/chroot/sys)

    IIRC that worked for me while installing Grub 2 in arch and numerous times on Gentoo. Then after chroot to /path/to/chroot command was simply:



    grub-install /dev/<boot_disk>



    As of lvm2 (and I belive madm but I haven't used it) the configuration is stored on disk. There is configuration what should be read to discover devices. Assuming your devices are in standard locations (/dev/sd* or /dev/hd*) there should be no problem.




    PS. I would not trust simple cp of live system as there are several places where it can go wrong:



    • Forgot to change /etc/fstab and other useful files

    • Files changed during access

    • Coping garbage (/tmp etc.)





    share|improve this answer




















    • Thanks. So basically, you are saying I do a sloppy chroot :) I'll give it a try with a proper chroot. cp -ax should be fine (maybe after dropping to single user runlevel) according to this old howto: tldp.org/HOWTO/Hard-Disk-Upgrade/copy.html
      – Janus
      Jan 2 '11 at 14:52










    • Worked a charm! Thank you very much for the help.
      – Janus
      Jan 2 '11 at 15:50






    • 1




      @Janus: I'd copy data from Live distro to be on safe side. I'm glad however it worked.
      – Maciej Piechotka
      Jan 2 '11 at 20:37










    • I had to do update-grub before install-grub.
      – Aryeh Leib Taurog
      Aug 8 '13 at 17:08














    up vote
    21
    down vote



    accepted










    Mount basic filesystems and copy/modify files while chrooting like:



    • /dev (mount -o bind /dev/ /path/to/chroot/dev)

    • /proc (mount -t proc none /path/to/chroot/proc)

    • /sys (mount -t sysfs none /path/to/chroot/sys)

    IIRC that worked for me while installing Grub 2 in arch and numerous times on Gentoo. Then after chroot to /path/to/chroot command was simply:



    grub-install /dev/<boot_disk>



    As of lvm2 (and I belive madm but I haven't used it) the configuration is stored on disk. There is configuration what should be read to discover devices. Assuming your devices are in standard locations (/dev/sd* or /dev/hd*) there should be no problem.




    PS. I would not trust simple cp of live system as there are several places where it can go wrong:



    • Forgot to change /etc/fstab and other useful files

    • Files changed during access

    • Coping garbage (/tmp etc.)





    share|improve this answer




















    • Thanks. So basically, you are saying I do a sloppy chroot :) I'll give it a try with a proper chroot. cp -ax should be fine (maybe after dropping to single user runlevel) according to this old howto: tldp.org/HOWTO/Hard-Disk-Upgrade/copy.html
      – Janus
      Jan 2 '11 at 14:52










    • Worked a charm! Thank you very much for the help.
      – Janus
      Jan 2 '11 at 15:50






    • 1




      @Janus: I'd copy data from Live distro to be on safe side. I'm glad however it worked.
      – Maciej Piechotka
      Jan 2 '11 at 20:37










    • I had to do update-grub before install-grub.
      – Aryeh Leib Taurog
      Aug 8 '13 at 17:08












    up vote
    21
    down vote



    accepted







    up vote
    21
    down vote



    accepted






    Mount basic filesystems and copy/modify files while chrooting like:



    • /dev (mount -o bind /dev/ /path/to/chroot/dev)

    • /proc (mount -t proc none /path/to/chroot/proc)

    • /sys (mount -t sysfs none /path/to/chroot/sys)

    IIRC that worked for me while installing Grub 2 in arch and numerous times on Gentoo. Then after chroot to /path/to/chroot command was simply:



    grub-install /dev/<boot_disk>



    As of lvm2 (and I belive madm but I haven't used it) the configuration is stored on disk. There is configuration what should be read to discover devices. Assuming your devices are in standard locations (/dev/sd* or /dev/hd*) there should be no problem.




    PS. I would not trust simple cp of live system as there are several places where it can go wrong:



    • Forgot to change /etc/fstab and other useful files

    • Files changed during access

    • Coping garbage (/tmp etc.)





    share|improve this answer












    Mount basic filesystems and copy/modify files while chrooting like:



    • /dev (mount -o bind /dev/ /path/to/chroot/dev)

    • /proc (mount -t proc none /path/to/chroot/proc)

    • /sys (mount -t sysfs none /path/to/chroot/sys)

    IIRC that worked for me while installing Grub 2 in arch and numerous times on Gentoo. Then after chroot to /path/to/chroot command was simply:



    grub-install /dev/<boot_disk>



    As of lvm2 (and I belive madm but I haven't used it) the configuration is stored on disk. There is configuration what should be read to discover devices. Assuming your devices are in standard locations (/dev/sd* or /dev/hd*) there should be no problem.




    PS. I would not trust simple cp of live system as there are several places where it can go wrong:



    • Forgot to change /etc/fstab and other useful files

    • Files changed during access

    • Coping garbage (/tmp etc.)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 2 '11 at 0:31









    Maciej Piechotka

    11k64276




    11k64276











    • Thanks. So basically, you are saying I do a sloppy chroot :) I'll give it a try with a proper chroot. cp -ax should be fine (maybe after dropping to single user runlevel) according to this old howto: tldp.org/HOWTO/Hard-Disk-Upgrade/copy.html
      – Janus
      Jan 2 '11 at 14:52










    • Worked a charm! Thank you very much for the help.
      – Janus
      Jan 2 '11 at 15:50






    • 1




      @Janus: I'd copy data from Live distro to be on safe side. I'm glad however it worked.
      – Maciej Piechotka
      Jan 2 '11 at 20:37










    • I had to do update-grub before install-grub.
      – Aryeh Leib Taurog
      Aug 8 '13 at 17:08
















    • Thanks. So basically, you are saying I do a sloppy chroot :) I'll give it a try with a proper chroot. cp -ax should be fine (maybe after dropping to single user runlevel) according to this old howto: tldp.org/HOWTO/Hard-Disk-Upgrade/copy.html
      – Janus
      Jan 2 '11 at 14:52










    • Worked a charm! Thank you very much for the help.
      – Janus
      Jan 2 '11 at 15:50






    • 1




      @Janus: I'd copy data from Live distro to be on safe side. I'm glad however it worked.
      – Maciej Piechotka
      Jan 2 '11 at 20:37










    • I had to do update-grub before install-grub.
      – Aryeh Leib Taurog
      Aug 8 '13 at 17:08















    Thanks. So basically, you are saying I do a sloppy chroot :) I'll give it a try with a proper chroot. cp -ax should be fine (maybe after dropping to single user runlevel) according to this old howto: tldp.org/HOWTO/Hard-Disk-Upgrade/copy.html
    – Janus
    Jan 2 '11 at 14:52




    Thanks. So basically, you are saying I do a sloppy chroot :) I'll give it a try with a proper chroot. cp -ax should be fine (maybe after dropping to single user runlevel) according to this old howto: tldp.org/HOWTO/Hard-Disk-Upgrade/copy.html
    – Janus
    Jan 2 '11 at 14:52












    Worked a charm! Thank you very much for the help.
    – Janus
    Jan 2 '11 at 15:50




    Worked a charm! Thank you very much for the help.
    – Janus
    Jan 2 '11 at 15:50




    1




    1




    @Janus: I'd copy data from Live distro to be on safe side. I'm glad however it worked.
    – Maciej Piechotka
    Jan 2 '11 at 20:37




    @Janus: I'd copy data from Live distro to be on safe side. I'm glad however it worked.
    – Maciej Piechotka
    Jan 2 '11 at 20:37












    I had to do update-grub before install-grub.
    – Aryeh Leib Taurog
    Aug 8 '13 at 17:08




    I had to do update-grub before install-grub.
    – Aryeh Leib Taurog
    Aug 8 '13 at 17:08












    up vote
    3
    down vote













    you can install grub from live distro without chrooting:



    grub-install /dev/hda --root-directory=/mnt/guest/





    share|improve this answer




















    • Thanks. I'm not sure this would work here: as I understand it, grub-install only updates the grub image files and writes the MBR: In particular, grub.cfg is not updated. As I commented above, mounting the special dirs might be overkill, but I still think the chroot is the way to update grub.cfg in a simple way?
      – Janus
      Jan 4 '11 at 7:23










    • Yes, this didn't work for me either. You have to get update-grub to work and that one does not have --root-directory or something, no?
      – Mitar
      Jun 30 '17 at 6:40














    up vote
    3
    down vote













    you can install grub from live distro without chrooting:



    grub-install /dev/hda --root-directory=/mnt/guest/





    share|improve this answer




















    • Thanks. I'm not sure this would work here: as I understand it, grub-install only updates the grub image files and writes the MBR: In particular, grub.cfg is not updated. As I commented above, mounting the special dirs might be overkill, but I still think the chroot is the way to update grub.cfg in a simple way?
      – Janus
      Jan 4 '11 at 7:23










    • Yes, this didn't work for me either. You have to get update-grub to work and that one does not have --root-directory or something, no?
      – Mitar
      Jun 30 '17 at 6:40












    up vote
    3
    down vote










    up vote
    3
    down vote









    you can install grub from live distro without chrooting:



    grub-install /dev/hda --root-directory=/mnt/guest/





    share|improve this answer












    you can install grub from live distro without chrooting:



    grub-install /dev/hda --root-directory=/mnt/guest/






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 3 '11 at 17:31









    jet

    80658




    80658











    • Thanks. I'm not sure this would work here: as I understand it, grub-install only updates the grub image files and writes the MBR: In particular, grub.cfg is not updated. As I commented above, mounting the special dirs might be overkill, but I still think the chroot is the way to update grub.cfg in a simple way?
      – Janus
      Jan 4 '11 at 7:23










    • Yes, this didn't work for me either. You have to get update-grub to work and that one does not have --root-directory or something, no?
      – Mitar
      Jun 30 '17 at 6:40
















    • Thanks. I'm not sure this would work here: as I understand it, grub-install only updates the grub image files and writes the MBR: In particular, grub.cfg is not updated. As I commented above, mounting the special dirs might be overkill, but I still think the chroot is the way to update grub.cfg in a simple way?
      – Janus
      Jan 4 '11 at 7:23










    • Yes, this didn't work for me either. You have to get update-grub to work and that one does not have --root-directory or something, no?
      – Mitar
      Jun 30 '17 at 6:40















    Thanks. I'm not sure this would work here: as I understand it, grub-install only updates the grub image files and writes the MBR: In particular, grub.cfg is not updated. As I commented above, mounting the special dirs might be overkill, but I still think the chroot is the way to update grub.cfg in a simple way?
    – Janus
    Jan 4 '11 at 7:23




    Thanks. I'm not sure this would work here: as I understand it, grub-install only updates the grub image files and writes the MBR: In particular, grub.cfg is not updated. As I commented above, mounting the special dirs might be overkill, but I still think the chroot is the way to update grub.cfg in a simple way?
    – Janus
    Jan 4 '11 at 7:23












    Yes, this didn't work for me either. You have to get update-grub to work and that one does not have --root-directory or something, no?
    – Mitar
    Jun 30 '17 at 6:40




    Yes, this didn't work for me either. You have to get update-grub to work and that one does not have --root-directory or something, no?
    – Mitar
    Jun 30 '17 at 6:40










    up vote
    0
    down vote













    BTW if you are adding a partition (like a windows) on which you don't want grub to write a in the boot sector, but you want grub to know about it when your computer boots, you can re-scan the partitions and generate a new grub.cfg file by using the grub_mkconfig command as follows in a terminal session




    cd /boot/grub



    sudo cp grub.cfg ./grub.cfg.old



    sudo grub_mkconfig -o ./grub.cfg




    Now when you boot off of your current linux partition (that had grub booting it) it will now know about the other partition.






    share|improve this answer
























      up vote
      0
      down vote













      BTW if you are adding a partition (like a windows) on which you don't want grub to write a in the boot sector, but you want grub to know about it when your computer boots, you can re-scan the partitions and generate a new grub.cfg file by using the grub_mkconfig command as follows in a terminal session




      cd /boot/grub



      sudo cp grub.cfg ./grub.cfg.old



      sudo grub_mkconfig -o ./grub.cfg




      Now when you boot off of your current linux partition (that had grub booting it) it will now know about the other partition.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        BTW if you are adding a partition (like a windows) on which you don't want grub to write a in the boot sector, but you want grub to know about it when your computer boots, you can re-scan the partitions and generate a new grub.cfg file by using the grub_mkconfig command as follows in a terminal session




        cd /boot/grub



        sudo cp grub.cfg ./grub.cfg.old



        sudo grub_mkconfig -o ./grub.cfg




        Now when you boot off of your current linux partition (that had grub booting it) it will now know about the other partition.






        share|improve this answer












        BTW if you are adding a partition (like a windows) on which you don't want grub to write a in the boot sector, but you want grub to know about it when your computer boots, you can re-scan the partitions and generate a new grub.cfg file by using the grub_mkconfig command as follows in a terminal session




        cd /boot/grub



        sudo cp grub.cfg ./grub.cfg.old



        sudo grub_mkconfig -o ./grub.cfg




        Now when you boot off of your current linux partition (that had grub booting it) it will now know about the other partition.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 16 '13 at 21:55









        user129087

        1




        1



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f5297%2fdebian-grub2-moving-root-partition-to-new-drive%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?