戻る

P-Plamo 5.2 の initrd.gz 内部の init

# cat pmt/init 
#!/bin/sh

export PATH=/bin

mount -t proc proc /proc
mount -t sysfs sys /sys

# squashfs.ko needs xz_dec.ko
for i in aufs squashfs ; do
  insmod /lib/modules/$i.ko
done

# nls_euc-jp.ko needs vfat.ko
for i in isofs nls_iso8859-1 nls_ascii nls_cp932 cdrom loop sr_mod sg \
    fat vfat nls_euc-jp ; do
  insmod /lib/modules/$i.ko
done

# for keyboard operation
for i in hid usbhid hid-generic ; do
  insmod /lib/modules/$i.ko
done

mount_ok=0

# check USB device first
if [ $mount_ok -eq 0 ] ; then
  sleep 5
  echo -n "trying USB device:"
  for i in sda sdb sdc sdd sde sdf sdg sdh ; do
    if [ -d /sys/block/$i ] && [ `cat /sys/block/$i/removable` -eq 1 ] ; then
      echo -n " $i"
      mount /dev/${i}1 /cdrom 2> /dev/null
      if [ $? -eq 0 ] ; then
        if [ -f /cdrom/isolinux/rootimg.squash ] ; then
          echo ; echo -n "found P-Plamo image on /dev/${i}1"
          CD_DEV=/dev/${i}1
          mount_ok=1
          break
        else
          umount /cdrom
        fi
      fi
    fi
  done
  echo
fi

# check CD device
if [ $mount_ok -eq 0 ] ; then
  sleep 10
  echo -n "trying CD device:"
  for i in sr0 sr1 sr2 ; do
    if [ -d /sys/block/$i ] ; then
      echo -n " $i"
      mount /dev/$i /cdrom 2> /dev/null
      if [ $? -eq 0 ] ; then
        sleep 3
        if [ -f /cdrom/isolinux/rootimg.squash ] ; then
          echo ; echo -n "found P-Plamo image on /dev/$i"
          CD_DEV=/dev/$i
          mount_ok=1
          break
        else
          umount /cdrom
        fi
      fi
    fi
  done
  echo
fi

# cannot find any CD device
if [ $mount_ok -eq 0 ] ; then
  echo "cannot find partition include squashfs, cannot continue booting, exit"
  exec sh
fi

# mount squashfs'ed rootfs image into /loop
losetup /dev/loop0 /cdrom/isolinux/rootimg.squash
mount -t squashfs /cdrom/isolinux/rootimg.squash /loop
mount -t tmpfs none /loop/tmp
for i in var bin etc lib run usr boot home sbin root opt srv misc net \
  install ; do
  mkdir -p /loop/tmp/ow/$i
  mount -t aufs -o br:/loop/tmp/ow/$i:/loop/$i none /loop/$i
done
mkdir -p /loop/dev
mount -t tmpfs tmpfs /loop/dev
cp -a /dev/console /loop/dev

echo "CD_DEV: $CD_DEV"
echo $CD_DEV > /loop/etc/cd_dev
mount --bind /proc /loop/proc
mount --bind /sys /loop/sys

echo "pivot_root to /loop"
sleep 5
cd /loop
pivot_root . loop
exec chroot . /loop/sbin/init

にゃんたろう 拝!

2014年 3月 23日 日曜日 21:28:58 JST 作成


戻る

Copyright © 2006.-2014. nyantarou All Rights Reserved.