Shrinking Root with Software Array, then Replacing Root with another Root Image
0. Start console. This is a hardware thing, whereby you can monitor the system console even during a reboot. For example:
ssh console@slcradar03-sp.con.slc.ebay.com
start /SP/console
escape + ( gets out of the console. then, you can do a “reset/SYS” to reboot
- Take down the raid superblock:
- turn off swap
- swapoff -a
- Check swaps to confirm
- cat /proc/swaps
- Check state of software raid
- cat /proc/mdstat
- Stop the md1
- mdadm –stop /dev/md1 (will be restarted if you reboot)
- Check/confirm previous command
- cat /proc/mdstat
- Examin /dev/sdb5
- mdadm -E /dev/sdb5
- makes it so that the device doesn’t return on reboot.
- mdadm –zero-superblock /dev/sdb5
- mdadm –zero-superblock /dev/sda5
- Nuke sda2 and sda5
- fdisk /dev/sda
- p (to print)
- d 5 (delete sda5)
- d 2 (delete sda2)
- w (confirm)
- q (quit)
- partprobe (from commandline. Deals with kernel still having locks on the drive. Saves you from having to reboot. Partprobe will warn you if you still need to reboot)
- Repeat for /dev/sdb
- update /etc/fstab
- remove the swap line
- comment out the line with UUID on the root partition
- replace line with /dev/md0 ext4 errors=remount-ro 0 1 (tell it to boot with /dev/md0 instead of uuid)
- Make grub show us console messages on boot
- vi /etc/default/grub
- find line GRUB_CMDLINE_LINUX, add “console=ttyS0,9600n8” <–S0 is serial port 0. 9600 is speed
- update-grub
- verify in /boot/grub/grub.cfg
- remove everything between /30_cs-prober begin and end
- reboot
- In grub, do e. Nuke the word quiet if you want to get detailed information on boot. Control X to boot.
- Remove sdb1 from software raid
- mdmadm —remove /dev/md0 /dev/sdb1 (this will fail, becaues it’s healthy, so…)
- mdmadm –fail /dev/md0 /dev/sdb1
- try the remove command again
- If you cat /proc/mdstat, you will no longer see /dev/sdb1
- mdadm –zero-superblock /dev/sdb1 (so that sdb1 no longer thinks it belongs to md0)
- verify with: mdadm -E /dev/sdb1
- mount sdb1, and backup its content
- mkdir /mnt/tmp
- mount /dev/sdb1 /mnt/tmp
- cd /mnt/tmp
- tar cvzf /mnt/root.tgz .
- umount /mnt/tmp
- kill the drive
- fdisk /dev/sdb
- d
- n (new)
- p
- 1
- 2048
- +5G
- fd
- p
- Create a second partition with the remaining space
- n
- p
- get the first sector from the last sector printed out above
- leave default on end sector
- 8e (LVM type)
- w (commit)
- mkfs.ext4 /dev/sdb1
- mount it again, and restore data
- mount /dev/sdb1 /mnt/tmp
- cd /mnt/tmp
- tar xvzf /mnt/root.tgz
- Tell machine to boot with sdb1
- cd /mnt/tmp
- vi /etc/fstab
- change /dev/md0 to /dev/sdb1
- reboot (make sure console is open)
- At grub, use e. Remove the search line. find the line with “linux /boot”, remove UUID and replace with root=/dev/sdb1
- mount /dev/md0 /mnt/temp
- copy root.tgz
- cp /mnt/temp/root.tgz /mnt
- unmount temp
- Delete whole concept of md0
- mdadm –stop /dev/md0
- to verify, cat /proc/mdstat
- mdadm –zero-superblock /dev/sda1
- If you now scan superblock with mdadm -Es, you shouldn’t see anything
- fdisk
- u
- We want ot make sda look exactly like sub.
- dd if=/dev/sdb of=/dev/sda bs=512 count=1 (BE CAREFUL!)
- partprobe
- verify with fdisk that /dev/sda and /dev/sdb are the same
- Create a raid array
- mdadm –create /dev/md0 –level 1 -n 2 /dev/sda1 missing
- verify using cat /proc/mdstat
- mkfs.ext4 /dev/md0
- mount /dev/md0 temp
- cd /mnt/temp
- tar xvzf ../root.tgz
- mdadm -Es > etc/mdadm/mdadm.conf (the mdadm.conf inside md0)
- chroot /mnt/temp
- update-initramfs -u
- cd /boot/grub
- vi grub.cfg
- nuke the search line
- find the line with the UUID, replace with root=/dev/md0
sync - umount /mnt/temp
- reboot
- Add sdb1 to md0 and wait for stuff to sync
- mdadm –manage /dev/md0 –add /dev/sdb1 (now, wait for sync…..)
- mdadm –create /dev/md1 –level 1 -n 2 /dev/sda2 /dev/sdb2 (wait for stuff to sync….)
- Create LVM
- Install lvm2 and push dependencies and install the debs according to the instructions at Virtual Machines Administration#AddingAdditionalPackages
- Or you can just log into radaradm@tnsar-imagehost, and copy the 3 deb files that will enable lvm on ops image in ops-image-lvm2-debs
- pvcreate /dev/md1 9create physical volume)
- vgcreate volmd1 /dev/md1 (create volume group)
- lvcreate -n swap -L 32G volmd1 (create swap logical volume)
- lvcreate -n ebay -L 200G volmd1 (create logical volume ebay)
- To verify, run pvscan, vgscan, lvscan
- mkswap /dev/mapper/volmd1-swap
- mkfs.ext4
L “/ebay” /dev/mapper/volmd1ebay - mdadm -Es > /etc/mdadm/mdadm.conf (so reboot will sitll see md1)
- edit /etc/fstab to auto-mount if required
- Add radaradm key to new machine’s /root/.ssh/auth_keys (on /dev/md0 aka opsroot)
- Deploy our own vdi file
- deploy_host host.vdi <machine name>
- update-grub (if you don’t see your os, check /etc/grub.d/ to see if 30_os-prober is executable
- verify. Look at /boot/grub/grub.cfg
- edit /boot/grub/grub.cfg, set default=”4″ (or whatever number you want the default to be
- turn off swap