How do I boot ubuntu?

How to get my Dell Ubuntu server to boot from a different drive?

  • I have an Ubuntu server. It's a Dell PowerEdge with a PERC 6 RAID controller. I'm trying to get it to boot to a different drive, and grub doesn't seem to be cooperating - it appears to attempt to boot to the correct volume and partition and then bonks out when mounting /proc - what gives? Here's http://mike.teczno.com/img/geo-proc-problem.jpg. I'm using the UUIDs of each volume in my grub configuration, and the volume I want to boot from has separate /boot and root partitions. I've been hand-editing my various grub files: devices.map, menu.lst, etc., and have what appears to be the right UUIDs in the right places: the boot partition under "uuid", and the *root* partition on the kernel options. I've also got what I think are the right entries in the fstab, and I can get into the grub shell at boot time and poke around enough to confirm that my (hd0,0) is where I think it is and that the UUIDs all appear correct. I can provide all these actual files if it would be useful. The existing and working boot drive is a RAID5 while the new one is a single physical volume that I'd like to use temporarily while shuffling around some other drives. Once I get this working, my plan is to do it a few more times in order to shuffle all the various files onto their intended disks.

  • Answer:

    Got a little more time now and can expand a little. If I were going to use a working Debian-derived installation to clone itself onto a new disk drive, I'd get a root shell on it and do these steps: 1. Partition the new disk with cfdisk. 2. Create empty filesystems in the new partitions with mkfs and mkswap. 3. Mount the partition that is to hold the clone's root filesystem on /mnt. 4. cp -ax / /mnt to copy the working root filesystem only to /mnt. -a recurses while preserving existing metadata, -x stops the recursion from descending into non-root filesystems like /dev and /proc and /mnt itself. 5. Mount all the clone's subsidiary filesystem partitions to appropriate spots inside /mnt (e.g. /mnt/home, /mnt/usr or whatever). 6. Use more cp -ax commands to copy each of the source system's mounted filesystems (except /mnt itself) to their corresponding locations under /mnt. 7. for d in dev proc sys; do mount --bind /$d /mnt/$d; done so that when I chroot into the clone's filesystem I'll still be working with the original system's processes, devices and whatnot. 8. chroot /mnt to start making necessary changes inside the clone. 9. Hand-edit /etc/fstab and /boot/grub/menu.lst (now that we're inside a chroot, these are the clone's copies), and change all the UUIDs to make them match the clone's partitions rather than the original's. 10. update-initramfs -u -k all - this is the step I suspect you missed. It makes sure that the version of /etc/fstab inside the clone's initial (boot-time) RAMdisk filesystem matches what will replace it once the real root partition gets mounted. 11. grub-install /dev/sdX where sdX is the device name for the whole clone disk (not any of its partitions). 12. Ctrl-D out of the chroot. 13. umount /mnt/dev/ /mnt/proc /mnt/sys /mnt and the new disk is ready to try booting from. On preview: I think all you'll probably need are steps 7, 8, 10, 12 and 13; looks like you've already done the equivalent of the rest.

migurski at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

cp is indeed deprecated in general for Unix cloning, but as far as I know the Gnu cp that comes with Linux is perfectly well-behaved; there's no particular need to jump through tar or cpio hoops to work around deficiencies it simply doesn't have. Using dd (or, better, http://www.gnu.org/software/ddrescue/ddrescue.html) is a good idea when (a) the system you're cloning is mostly full - otherwise you waste a lot of time copying empty space (b) the clone's mount tree is the same shape as the source's and (c) you'll be physically disconnecting the source drives before attempting to boot the clone - dd clones all the filesystem UUIDs along with everything else. It probably is a bit rude trying to do install-grub from inside a chroot with a /etc/mtab that tells lies, but whatever you've done seems to have worked in any case; you're way past grub in the boot sequence when you strike your mount problem, which in my opinion is almost certainly caused by booting up with a copy of your original installation's initrd. This in turn will contain a copy of your original installation's /etc/fstab, including all the original UUIDs, which will make it impossible for init to find your clone's real root filesystem, which makes that impossible to mount, which makes all its mount points unavailable, which makes everything else impossible to mount. Running update-initramfs from inside the chroot should copy the clone's /etc/fstab into the clone's initrd image, and as long as that fstab contains a correct reference to the clone's root filesystem's UUID, all should then be well. When you rsync'd it probably skipped copying /proc /sys /dev because they're not normal filesystems. So your new /root is simply missing a empty directory named proc that needs to be there for the the real /proc to get mounted on via fstab. I have experimental results that show that cp -ax does not cause this trouble. If you've got a second filesystem mounted on /foo/bar and you cp -ax /foo /qux you will end up with an empty directory at /qux/foo/bar (whcih makes sense; -x means "stay on one filesystem" and in the original /foo filesystem there is an empty mount-point directory at /foo/bar).

flabdablet

I was clearly labouring under the misapprehension that it was even fluffier still! Thanks for the clear exposition.

flabdablet

Doesn't look like a grub problem to me; looks like an initrd issue. How did you go about getting your system onto the new disk, and was update-initramfs -u -k all involved at any stage?

flabdablet

How? I don't think you can do this anymore, but it's easier to think about the old days when you could boot a Linux system from a single floppy disk. The kernel is built with support compiled in for a simple extfs filesystem. Parts of it are compressed and a block of code with the compressed size and the uncompressor/loader code is stuck on the front. You dd that out to a floppy and say it takes up the first 500 sectors. Then you build a extfs filesystem starting at block 501 to the end. The computer boots, load the first sector and executes it. The boot code uncompresses and loads the kernel into memory, then loads the root inode of the following filesysem into the kernel's / inode space and passes execution off to the loaded kernel. The kernel then looks for an init or failing that a sh in the only filesystem it knows about and presto! running linux. Later on in the HD age, the kernel has a couple of set offset places that hold the device information for the / device, and you have a MBR based boot loader. You don't bother with compression. You build your kernel with the filesystem support for your / filesystem, then (ls -l /dev/sda1 => brw-rw---- 1 root disk 8, 1 2011-04-30 02:09 /dev/sda1) you patch your kernel with and give it the 8,1. Then you patch the MBR loader with the raw disk blocks location of the kernel. The computer boots, the MBR runs, it loads the kernel into memory, the kernel looks for device 8,1 and loads the / inode from there and continues with the init hunting process. Now with things like GRUB and initrd, grub will load the kernel, then uncompress initrd into memory and then patch the kernel with the device info for (brw-rw---- 1 root disk 1, 0 2011-04-30 02:09 /dev/ram0) IIRC. Anyway, the kernel gets the / inode of a in-memory filesystem with bunches of modules and fru-fru, loads the init from that. The init on the initrd has access to the libraries and programs needed to probe the machine to determine which special modules to load (raid, encryption, lvm), then processes the arguments passed in by the bootloader letting you dynamically control which / filesystem you want to use among other things. Then it does a 'pivot' to possibly remove the initrd filesystem, and chain on to the realroot init. By now, Ubuntu's initrd has so much fluf in it that it is practically it's own OS.

zengargoyle

So now I've found out more or less how, and my assumption that the initrd contains an /etc/fstab is indeed dead wrong. Sorry for the mislead. For the record: the init script inside the Debian initrd finds out where to look for the real root filesystem by parsing the root= command line option passed to the kernel, which it extracts from /proc/cmdline after doing mount -t proc -o nodev,noexec,nosuid none /proc very early on. However, the fact remains that I have often needed to do a chrooted update-initramfs before a cloned system would boot properly for me. I'd always assumed it was fstab. Now I'm assuming it's actually down to some difference in the modules required for startup. The initrd images are just gzip-compressed cpio archives, so it's pretty easy to find out what your chrooted update-initramfs actually did, if you're interested (I am!). After you've exited the chroot but before unmounting /mnt, you can do cd /tmp mkdir initrd-orig initrd-clone cd initrd-orig zcat /boot/initrd.img* | cpio -i cd ../initrd-clone zcat /mnt/boot/initrd.img* | cpio -i cd .. diff -r initrd-orig initrd-clone | less If you've got more than one initrd.img* file in /boot, put in the whole name of the one you've actually been working with (tab-completion fails for me, probably because zcat wants its argument filenames to end in .gz).

flabdablet

It simply mounts root How?

flabdablet

flabdablet, I really don't think fstab has anything to do with initrd. At least not unless Ubuntu Server is different than Ubuntu Desktop and CentOS and Gentoo and just plain old generic kernel. The initrd just holds kernel modules needed to get the root filesystem mounted (esoteric fstype modules like reiser/crypt) and on the fru-fru systems a fancy graphics screen to hide the boot messages. It simply mounts root, rebinds proc and sys that it mounted in its fakeroot so it could do all the fru-fru stuff, finds a suitable /sbin/init, /bin/init, /init, /bin/sh and then pivots the filesystem over and execs init. I looked at the initrd for my Ubuntu Desktop and that is what it does. I've mix and matched various distros kernel/initrd combos across different roots and even different distros and bare kernels with no modules with no problems. The initrd if any just needs to match the kernel for module loading.

zengargoyle

cat /proc/mounts is really valuable, btw - didn't know about it.

migurski

So good, thanks everyone - flabdablet and zengargoyle I think your advice was exactly right! I ran initrd and I also made sure that /proc exists ahead of time on the new system. It got well past the /proc stage, running into problems only when one of the other volumes on the system (the one where I moved /home to) needed to be fscked. I let that run for a bit and then switched back to the original drives to do a bit more maintenance. I'm going to complete the switch sometime this weekend.

migurski

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.