2

Context:

  • a few remote debian 7 32bit servers
  • only accessible via SSH
  • more than half of the disks are empty
  • 1 whole disk partition per server
  • small maintenance window, cannot be down for long
  • ext4 filesystems
  • NOTE: I am developing my solution using a VirtualBox VM, but the servers are straight bare metal.

Goal: upgrade OS to debian 9+, in a non-destructive way, since ideally machine needs to stay up until the reboot into the new OS.


So, for each servers, I plan (other suggestions welcomed) to do the following:

  1. Shrink the current deb 7 rootfs with resize2fs to a bit less than 1/2 the partition size
  2. Shrink the partition to clear out 1/2 the disk
  3. Partition the newly freed space (/, /home, swap) and Install LVM2
    (create VG,LV etc.) and Debian 9

My problem is that resize2fs can only shrink ext4 fs IF unmounted. So the idea is to use initrd image or initramfs to call resize2fs on the unmounted /dev/sda1 during the GRUB2 bootloading sequence.

I have built my own initrd image containing a static resize2fs binary and a shell script which calls it (and does other validations etc.), but I seem to have hit a snag trying to write the correct entry in the grub.cfg file to make it mount my initrd image and execute my resizing script on the unmounted /dev/sda1.

So my Question is:

What grub.cfg menuentry do I need to write in order to load my custom initrd image containing my /bin/resize.sh script and then execute it (the /bin/resize.sh)?

  • What I've done previously (and possibly risky?) is set up a temporary minimal filesystem in a ramdisk and pivot_root over to it, allowing unmount of the disk without losing SSH access. Used it before to completely change the root filesystem type, so shrinking should work. If you want to pursue that path let me know and I can write it up in the morning. – Bob Jan 22 '18 at 15:47
  • Also, whichever method you use, I'd suggest making sure you have backups that are up to date and restorable in case the worst happens. – Bob Jan 22 '18 at 15:49
  • Hi @Bob, indeed I read about using the pivot_root technique but I felt it was a bit more risky and complex (many steps) than simply doing the resizing from grub (ie: before mounting any partitions). I am trying to keep it relatively simple and also scriptable (ie: unattended execution if possible). That said I would definitely be interested in getting more details on the path you chose. Thanks in advance. – Martin Vincent Jan 22 '18 at 17:30
  • Ah, I found the one I based mine off, which is a pretty comprehensive guide (and works on systemd setups, unlike the one you linked). The only modification I made was generating the temporary root with debootstrap rather than cping existing files. For my purposes, having an interactive shell was more useful, both because my install was many steps and for testing/validation before rebooting. But of course if you'd rather automate it with an initrd that's equally valid - I can't help directly with that though, sorry. – Bob Jan 22 '18 at 23:40
  • 1
    Thanks again @Bob for your reply. I managed yo make it work using initrd with roughly the following steps: 1.create an initrd image file (unzip in ~/initrd an existing one, add a few files) an rezip with : debian7-32bits:~/initrd# find . | cpio -o -H newc | gzip -9 > /boot/initrd.img-3.2.0-5-486-resize2fs 2.create an entry in /boot/grub/grub.cfg like so : menuentry "run_once_resize_fs" { set root='(hd0,msdos1)'; insmod linux grub help kernel initrd; linux /boot/vmlinuz-3.2.0-5-486; initrd /boot/initrd.img-3.2.0-5-486-resize2fs; } – Martin Vincent Jan 23 '18 at 22:15
0

(@All: sorry, just realized I never came back to answer my question, so better late than ever, here it is.) Thanks again Bob for your help btw.

So, my solution was:

I managed yo make it work using initrd with roughly the following steps:

1.create an initrd image file (unzip in ~/initrd an existing one, add a few files) and rezip with :

debian7-32bits:~/initrd# find . | cpio -o -H newc | gzip -9 > /boot/initrd.img-3.2.0-5-486-resize2fs

2.create an entry in /boot/grub/grub.cfg like so :

debian7-32bits:~/initrd# menuentry "run_once_resize_fs" { set root='(hd0,msdos1)'; insmod linux grub help kernel initrd; linux  /boot/vmlinuz-3.2.0-5-486; initrd /boot/initrd.img-3.2.0-5-486-resize2fs; } 

2.create an entry in /boot/grub/grub.cfg like so :

I do not have the script (step 3.?) that would call the menu entry at boot, sadly, be it that it was 2 years ago and at a different workplace. Hopefully this can still help someone.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.