Tuesday, 3 August 2010

LAP - Compression

Now, first of all lets deal with the kernel sources that we have left around in the sources directory. We are going to compress these into an archive file that will take up less space. We'll need a more powerful compressor than gzip or bzip2. We're going to use lzma. Now would also be a good time to install [.zip] file support. We aren't going to use it immediately, but we will do so eventually.

umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources
mkdir extras
chmod -v a+wt extras
cd extras
wget http://tukaani.org/lzma/lzma-4.32.7.tar.gz
wget http://downloads.sourceforge.net/infozip/unzip60.tar.gz
wget http://downloads.sourceforge.net/infozip/zip30.tar.gz

These commands make an [extras] folder inside the [/sources] folder on the Amiga Key. I am going to use that to store some of the add on bits of software. As some of these are optional (including technically this one) I will just repeat the [mkdir] command on the other occasions, just in case I have missed it out at any stage.

The install commands are quite simple, so unlike the networking utilities, we will just make a text file to remind us of the commands - much like installing wireless utilities. We have to make the text file and then move it into the LFS /root directory, because permissions bullshit(TM) prevents [cat] making the file directly.

sudo cat > compression.txt << "EOF"
cd /sources/extras
tar -xzvf /sources/extras/lzma-4.32.7.tar.gz
cd lzma-4.32.7
./configure --prefix=/usr
make $CORES_TO_USE
make check
make install
cd ..
rm -rvf lzma-4.32.7
tar -xzvf /sources/extras/unzip60.tar.gz
cd unzip60
make -f unix/Makefile linux
make prefix=/usr install
cd ..
rm -rvf unzip60
tar -xzvf /sources/extras/zip30.tar.gz
cd zip30
make -f unix/Makefile generic_gcc
make prefix=/usr -f unix/Makefile install
cd ..
rm -rvf zip30
EOF
sudo mv ./compression.txt /media/lfs/root 

We then reboot into the new system and run:
cat /root/compression.txt

and that will give you the commands to repeat. There may be a way to copy and paste using the command line only, but I haven't found it yet. If you want to be ultra lazy you could just rename the file to *.sh and [chmod +x] it to be executable and then run it. Just sayin.

Once installed, we can compress the kernel folder:

cd /sources
tar -c linux-2.6.32.8 | lzma --best > linux.tar.lzma
rm -rf linux-2.6.32.8

That command is pretty tricky. It is really in two bits. The first, before the [|] pipe uses the [tar] command to lump the contents of the kernel source directory into one large file which it then passes to the [lzma] on the other side of the pipe. The [best] bit tells it to really, really compress the data. Like up to an hour to compress. You can omit the [best] bit and it will do it quicker, but the resulting file will obviously be larger.

To uncompress in the future, run these commands:

cd /sources
cat linux.tar.lzma | lzma -d | tar x

That command is in THREE sections, which is even more complicated. What this does is pass the contents of the [.lzma] file to the [lzma] command, telling it to [d]ecompress before passing the outcome of that to the [tar] command to e[x]tract the file structure. This is much quicker, but still expect a couple of minutes to get the whole thing unpacked. This probably says more about the speed of the USB stick than the efficiency of the code though.

Lets just leave reminder of those instructions for ourselves in the system:

cat > compress_kernel_source.txt << "EOF"
cd /sources
tar -c linux-2.6.32.8 | lzma --best > linux.tar.lzma
rm -rf linux-2.6.32.8

cd /sources
cat linux.tar.lzma | lzma -d | tar x
EOF
sudo mv ./compress_kernel_source.txt /media/lfs/root

No comments:

Post a Comment