1
  • I have a one disk, no RAID, no LVM system based on Debian Squeeze (my old system).
  • I created a RAID array (RAID 5, 4 HDDs) with mdadm (my new system).
  • I installed LVM2 on the new system and created several LVs.
  • I migrated the folders (/,/boot,/home,/var/,/tmp,/usr) of the old system in the respective LVs (lv_root,lv_boot,lv_home,lv_var,lv_tmp,lv_usr) by using rsync.
  • Note that my boot is in LVM, not outside.

How do I proceed for the following tasks (I didn't find any good tutorials for my level of knowledge):

  • Once the RAID array is created, how can I build a mdadm.conf file on the new system?
  • How can I create a fstab file on the new system
  • How can I install Grub2 in /boot and configure the four disks in order to boot from any?

After these tasks, I should be able to shutdown my machine, remove the HDD with the old system, restart the machine and the new system should boot.

Bertaud
  • 245
  • 1
  • 3
  • 12
  • So the new system is a installation from scratch (Debian Wheezy?)? What folders did you migrate from the old system - just `/home` and stuff like that, or also parts of the system itself (`/usr`, ...)? If it's an installation from scratch, the Debian installer should have taken care of the tasks that you list. – Martin von Wittich Jan 28 '14 at 17:31
  • see my new text according to your question. It's not a scratch. – Bertaud Jan 28 '14 at 17:45

1 Answers1

3

So you're inside a rescue system now? You need mount all these LVs somewhere, for example to /mnt/target:

  • lv_root -> /mnt/target/
  • lv_boot -> /mnt/target/boot
  • lv_home -> /mnt/target/home
  • ...

Then you need to bind-mount the kernel filesystems:

for i in proc sys run dev; do mount --bind /$i /mnt/target/$i; done

Now you can change into this "dead" system with chroot:

chroot /mnt/target

You are now inside the system, as if you had booted into it; that is, / is now no longer the old / from your rescue system, but the root LV.

Create the mdadm.conf:

/usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf

Check it manually with an editor to see if everythings OK.

Create the device.map for grub:

grub-mkdevicemap

Check that manually too. Install grub to all disks (put in the correct disk names here):

grub-install /dev/sda
grub-install /dev/sdb
...

Manually adapt you /etc/fstab so that all LVs are mounted to their correct mount points.

Regenerate the grub config and the initramfs:

update-grub
update-initramfs -u
Martin von Wittich
  • 13,857
  • 6
  • 51
  • 74
  • Very good info for me. I am inside the old system, not a rescue system. I didn't migrate the content of the /sys et /proc folders. Shall I do it ? Chroot was missing in my knowledge ! How can I terminate this function ? Before the device.map creation, I suppose that I must install or verify that Grub2 is in the boot folder, correct ? – Bertaud Jan 28 '14 at 23:06
  • @Bertaud It's usually wise to do migrations like these from some kind of rescue system, because a) you're guaranteed that the old system won't change during or after you've copied the files to the new system (for example, if you have a mail server running, it might accept an incoming mail after you've already copied the mail spool. This mail is lost when you switch to the new system) and b) you can access the whole filesystem without having to worried about overmounted folders like `/dev`. – Martin von Wittich Jan 29 '14 at 00:00
  • "I didn't migrate the content of the /sys et /proc folders. Shall I do it?" - no, do not try to copy the *contents* of `/proc` and `/sys`, because these are virtual filesystems. You really don't want to try to copy files like `/proc/kcore` ;). Instead, create them as empty folders in the target filesystem, and then mount-bind them so you can successfully `chroot` into it. – Martin von Wittich Jan 29 '14 at 00:03
  • Ok. I will try tomorow because it's 01:00 am ;-) I appreciated your explanation. Gute Nacht. – Bertaud Jan 29 '14 at 00:08
  • my mdadm.conf seems to be strange: ARRAY /dev/md/0 metadata=1.2 UUID=... name=... I expected /dev/md0 – Bertaud Jan 29 '14 at 13:39
  • I don't know the exact reason behind this, but I'd say that's fine. I've just checked on a recently installed server in our company - it does say `/dev/md/0` in `mdadm.conf` too, but the RAID device is called `/dev/md0`. It probably has to do something with the 1.2 metadata. – Martin von Wittich Jan 29 '14 at 13:46
  • Ok. no line "DEVICE": correct also ? – Bertaud Jan 29 '14 at 13:53
  • Yep, should be correct. – Martin von Wittich Jan 29 '14 at 13:54
  • /boot/grub/device.map has a reference to my hdd "old system": shall I get rid that line ? (hd1) /dev/disk/by-id/ata-wdc... – Bertaud Jan 29 '14 at 14:00
  • I haven't found any explanation for `/dev/md/0` instead of `/dev/md0`, so I've posted a question: http://unix.stackexchange.com/questions/111479/linux-md-raid-dev-md0-vs-dev-md-0 – Martin von Wittich Jan 29 '14 at 14:00
  • @Bertaud yes, I usually delete those. It probably won't do any harm though. – Martin von Wittich Jan 29 '14 at 14:00
  • In /etc/fstab, after a blkid, shall I write /dev/md0: UUID=... or/and each lines /dev/mapper/myRaid-root: UUID= ... – Bertaud Jan 29 '14 at 14:12
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/12730/discussion-between-martin-von-wittich-and-bertaud) – Martin von Wittich Jan 29 '14 at 14:26
  • just tell me how to answer to your questions in the chat ! – Bertaud Jan 29 '14 at 14:30