Smokes your problems, coughs fresh air.

Tag: Linux (Page 3 of 4)

Native execution of Windows programs on Linux

When I installed this laptop last year, I was pleasantly surprised by the performance of vanilla Wine (and Gentoo’s default Wine configuration). At that time, my only memory of Wine was that getting anything useful to work took work and that your best bet to get anything working was to install CrossOver Office. Things change and in the meantime Wine has even come to version 1.0.

I want to write down what I had to do to be able to execute Windows executables as if they are Linux native. This can be done thanks to Linux’ support for misc. binaries.

First, you have to enable CONFIG_BINFMT_MISC in your kernel configuration. If it was configured as a module, run /sbin/modprobe binfmt_misc.

Then you have to register the appropriate binary formats:

':windows:M::MZ::/usr/bin/wine:' > /proc/sys/fs/binfmt_misc/register

That’s it. Of course, the .exe files need to have their executable bit set:

chmod u+x program.exe

Done.

Installing grub on RAID1

When you have your kernel image and grub boot stages on a Linux software RAID1 partition, installing grub needs a bit of trickery.

It determines on what hardware device those files are located by looking at /etc/mtab. It will find /dev/md/0 for / or /boot (or whatever) where the files are located. That device has no BIOS device, because it is managed by the Linux kernel. Therefore, when you try to install grub, it says: “/dev/md/0 does not have any corresponding BIOS drive.“. But because the underlying partitions in a RAID1 have the same data as the virtual device, we can trick grub.

All we have to do is edit /etc/mtab and replace the /dev/md/0 with /dev/sda1 (or whatever). You can then run grub-install hd0. Of course, make a backup of mtab first so you can revert it after having installed grub.

I find it kind of weird that grub doesn’t determine that the device in question is a RAID1 and that it can simply use the underlying device; the internet is filled with people having the same problem. If anybody knows a more elegant solution than this, I’m all ears.

Based on the comments, this is what you need to install it from the grub prompt:

# grub
grub> root (hd0,0)
grub> setup(hd0)
grub> root (hd1,0)
grub> setup (hd1)

Creating a custom device node for specific hardware with udev

Sometimes you want specific hardware to get a specific device name in /dev. For example, I want my backup hard disk to have the same device name. I can’t automate anything if sometimes the device is sdc and other times it’s sdd.

To do that, you need to create a specific udev rule. I put this one in 10-local for my backup hard disk:

BUS=="scsi", KERNEL=="sd*", SYSFS{vendor}=="ST325062", NAME="usbhd%n"

Everything with dual equal sign it uses as match, and I assign a different name at the end with a single equals sign.

You can look up the specific attributes to match in “/sys/bus/scsi/devices/[devicenumber]/”. The file “vendor” contains the “ST325062” I match for. My internal drives have vendor ATA (for whatever reason), so there will never be a conflict.

After having made the rule, you can use “udevstart”, “udevtrigger”, “udevadm trigger” or whatever your distro uses to test it.

Edit, this has been deprecated. Now it’s:

SUBSYSTEM=="scsi", KERNEL=="sd*", ATTR{vendor}=="ST325062", NAME="usbhd%n"

Clonezilla as disk imager

I was always using partimage to make backups of the hard disks of workstations. When trying to restore one the other day, it just started giving CRC errors. After recreating the image and running a simulated restore, it gave CRC errors again. So, apparently, it’s not incidental. It must be due to the experimental NTFS support. So, I set out to find a new tool. And that’s how I found Clonezilla, which gives me a very good first impression.

Clonezilla is a wizard-style live CD. It uses several tools, including partimage. However, it prefers ntfsclone over partimage at it’s default settings. Besides its handy interface, it has some very cool features: It doesn’t only create the image, but also some other useful files, such as the MBR (first 512 bytes of a disk), the data between the MBR and the first partition, an sfdisk dump of the partition table and some files with info about the PCI devices and other hardware. All this ensures you can properly restore the image.

Also, it has support for leaving out the page- and hybernation files on Windows systems, which can save you several gigabytes of space. And, to top it off, it calls “sync” when everything is done. They must have read my backup article :).

And the last major thing: it allows you to remove the CD when rebooting or halting. It is so incredibly annoying when live CD’s don’t do that…

A must have live CD for any sysadmin, I would say.

Gentoo update: Portage configuration confusion

During the first gentoo update session for this machine, I didn’t get very far. I already mentioned the problem I had with e2fsprogs, but this was not the first or the last problem that I had.

Until a few moments ago, I actually thought I made a bit of a fuck-up. I was meaning to make regular snapshots of /etc/portage files for a while now, because I was always just an echo something >> /etc/portage/package.keywords with one >-symbol too few away from destroying my configuration. Despite this fear, I thought I had already started deleting entries from /etc/portage/package.keywords and /etc/portage/package.unmask without backing up first.

Luckily, it turns out that I did make a dated copy of /etc/portage/package.keywords before starting on my modifications. I didn’t do so for /etc/portage/package.unmask, but I recovered a recent enough version from a recent full system rsync backup. So, everything is good. Still, I’m glad that I now use Git to track all changes in /etc/. All this goes to show that my methods are sometimes a bit more organized than my mind, which, I suppose, is a good thing. 😕

The point of this post—yes, there is a point—the point is that once you start mixing stable and unstable stuff, your system becomes, ehm, unstable. I have this huge amount of crap already in /etc/portage to cater to my wish to run stuff that I know to be quite stable but that isn’t yet marked as such in the Gentoo porttree. Now, after many months, I want to remove everything from package.keywords and package.unmask that is no longer necessary.

I was going to write about all the complicated upgrades, downgrades and conflicts suggested by Portage (mostly related to me removing KDE 4 stuff from package.keywords and package.unmask), because I was confused about what changes I had made. With the relevant backups readily available for comparison, I am no longer in a hurry to untangle my thoughts and I’ve moved the preliminary notes to a new draft for when I’ll actually update KDE 4.

Actual justification for this post

I’m trying to get into a blogging style were I post a lot more rubbish like this that can’t possibly be of any use to anybody except myself. I have plenty of reasons/excuses for this (about which I’ll likely post in the future), but I shouldn’t actually need any. That Ryan wanker who thinks I publish this blog for him should really shut the fuck up. Sure enough, he isn’t talking about this blog but I still think he’s a big-time asshole. Fuck you, Ryan!

Tracking /etc/ updates with Git

During my recent Gentoo update session, I was once again confronted with the inconvenience of not having my /etc/ directory under version management. This time, I thought I had the ideal SCM for this job: Git.

I found a blog post of a chap who has done the same. It includes a few notes I might not have thought about on my own and also a few very cool Debian tricks.

One of the steps that I might have overlooked myself is that it’s essential to make the .git directory group/world inaccessible with chmod go-rwx. If I would have forgotten this, a smart attacker might use my Git repo to access forbidden file contents.

The author also describes a cool Post-Invoke for Debian’s dpkg that will automatically stage and commit configuration changes made by apt/dpkg (although, later, he mentions that Debian has gotten a package could etckeeper that does this automatically.

Now I would like to learn how I can let Gentoo’s etc-update do as much. In its /etc/dispatch-conf.conf I can only find the option to use (of all things) RCS to track replaced configuration files in a special directory (/etc/config-archive/ by default). Hopefully, there is some drop-in replacement for etc-update which does this and which can rid me of etc-update’s awkward interface at once.

ImageMagick can convert PDF to anything

I encountered one of those scans which was shared as a single-page PDF. I don’t want it that way, because I want to include it in a web page. I want a simple bitmap image. ImageMagick comes to the rescue:

convert scan.pdf scan.jpg

If the resolution this produces is too low for you, try telling Ghostscript (which ImageMagick uses internally) that you want a different density:

convert -density 300 scan.pdf scan.jpg

Attribution

Googling linux pdf to jpg produced two useful results:

  1. Batch converting PDF to JPG/JPEG using free software
  2. Converting PDF to PNG/JPG using ImageMagick in Linux

smbmnt user needs to own the mountpoint if you want to mount rw

I just found out that it’s impossible on my system to mount /mnt/smb-docs as user bigsmoke, even with the following fstab:

//server/shared\040documents       /mnt/smb-docs smbfs   noauto,user,uid=bigsmoke,username=secret,password=alsosecret  0 0

I tried to chmod 775 /mnt/smb-docs; chgrp bigsmoke /mnt/smb-docs, but no luck. I had to actually chown bigsmoke /mnt/smb-docs. Does someone understand why? I noticed that I’m not the only one who noticed this.

Gentoo update: e2fsprogs blocks e2fsprogs

Yesterday evening, I dropped by at Wiebe‘s with my laptop to start updating our Gentoo systems together. I hadn’t updated this machine since first installing it in spring last year, so I expected quite a few problems. The first blockage that we both had to solve was caused by e2fsprogs.

Wiebe searched the forums for help and found an unfortunate abundance of it. Eventually, I decided to give one of the many contradictory tips a try, although it seemed risky.

$ emerge --unmerge --ask --verbose e2fsprogs

Until you reinstall e2fsprogs, you won’t have any of the ext2/3 utilities such as e2fsck. So, reinstall immediately:

$ emerge --oneshot --ask --verbose e2fsprogs

This will remove libcom_err and libss, and replace them with e2fsprogs-libs, thus solving the blockages.

Wiebe tried an alternative route by first unmerging com_err and ss, and then replacing e2fsprogs. This didn’t work as expected, probably because he had kerberos in his use flags. libkerberos used libcom_err, which broke wget. Scp’ing the distfiles to him didn’t work either (OpenSSH also has kerberos support). Neither did mounting an USB stick with the files. Luckily, Thunderbird still worked, so I emailed the distfiles and the problem was solved. We found it amusing to have to use e-mail while being in the same room. 😉

The reason why this blockage occurred is not entirely clear to me. What I do understand is that com_err and ss were both provided by the e2fsprogs project and are now deprecated in favor of e2fsprogs-libs. Also, it’s clear that the new libraries are binary compatible with the old libraries or his system would have remained unusable, even after merging e2fsprogs-libs.

Before we tackled this problem, I had only updated portage and net-print/foomatic-db-ppds (also a blocking situation). Afterwards, I had just some motivation left to update krb5. Which leaves another 282 packages for the next get-together.

XTerm is favorite

XTerm is know to most X-Windows users as that ugly terminal with the strange scrollbar and the unreadable font. And it doesn’t even have tabs! But, I think it’s the best damn terminal emulator in the world. It just doesn’t appear that way at first.

By default, XTerm comes with warts:

  • It has an ugly, small font.
  • What’s up with the black on white? I’m a 1337 h4x0r and I want a black background, damnit!
  • Double-click Selections is unintuitive.
  • Where are the tabs?

Default configuration for XTerm 234

But its warts are easily removed.

The font is small and ugly

Easily solved:

$ xrdb -merge
/* I want pretier fonts */
XTerm*faceName: Liberation Mono
XTerm*faceSize: 10
[Ctrl+D]
$ xterm

XTerm with nicer than default font

The black on white is an insult to my 1337ness

No longer so:

$ xrdb -merge
/* I want a 1337-style color-scheme */
XTerm*background: black
XTerm*Foreground: Grey
[Ctrl+D]
$ xterm

Now I can install my 1337 hacking tools in style! (If only I could install 1337 hacking skills as easily.)

1337-style XTerm

Double-click selections are unintuitive

Most terminal emulators let you double-click to quickly select words. XTerm does this as well, but its definition of a “word” is a bit narrow if you’re used to other programs. The good news is that XTerm is extremely configurable in this sense. It lets you decide what to select on double-click, on triple-click, all the way up to 5 clicks. You can define the boundaries of the selection by means of presets such as line, group and page, but what I like best is its ability to use regular expressions. This lets you do cool things, like, for example, using one click to select a word, two clicks to select a sentence, and three clicks to select a paragraph.

My own configuration is a bit simple, probably a testimony to how little code I write these days:

$ xrdb -merge
/* The selection only stops at spaces and newlines */
XTerm*on2Clicks: regex [^  \n]+
[Ctrl+D]

Where are my tabs

You should really be using GNU Screen instead, which has too many advantages to name here. It even allows you to do Remote pair programming over SSH.

If you use Screen within an XTerm, be sure to add to following to your X configuration.

$ echo "XTerm*metaSendsEscape: true" | xrdb -merge

Otherwise, you might find yourself unable to control Screen

Saving your configuration

Ready to save your precious configuration?

$ xrdb -edit .Xdefaults

You’re done. It’s time to go brag to your friends.

« Older posts Newer posts »

© 2024 BigSmoke

Theme by Anders NorenUp ↑