General TC > Programming & Scripting - Unofficial

Script to remaster with ntfs-3g included

(1/3) > >>

SvOlli:
Hello,

I've hacked a little script together for integrating ntfs-3g into the initrd. I'm using this to set up a system where I need to put the tce directory inside an ntfs-partition. It is intended to be used together with the grub4dos.tcz package, which includes everything needed to start Tiny Core Linux using the Windows Bootloader.


--- Code: ---#!/bin/sh

if [ -f /opt/.tce_dir ]; then
  TCEDIR=$(cat /opt/.tce_dir)
else
  TCEDIR=/tmp/tce
fi

TMPDIR=/tmp/initrd.d
TCLOOP=/tmp/tcloop
TCENAMES="ntfs-3g"

installtcz()
{
for tce in $@;do
  if [ ! -d ${TCLOOP}/${tce} ]; then
    if [ ! -f ${TCEDIR}/optional/${tce}.tcz ]; then
      echo "downloading ${tce}"
      tce-load -w ${tce}
    fi
    echo "installing ${tce}"
    tce-load -i ${TCEDIR}/optional/${tce}.tcz
    if [ ! -d ${TCLOOP}/${tce} ]; then
      echo "${tce} seems to be installed, but not via loopback, forcing it."
      sudo mkdir -p ${TCLOOP}/${tce}
      sudo mount -o loop ${TCEDIR}/optional/${tce}.tcz ${TCLOOP}/${tce}
    fi
  fi

  echo "copying ${tce} to new initrd"
  (cd ${TCLOOP}/${tce} ; find * ! -type d | xargs tar cf -) |
    (cd ${TMPDIR};sudo tar xf -)
  touch ${TMPDIR}/usr/local/tce.installed/${tce}
done
}

if [ "$(id -u)" -eq 0 ]; then
  echo do not run as root, sudo will called when necessary
  exit 0
fi

if [ ! -f "${1}" ]; then
  echo "usage: ${0} initrd.gz [initrd_ntfs.gz]"
  exit 0
fi

sudo rm -rf ${TMPDIR}
sudo mkdir -p ${TMPDIR}

echo "unpacking initrd"
gzip -dc ${1} | (cd ${TMPDIR};sudo cpio -i)

echo "creating /usr/local/tce.installed"
sudo mkdir -p ${TMPDIR}/usr/local/tce.installed
sudo chown ${USER}:staff ${TMPDIR}/usr/local/tce.installed

installtcz ${TCENAMES}

sudo chroot ${TMPDIR} ldconfig
sudo sed -i 's/\$(blkid \$1)/$(blkid $1|sed s@TYPE=\\"ntfs\\"@TYPE=\\"ntfs-3g\\"@g)/' ${TMPDIR}/usr/sbin/fstype

ntfscpio="${2}"
[ -z "${ntfscpio}" ] && ntfscpio="tinycore+ntfs.gz"

echo "creating new initrd"
(cd ${TMPDIR};find .|sudo cpio -H newc -o) | gzip -9 > "${ntfscpio}"
[ -x /usr/local/bin/advdef ] && /usr/local/bin/advdef -z4 "${ntfscpio}"

--- End code ---
(edit 1: bugfix in sed-script for patching fstype)

Xianwen Chen:

--- Quote from: SvOlli on May 31, 2010, 09:35:34 AM ---Hello,

I've hacked a little script together for integrating ntfs-3g into the initrd. I'm using this to set up a system where I need to put the tce directory inside an ntfs-partition. It is intended to be used together with the grub4dos.tcz package, which includes everything needed to start Tiny Core Linux using the Windows Bootloader.


--- Code: ---#!/bin/sh

if [ -f /opt/.tce_dir ]; then
  TCEDIR=$(cat /opt/.tce_dir)
else
  TCEDIR=/tmp/tce
fi

TMPDIR=/tmp/initrd.d
TCLOOP=/tmp/tcloop
TCENAMES="ntfs-3g"

installtcz()
{
for tce in $@;do
  if [ ! -d ${TCLOOP}/${tce} ]; then
    if [ ! -f ${TCEDIR}/optional/${tce}.tcz ]; then
      echo "downloading ${tce}"
      tce-load -w ${tce}
    fi
    echo "installing ${tce}"
    tce-load -i ${TCEDIR}/optional/${tce}.tcz
    if [ ! -d ${TCLOOP}/${tce} ]; then
      echo "${tce} seems to be installed, but not via loopback, forcing it."
      sudo mkdir -p ${TCLOOP}/${tce}
      sudo mount -o loop ${TCEDIR}/optional/${tce}.tcz ${TCLOOP}/${tce}
    fi
  fi

  echo "copying ${tce} to new initrd"
  (cd ${TCLOOP}/${tce} ; find * ! -type d | xargs tar cf -) |
    (cd ${TMPDIR};sudo tar xf -)
  touch ${TMPDIR}/usr/local/tce.installed/${tce}
done
}

if [ "$(id -u)" -eq 0 ]; then
  echo do not run as root, sudo will called when necessary
  exit 0
fi

if [ ! -f "${1}" ]; then
  echo "usage: ${0} initrd.gz [initrd_ntfs.gz]"
  exit 0
fi

sudo rm -rf ${TMPDIR}
sudo mkdir -p ${TMPDIR}

echo "unpacking initrd"
gzip -dc ${1} | (cd ${TMPDIR};sudo cpio -i)

echo "creating /usr/local/tce.installed"
sudo mkdir -p ${TMPDIR}/usr/local/tce.installed
sudo chown ${USER}:staff ${TMPDIR}/usr/local/tce.installed

installtcz ${TCENAMES}

sudo chroot ${TMPDIR} ldconfig
sudo sed -i 's/\$(blkid \$1)/$(blkid $1|sed s@TYPE=\\"ntfs\\"@TYPE=\\"ntfs-3g\\"@g)/' ${TMPDIR}/usr/sbin/fstype

ntfscpio="${2}"
[ -z "${ntfscpio}" ] && ntfscpio="tinycore+ntfs.gz"

echo "creating new initrd"
(cd ${TMPDIR};find .|sudo cpio -H newc -o) | gzip -9 > "${ntfscpio}"
[ -x /usr/local/bin/advdef ] && /usr/local/bin/advdef -z4 "${ntfscpio}"

--- End code ---
(edit 1: bugfix in sed-script for patching fstype)

--- End quote ---

Dear SvOlli,

Thanks for sharing!

Best regards,

Xianwen

Xianwen Chen:
Can this script be used for TC 3.0?

maro:
I'm obviously not the author of the script (and have not used it myself) but after reading it I'm pretty sure that it should work with TC 3.0.

AFAICT it uses only one extension (i.e. 'ntfs-3g.tcz') which does exists in the 3.x repository and the rest is "just" a typical shell script using functionality BusyBox should supply. I would therefore encourage you to trial it out, or wait until SvOlli has had a chance to confirm my opinion.

SvOlli:
@maro: your assumptions are all correct :)

@Xianwen Chen: I haven't tested it on 3.x yet, but I can't think of any cause why it shouldn't work. Just give it a try.

I'm also working on a script that remasters a tinycore iso with ntfs drivers that works on any Linux system. After that one is done, I'll double-check this script. So stay tuned. ;)

Navigation

[0] Message Index

[#] Next page

Go to full version