Fixing your Debian NAS from within initramfs-tools
The following article was contributed by John Cass. Note that John's instructions will also work on other NAS machines running Debian, such as QNAP devices.
I had a problem upgrading my Debian kernel to 2.6.32 on the D-Link DNS-323. The upgrade looked like it worked but on reboot I had a hung machine. I tried taking the disk out, putting it in my main machine and remaking the links in /boot to the previous kernel and initrd.img but it turns out that on the DNS-323 both kernel and initrd are actually stored in flash memory (the /boot disk files are where they are built and a useful archive but are not used during the boot process).
So I was stuck, and had to make a serial cable in order to find out what was going on. The instructions here and here were very useful and the CA-42 clone cost me 4 GBP on eBay and arrived within a couple of days. A delicate bit of soldering (and installing ckermit on my main machine) and I had a serial connection - I could finally see what was was happening.
The upshot was, during the boot process the DNS-323 failed to mount my root partition. This was because the partition was formatted ext3 and the initrd.img had not included the ext3 module. It probably did this because I had deliberately forced mounting it as ext2 in the /etc/fstab (in an attempt to limit the write access to the disk, I want it to stay in standby for a long time but that's another post). (Remark by Martin: this is a known issue with initramfs-tools.)
Anyway, having seen this, Martin was able to guide me to getting it fixed:
modprobe ext2
to get the ext2
module loaded (luckily this was included in initrd.img).mount
-t ext2 /dev/sda2 /root
- it will complain a bit but will work
fine./scripts/init-bottom/udev
- this moves /dev to
within the new root directory.chroot /root /bin/sh
- shift the root around so we are
working from the proper root diskmount -t proc none /proc
- mount the proc treemount -t sys none /sys
- and the sys treenano /etc/fstab
- edit this to change ext2 back to ext3
for the root partitionmount -t ext2 /dev/sda1 /boot
- mount the boot
partition if it's a different device (mine is)/etc/initramfs-tools/modules
and add both
ext2
and ext3
- this will force their
inclusion in the updated initrd.imgupdate-initramfs -u
to regenerate the kernel and
initrd.img - this will rebuild the files in /boot and it will
use flash-kernel
to put them into the flash memoryumount /proc /sys /dev /boot
- unmount filesystemsexit
- leave the chrootumount /root
- unmount the root partitionreboot
And it should all be working!