mycroes

There's always time to play
Showing posts with label gentoo. Show all posts
Showing posts with label gentoo. Show all posts

Tuesday, March 10, 2009

How not to fix an issue in an ebuild

As seen on http://bugs.gentoo.org/show_bug.cgi?id=224781 Comment #2 From Christian Hoffmann 2008-06-08 13:59:44:
cherokee ships a patched version of lighty's spawn-fcgi. We could try to make
spawn-fcgi an independent package again and patch in the additional features of
cherokee based on a USE flag. Or we could introduce a "spawn-fcgi" USE flag for
both lighty and cherokee and die in the ebuild if the other web server was
installed with USE=spawn-fcgi as well. Any ideas?


Yes dude, you totally understood it. I bet mister Hoffman likes to tell portage (or whatever package manager he uses) to continue after every second ebuild because there's a check halfway in the ebuild instead of a real solution...

What if the check fails? Well, then package install fails of course. And what then? Well if you were just rebuilding world then you can fix the issue and start over again, or continue and know that you still have to fix it...

Sunday, February 8, 2009

Migrating from single disk to 3-disk RAID 5 (on Gentoo)

When following this guide a disk crash before the final step might still result in data loss, so if your data *is* important, back it up!

As my 1TB harddrive was filling up I was considering the ways I could expand storage. I hate usb drives, just for the simple fact that they're slow. I also don't like external storage at all, unless it's network storage. However, network storage would be slow for me too unless I at least spend some money to buy a decent gigabit switch instead of my 10/100 switch.

The option I liked most turned out to be to add another internal drive. I was already using LVM, so extending the volume group to span another disk wouldn't be hard, but that had it's serious downsides too. I'm not someone who does regular backups, I actually just don't do them at all unless something is really broken or I really feel I need to. Last time either of those happened is longer than a year ago I think, so a lot has changed since then. Now there's a lot of stuff I just don't need to backup, for the simple fact that it's someone else's service. I only use IMAP mail accounts and that's about the most important thing I could lose...

Because I don't do regular backups, I hope my harddisks will stay alive. Starting with a little bit of data and a new harddisk I can survive a near-instant crash. However when I would extend my 1TB lvm volume group with another drive, the risk of losing all data would immediately become twice as high. That's something I'm not willing to risk, because there's ways in which I simply don't have to risk it.

The solution I came up with was to buy 2 extra drives and create a RAID 5 array on top of them. A RAID 5 array requires at least 3 block devices, best to use 3 different disks for that, and will allow recovery of all data if at most one drive fails. It's possible to start with 3 drives and later expand to more while keeping all data on the disks. Another advantage is that data will be spread across disks, so reads and writes will also be spread across disks, so they will both be faster (the processing overhead for RAID 5 is very low).

When I made up my mind I had to figure out how to transition from my single disk to the RAID array, without having to use yet another disk to temporarily store my current data. A while ago I found some pages that pointed out that it's possible to create a 'degraded' RAID array. A degraded array means that on drive fail you might lose data, but when I still have all data on the old disk that won't be an issue. After having all the data on the degraded array, the old drive can be added to the array to fix the array integrity again.

So to summarize all of the above this is what I had to do:
- Add the drives to the system
- Create a degraded RAID 5 array on the 2 new drives
- Copy all data to the degraded RAID array
- Clean the old disk and add it to the array

Of course in reality I also had to compile a kernel with linux software raid support, because it was not there yet.

And here's what I typed with some additional explanation:
# paludis -i mdadm

Install mdadm, the linux software raid utility

# fdisk /dev/sda
# fdisk /dev/sdc

Partition the disks, in my case it just meant creating a full size partition with type fd (linux raid autodetect). Yes, my new disks are sda and sdc, I might have switched cables somewhere...

# mdadm --create -f /dev/md0 --level=5 --raid-devices=3 /dev/sda1 /dev/sdc1 missing

Create the degraded RAID 5 array with a missing drive.

# mdadm --examine --scan >> /etc/mdadm/mdadm.conf

Create a usable config file. Don't know when I would need it, but hey, it's there when I need it...

# pvcreate /dev/md0

Initialize a physical volume for lvm.

# vgcreate vg /dev/md0

Create the volume group 'vg' on the RAID array. Keep in mind that it needs to be different from the volume group name you was already using, if you were already using one...

# lvcreate -L30G -nroot vg
# lvcreate -L1200G -nhome vg

Create logical volumes for the root and home partition (that's all I use).

# mkfs.ext4 -L root /dev/vg/root
# mkfs.ext4 -L home /dev/vg/home

Create a filesystem, why not use ext4 immediately? Especially nice with biggish files.

At this point it's time to copy over all files, everyone has their own opinions about how this should be done, I just cped them over from the live install, leaving out /dev, /proc, /sys and creating them afterwards, copied /dev/null and /dev/console (copying all of /dev isn't really feasible, and those are all you need in gentoo) and I was done copying.

Now there's some additional stuff to worry about. I'm using gentoo, so I have to worry about being able to start from my RAID array too. Because I wanted to use the full disks for my RAID array I'm going to have to boot from another device, like a usb flash drive. So I started by copying my kernel with RAID and lvm support to my usb drive, created the entry in my syslinux config and created an initrd with
genkernel --lvm --mdadm initrd
. This created a nice initrd, with the helpful message that to use the lvm stuff I also had to pass dolvm on my kernel commandline. Now it was time to see if it all worked, and... fail... My RAID array was not detected, so all I could use was my old disk. After a while I found that for mdadm support you also need to pass 'domdadm' on the kernel commandline, and that solved all of my issues with booting, now let's hope that gets documented somewhere too.

I was now able to boot using my new lvm logical volumes on my new RAID 5 array. I actually started copying my home volume when I was able to boot, because that would take quite some time. All in all there was just one thing left to do, and that was adding the old drive to the RAID array (after changing the partition layout of course):

# mdadm /dev/md0 --add /dev/sdb1

Add sdb1 to the raid array.

Immediately the raid array will be resynced. This will take quite a while, because the RAID array itself has no knowledge about the data on it, so the entire disks are being synced.

While this all happens and after this all happens you can
$ cat /proc/mdstat
to see the status of the RAID array.

Now you should have a working RAID 5 array, just make sure you don't delete your data because a RAID array won't protect you from being stupid.

For a more detailed guide on just setting up the RAID array with a missing drive see Linux Software RAID 101 -- Part 3: creating an array with a missing drive, the guide I used to create my RAID array (you will notice all the mdadm commands are directly copied from that page).

Wednesday, January 7, 2009

Creating a multiboot USB-stick using syslinux

Since I have an eeepc-701, I need a way to boot it from external media so I can mess with it. I have a Corsair Flash Survivor (16GB), so I'm going to use that for rescue-goodness. I'll give step by step instructions on how to create a similar boot disk. In these instructions I'll assume that /dev/sdc is the usb drive, /dev/sdc1 is the partition we're using for the filesystem. Further mine will be mounted at /media/Corsair and I'll also assume you can find the appropiate packages if you haven't gotten them yet (dosfstools and syslinux in gentoo). Last but not least most of these commands will need root permissions, so prepend them with sudo if that's your thing, or become root and do it all as root.

Format the usb drive as fat 32
Of course there are other options than fat 32 to create a bootable usb drive, but syslinux needs a FAT filesystem to work.
# mkdosfs -F 32 -n Corsair /dev/sdc1

Mount the usb drive
Unplugging and replugging will work for me as I use Gnome with automount support, should probably work for most people using a larger desktop environment. If not:
# mkdir -p /media/Corsair
# mount /dev/sdc1 /media/Corsair

Create a syslinux directory
Syslinux needs somewhere to store its files, I prefer doing that in a directory so I don't get a cluttered view every time I look at the files on my usb drive.
$ mkdir /media/Corsair/syslinux

Unmount and install syslinux
Unmount in whatever way suits you, just don't unplug yet. The -d option tells syslinux to use our directory 'syslinux' to store its files, just make sure the directory is there before running syslinux.
# umount /media/Corsair
# syslinux -d syslinux /dev/sdc1

Mount again
Remount the device to put more on it than just syslinux.
# mount /dev/sdc1 /media/Corsair

There's only two things left to do now:
1. Move images to the usb drive
2. Create the syslinux.cfg file

Move images to the usb drive
I create two directories to start with: gentoo and gparted. Inside the gentoo directory I put the kernel, initrd and squashfs from the minimal install cd and renamed them to include the release number in the files. At first I named my kernel just 'kernel-2008.0', but that seems to confuse syslinux so I renamed it to kernel-2008.0.img in the end. Better extensions suggestions for the kernel are welcome. I also copied all the .msg files from the gentoo cd to the syslinux directory I created on the root of the filesystem, so I can press F1-F6 and see irrelevant gentoo messages, however, changing these is easy and will be done when I have more time. It also seems gentoo needs a file called 'livecd' on the root, else it won't find the media as the fs media. It's cluttering the drive, but removing the file will just cause gentoo not to find a valid root fs. Last but not least I compiled a kernel that has support for most of the hardware in my eeepc 701/4G surf, and named that 'kernel-eee' straight on the root of the USB drive. I needed at least 2.6.28 so I could have support for the onboard network card, whatever way I'm installing it I'm gonna want network support. The kernel is monolithic (no modules and no module loading support) and works fine with the gentoo 2008.0 squashfs.

Inside the gparted directory I again put the kernel, initrd and squashfs files. I just took them from the livecd, left names as they were.

Create the syslinux.cfg file
I took most of this file straight out of the isolinux.cfg that came on the gentoo cd and customized where necessary.
default gentoo
timeout 150
prompt 1
display boot.msg
F1 kernels.msg
F2 F2.msg
F3 F3.msg
F4 F4.msg
F5 F5.msg
F6 F6.msg
F7 F7.msg

label eee
kernel /kernel-eee
append root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/gentoo/minimal-2008.0.squashfs cdroot initrd=/gentoo/initrd-2008.0.igz

label gentoo
kernel /gentoo/kernel-2008.0.img
append root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/gentoo/minimal-2008.0.squashfs cdroot initrd=/gentoo/initrd-2008.0.igz vga=791

label gentoo-nofb
kernel /gentoo/kernel-2008.0.img
append root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/gentoo/minimal-2008.0.squashfs cdroot initrd=/gentoo/initrd-2008.0.igz

label gparted
kernel /gparted/vmlinuz
append initrd=/gparted/initrd1.img boot=live union=aufs noswap vga=791 ip=frommedia nolocales live-media-path=gparted

label memtest86
kernel memtest86

Syslinux uses relative paths by default, so if you use no '/' syslinux will look for the files inside the dir syslinux is. The solution is simple, use absolute paths for the kernel and initrd and it's all OK. Most important change made to this file is the append lines. For gentoo, the loop parameter needs to point to the squashs image, so I changed that to /gentoo/minimal-2008.0.squashfs (name of the image in my case). I added a line for my eeepc kernel, which just boots into a gentoo minimal cd.

Next was gparted. Gparted supports a 'live-media-path=' parameter, this needs to be used when the gparted squashfs image is not directly in the root of the filesystem on the usb drive. Other than that gparted just looks for any file with name *.{squashfs,ext2,ext3,jffs2} so the name doesn't really matter as long as the extension hasn't changed.

I also left the memtest line in place, added the memtest image to the root of the drive and my rescue-drive is mostly done.

It should also be possible to do the same thing using grub, except for the F1-F6 messages and the default message (or can grub do that too?). I'm definately gonna add grub to it, probably replacing syslinux with grub. Using grub might also allow for use of other filesystems on the drive, which might end up being a big plus too. Come back again to read about that, once I've tried it myself.

Wednesday, June 18, 2008

gstreamer television recording

I've been trying to record stuff from my tv tuner card using gstreamer. I like gstreamer as a multimedia framework and I like some apps that use it, so although there are enough other options I wanted to try this using gstreamer first.

The first issue was to record something from the tv card. I started by installing the video4linux gstreamer plugin. I actually started with installing version 1, then noticed there was a version 2 and because that's what the kernel uses natively I decided to go for v4l2. The gstreamer plugin is called v4l2src. I already read that to display something you need to run it through ffmpegcolorspace. To get it more useful you also need to specify resolution and framerate so to get something useful on my screen I started with
gst-launch-0.10 v4l2src device=/dev/video0 ! \
video/x-raw-yuv,width=768,height=520,framerate=\(fraction\)30000/1001 ! \
ffmpegcolorspace ! ximagesink

This works, but you still need to control the tv card or else you'll probably just see snow. There's a few different ways to control the tv card, but I wanted something as small as possible because I only needed to change the frequency to a desired frequency. I found dov4l, a small program that can do all the basic stuff that I needed done. To switch to discovery channel I could do a simple
./dov4l -f 496000000
from the folder where I unpacked the dov4l sources after I ran make. So now I actually had discovery channel displaying on my computer screen. Next step was audio. I use a bt878 tv card so I can use snd_bt87x to capture audio from the tuner device. A simple
gst-launch-0.10 alsasrc device=hw:1,0 ! alsasink
gave sound, so now I had audio and video from my tv card.

Now the hardest part was to get it all into a file. I'd seen various websites explaining some simple gstreamer stuff, and that at least taught me about muxing and demuxing. Actually, I didn't know much about the basics either. In short you usually want to encode video into something, encode audio into something and then dump it into a media container. So one common media container everyone knows is the avi format. I actually started out with ogg (vorbis and theora in an ogg container), but that gave me issues with both picture and sound so I soon moved to lame to convert my audio into mp3 and used ffenc_mpeg4 to convert my video into mpeg4. Dumping that into an avi container I ran into audio sync issues. After asking in #gstreamer on freenode I was told that the avi container doesn't handle time very well (or at all), so I should use another container and they pointed me to matroska. At this moment I was able to record to a file and view it afterwards, but that was not enough for me...

I wanted to use something modern. Although I quite like matroska containers because they're quite well supported on all platforms (vlc supports them, so any platform that supports vlc can in some way handle them) I was looking more for something like mp4. ffmpeg offers a muxing plugin for mp4, but I haven't gotten it to also use audio and I can only play it with mplayer then, so that's not really an option. I could however use something else in the matroska container. So I decided to use x264 for video. I'm on gentoo so I prefer to install by using ebuilds (although I'm using paludis so importare works for me too), so I went looking for an ebuild. The easy solution is to copy an existing gst-plugins-bad plugin ebuild (like the lame ebuild) and name it gst-plugins-x264-0.10.6.ebuild and place it in a correctly named folder in an overlay. Remove the deps that don't make sense (only lame for this specific plugin) and you should be able to install the plugin. I first tried with -0.10.7, but that wants gstreamer-0.10.19, so I decided to stick with gst-plugins-x264-0.10.6. Now I also needed something decent for audio, and I decided to go for faac, which seems to be reasonably supported these days and I ended up with the following line to do nice gstreamer recording from my tv card:
gst-launch-0.10 matroskamux name=mux ! \
filesink location=test.mkv alsasrc device=hw:1,0 ! \
audio/x-raw-int,channels=2,rate=32000,depth=16 ! \
audioconvert ! faac ! queue ! \
mux. v4l2src device=/dev/video0 ! \
video/x-raw-yuv,width=768,height=520,framerate=\(fraction\)30000/1001 ! \
ffmpegcolorspace ! x264enc ! queue ! mux.

I started with a capture resolution of 924x576, because that's what my card supports, but x264enc doesn't like that. Besides the fact that it complains that it can't encode fast when the width or height is not a multiple of 16 it wasn't properly encoding on that resolution. So as you can see I dropped it to 768x520, which gives a very decent picture, even for full screen viewing. Have fun watching!

Wednesday, June 4, 2008

How to get google gadgets to get gadget metadata

So it seems that now google gadgets for linux has been announced a lot of people want to try it. Seems most of them are retarded too and can't get it working. Because I have nothing against retarded people I'm going to list what I've found out:
- The error "Failed to update gadget metadata" can mean a couple of things.
- Curl needs to use openssl for cryptography to work with ggl.
- On gentoo you seem to need recent ca-certificates. In my case, upgrading from amd64 to ~amd64 worked.
- a simple `curl https://desktop.google.com/desktop` can show you why ggl can't fetch metadata.

I hope someone reads this and thinks it's useful, please leave a comment if so.

Sunday, May 20, 2007

Don't you, forget about me...

The title was this time sung by the nptl useflag. On a new Gentoo server install I set -* and forgot about nptl and nptl-only for glibc, so glibc was build with linuxthreads instead of nptl. Not much of a problem you probably think, but there seems to be some bug in mysql that when running on amd64 with linuxthreads it just won't stop... Killing by hand won't stop mysql either, unless I use -9. So from now on I'll remember to put nptl and nptl-only in my useflags...