Category: Penguinarium

Linux-related materials

  • Jelly Bean, multiuser and lost security patterns

    Finally got my N7 setup with multiuser goodness from JB. However my son in attack of curiosity locked himself out with security pattern. Well… I didn’t 😉 Thanks to always helpful XDA: [GUIDE][HOW-TO]Crack android pattern lock! solution was really quite simple:

    # find / -name gesture.key 
    # mv /data/system/users/11/gesture.key /data/system/users/11/gesture.key.bak 
  • bash color goodness (yes, I do miss Gentoo’s colorful CLI)

    I keep on repeating the same setup over and over and every time I have to go and look.

    # Black            \e[0;30m
    # Blue             \e[0;34m
    # Green            \e[0;32m
    # Cyan             \e[0;36m
    # Red              \e[0;31m
    # Purple           \e[0;35m
    # Brown            \e[0;33m
    # Gray             \e[0;37m
    # Dark Gray        \e[1;30m
    # Light Blue       \e[1;34m
    # Light Green      \e[1;32m
    # Light Cyan       \e[1;36m
    # Light Red        \e[1;31m
    # Light Purple     \e[1;35m
    # Yellow           \e[1;33m
    # White            \e[1;37m
    
    grey='\[\e[0;37m\]'
    dgrey='\[\e[1;30m\]'
    red='\[\e[1;31m\]'
    green='\[\e[1;32m\]'
    yellow='\[\e[1;33m\]'
    blue='\[\e[1;34m\]'
    magenta='\[\e[1;35m\]'
    cyan='\[\e[1;36m\]'
    white='\[\e[1;37m\]'
    underline='\[\e[4m\]'
    eofmt='\[\e[m\]'
    eoc='\[\e[0m\]'
    
    . ${HOME}/.bash_color
    PS1_DIR_COLOR=${PS1_DIR_COLOR:-yellow}
    eval PS1_DIR_COLOR=\$$PS1_DIR_COLOR
    if [ "$TERM" == "xterm" ]; then
    export PS1=$white'\! '$dgrey'\t '$white'\u'$eoc'@'$underline'\h'$eofmt' '$PS1_DIR_COLOR'\w '$white'\$ '$eoc
    else
    export PS1=$white'\! '$white'\u'$eoc'@'$underline'\h'$eofmt' '$PS1_DIR_COLOR'\w '$white'\$ '$eoc
    fi
    export HISTCONTROL="ignorespace:ignoredups"
    export HISTTIMEFORMAT=" %F-%H:%M "
    
    

    Now add to your ~/.bash_color:

    #!/bin/bash
    
    PS1_DIR_COLOR="green"
    

    and you have per-machine colors with easy management.

  • Zalman ZM-VE200SE

    Couple of month ago I have acquired a neat piece of equipment: Zalman ZM-VE200 . However I have never had a chance to test it’s most intriguing geek-feature: ISO mounts. In short – it can pick and ISO from disk and pretend to be a CD/DVD drive to a computer. Very handy and no mess with optical media etc.

    Zalman website is not very usefull (no docs whatsoever). So I have snooped around and found what I needed:

    • Have to create the firstpartition as NTFS
      • FAT32 wouldn’t accept DVD images over 4G
      • $ mkfs.ntfs -f -L ZALMAN_NTFS /dev/sdb1
    • Have to stash ISO’s into “_iso” folder (note the case)
    • Will have to defrag that drive from time to time
    So I ended up allocating 100G from 500G drive for the NTFS partition with intent of wiping it every now and then and reformatting to work around absence of defrag tools in Linux
    Installing Fedora 18 on Dell laptop I had to use the rocker to select ISO, then scroll up and change mode from “DUAL” to “ODD”, scroll back to Fedora ISO, depress the rocker and Dell finally agreed to recognize VE200SE as a proper CDROM.
  • Configuration management (rant #1)

    I’ve been on a lookout for a good configuration management solution (technique, tool, ANYTHING!) for quite a while. However most of them have been geared towards managing fleets of identical machines, while in my case each machine is fairly unique. Here are the tools I’ve seen so far:

    I’ve tried to integrate some config management into CPacMan for a while now with variable success. I think mainly because I was trying to peg old practices into a new paradigm…

    I came across the great post and that got me thinking… One should be able to manage configs by simply using… Git 🙂 Setup is fairly simple:

    • each host has it’s own Git repository of /etc (and all the other locations??)
    • centralized version of configs should be branched from each host
    • based on above operating git with pull/push and adding some clever hooks it should be possible to maintain config files asynchronously in 2 places periodically re-syncing centralized versions…

    Maybe it should be SVN though, as cetralized version can’t be anything else but branches of remote ones… hmm…

     

  • EeePC 901 + Fedora 17 + KDE = …

    Time has come to spruce up my old [t]rusty EeePC 901 with it’s ageing F15, so we’re on to F17 (starting with Beta…)

    This time I decided to take time to know things “intimately” and knock off any unnecessary cruft to get mean and lean system that does exactly what I want and nothing more, just like I did with HTCP build earlier. I’m using my main SSD (which is under 4G size) so things are tight and installing anything “extra” comes with a hefty price tag.

    First, we install “Minimal install”. That gets us booting system with about 200 packages.

    Our approach will be – try to install desired group of packages via:

    $ yum groupinstall SOME_FOO_GROUP

    , check out list of packages to be installed (not the dependency list) which typically is a small set to operate on, and trim it down to bare necessities.

    Now, on to more complex tasks: X11 environment. I thought tweaking and twisting that one would give me space, but, as a matter of fact trimming package list down only saved me about 4M out of a 100M so I stuck with conventional:

    $ yum groupinstall “X Window System”

    KDE is where it did make a difference to get things “just right”. Firing “yum groupinstall KDE” ends up reporting about 1.4G of packages. I’ve done some analysis and ended up with:

    $ yum install kdeplasma-addons kdm kgpg kipi-plugins kolourpaint \
    konversation kruler krusader ksnapshot ksshaskpass ksysguard ktorrent \
    ktp-accounts-kcm ktp-approver ktp-auth-handler ktp-contact-applet \
    ktp-contact-list ktp-filetransfer-handler ktp-kded-integration-module \
    ktp-presence-applet ktp-send-file ktp-text-ui kwallet kwebkitpart \
    okular oxygen-gtk phonon-backend-gstreamer pinentry-qt \
    plasma-scriptengine-python scribus system-config-printer-kde \
    system-config-services xorg-x11-apps xsettings-kde xterm \
    kdenetwork-{kget,krdc,krfb,kopete} kde-plasma-networkmanagement \
    kde-plasma-networkmanagement-pptp

    which is about 950M instead. Almost 0.5G shaved – that’s not bad 🙂

    Now we’ll add some office tools:

    $ yum install calligra

    At this point we have 1.1G to spare, which is not bad so far. From here on it’s a mini-tweaking game. We’re done.

  • Installing VMs from USB iso with SELinux

    Today I’ve attempted installing Fedora VM from the image on USB and got some unpleasant messages in virt-install:

    2012-02-24 20:24:06.582+0000: 1329: error : qemuProcessReadLogOutput:969 : internal error Process exited while reading console log output: char device redirected to /dev/pts/4
    qemu-kvm: -drive file=/media/3D2B-FFC6/iso/Fedora-16-x86_64-netinst.iso,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw: could not open disk image /media/3D2B-FFC6/iso/Fedora-16-x86_64-netinst.iso: Permission denied

    Digging for the truth took me a while. In the meantime I have attempted “logical” solution:

    mount -o context=system_u:object_r:virt_image_t:s0 /dev/sdb1 /var/lib/libvirt/images

    Which turned out to be wrong as installer would still fail, this time leaving message in /var/log/messages:

    Feb 24 13:46:18 dimon2 kernel: [87065.769543] type=1400 audit(1330116378.901:4): avc: denied { read } for pid=1287 3 comm=”qemu-kvm” name=”Fedora-16-x86_64-netinst.iso” dev=sdb1 ino=116 scontext=system_u:system_r:svirt_t:s0:c130,c52 7 tcontext=system_u:object_r:virt_image_t:s0 tclass=file

    So I came across a bug in RH bugzilla that helped with the solution:

    mount -o context=system_u:object_r:svirt_image_t:s0 /dev/sdb1 /var/lib/libvirt/images

    Note the tiny difference – using “svirt_image_t” vs “virt_image_t”. Unpleasant but I can live with that… It also means I have to mount USB devices manually to be able to use them as a source for VM images… but that is OK.

  • Building Linux Home Theater box

    Hardware

    First Note: this build was not about “cheap”. This is all about “building my own”, “small” and “quiet”, “cheap” comes as a last criteria.

    SilentPCReview gave me some really valuable information on how to get things together with this case. Most importantly – to get 120mm case fan. I experimented with 80mm and got temperatures inside the case dropping from ~80C down to ~60C which prompted me to go that extra mile and get 120mm fan – Noctua NF-S12B turned out to be one valuable addition – with varied settings 1200/900/600 RPM it allowed me to be the judge of what’s acceptable, and I ended up using 900RPM setting as it was much quieter than 1200RPM yet provided plenty of airflow. I ended up pointing it outward (i.e. sucking air out of the case vs sucking it in). Such positioning allows you to suck cool air directly towards CPU drawing hot air towards PSU fan and the Case Fan allowing for better temperature management as far as I can tell. Temperatures seem to be in comfortable ~50C zone so no unpleasant noise so far (well, we’ll wait for movies to warm things up).

    My plan B includes underclocking CPU and GPU if temperatures get too high. Core i3 is more than enough for movie-watching/internet browsing so I’m not too worried about effects of underclocking.

    Software

    Pre-building in VM

    This one needs to be quiet and not to burn holes in SSD and be fairly minimalistic, so I’m building it from Fedora 16 Install DVD starting with “minimal” setup and building up to something I can accept. After building the box as a VM (with Spice graphics) – image of an SSD that we’re about to use, and installing base OS first tweak is to get rid of all unnecessary writes via noatime, and tmpfs:

    # cat /etc/fstab
    /dev/sda1  /                       ext4    discard,noatime,data=writeback        1 1
    none /tmp tmpfs defaults 0 0

    Now we need some packages for X Windows:

    # yum groupinstall “X Window System” LXDE

    That should give us nice base. However if you try to launch graphical interface:

    # systemctl start graphical.target

    you get no fonts and lots of squares on the screen. I fixed that with a “hammer”:

    # yum install xorg-x11-fonts\*
    # yum install liberation\*

    after that we can start up Xorg – no problem.

    Now some apps and more convenience:

    # rpm -Uvh http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noarch.rpm
    # rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
    # yum install flash-plugin
    # yum install libdvdread libdvdnav lsdvd
    # yum install mplayer mplayer-gui smplayer
    # rpm -Uvh http://rpm.livna.org/livna-release.rpm
    # yum install libdvdcss
    # yum install vlc
    # yum install xine-lib xine-lib-extras xine-lib-extras-freeworld xine-ui xine-ui-skins gxine minitube
    # yum install firefox

    And all this goodness in 1.5G – not bad. We’ve got Flash, Firefox, XBMC, Mplayer, VLC and Xine – almost ready to bust some movies 🙂

    All we need now is to boot into XBMC by default to avoid all the complexities of a “typical boot” on this over-simplified machine:

    # useradd -m -g users -G audio,video -s /bin/bash xbmc
    # passwd xbmc
    # cat > /etc/lxdm/lxdm.conf
    [base]
    session=/usr/bin/xbmc-standalone
    greeter=/usr/libexec/lxdm-greeter-gtk
    autologin=xbmc

    [server]
    arg=/usr/bin/X -background vt1

    [display]
    gtk_theme=Clearlooks
    bg=/usr/share/backgrounds/default.png
    bottom_pane=1
    lang=1
    theme=Industrial

    [input]

    [userlist]
    disable=0
    white=
    black=
    ^D

    Notes on above: we’ve created xbmc user, set his password. And made default action for lxdm to login xbmc user using xbmc-standalone shell. Almost there…
    Now some graphical goodness for package management in case we need it:

    # yum install yumex

    After that VM can be shut down and we’re transfering our image over to CompactFlash card connected via CardReader:

    homePC # virsh shutdown htpc
    homePC # dd if=htpc.img of=/dev/sdf

    Note that above is done from my “normal PC” rather than from within VM itself.

    Tuning of the real thing

    Now whenever I plug My CF-to-SATA kit into Zotac H-55 I’m getting system that hangs for a while, and then… doesn’t see new disk. Bummer. Fall-back – 4G USB stick.

    now I’ve got USB stick ready and found out I’m missing NetworkManager, d’oh!

    First thing that hit me – difference in size of CF and USB stick. F16 uses GPT, and bitterly complains about broken FS etc. etc. etc. so… fixing is possible only via parted:

    htpc # parted
    (parted) print all

    after which it asks you whether you want to fix various issues and the answer is “yes”

    # yum install NetworkManager NetworkManager-gtk NetworkManager-gnome

    However after that I’ve got the unpleasant

    $ nm-connection-editor

    ** (nm-connection-editor:10500): WARNING **: Icon nm-device-wired missing: Icon ‘nm-device-wired’ not present in theme

    ** (nm-connection-editor:10500): WARNING **: Failed to initialize the UI, exiting…

    which was fixed by

    # yum install gnome-icon-theme-legacy

    but even then I’ve got:

    ** (nm-connection-editor:10500): WARNING **: Icon nm-device-wwan missing: Icon ‘nm-device-wwan’ not present in theme

    I have resorted to a hack – symlinked some instances of nm-device-wired.png to nm-device-wwan.png and even that didn’t help!

    # yum install lxde-icon-theme

    while that made LXDE look less “rough” it didn’t fix the issue. Argh!
    Final attempt was to install whatever pieces of NetworkManager missing:

    # yum install NetworkManager-{openconnect,openvpn,openswan,pptp,vpnc}

    and that has finally resolved the issues of missing icons, g’ah!

    Things to do

    • add Autofs mounting of NAS shares with pictures/movies

     

  • On SSD-based builds

    As I was making my way through FreeBSD reinstall on CF I was also working on Linux-based Home Media Centre with as few moving parts as possible, yes and it includes SSD. So I started snooping around to get similar tweaks to FreeBSD ones, and surprisingly those are the same – use “noatime” and mount needed partitions as tmpfs:

    # grep tmpfs /etc/fstab
    none /tmp tmpfs defaults 0 0

    As I will be making my way through that build I’ll try to document it bit better.

  • Fedora 16 renaming mdraid disks and grub2 woes

    Dealing with constant mdraid device renames that F16 DVD (just like F15 did before it) performs and bugs and oddities of grub2 I’ve decided to rename md devices back to what I created and documented them as. While mdadm docs are quite terse, fellow sysadmin came to the rescue:

    # mdadm –assemble /dev/md3  /dev/sd[abcdefghijk]3

    given how old my mdraid devices were I had to resort to the oldest syntax possible to get things going.

    In the meantime Grub2 decided to go crazy on me (boy, it does remind me LILO in it’s old days). So here’s quick problem-solution combo.

    Problem

    Since I’ve installed F16 rescue mode renamed /dev/md* devices several times. ugh! Apparently grub2 capability to boot from mdraid devices is not mature enough (or the ways Fedora scripts using it are immature…) to get initial setup. Well, /boot/grub2/grub.cfg can be made to have no reference to real devices – no problem, BUT! Apparently Grub2 stashes someplace /boot’s device name when you perform grub2 install!

    Solution

    solution is to boot into Fedora DVD’s rescue mode and before allowing it to locate all the disks switch to console 2 (Alt-F2) and:

    1. rename all md* devices to what they should be via above trick:

    # mdadm –stop /dev/md123
    # mdadm –assemble /dev/md2 /dev/sd[ac]2

    note how we shut down renamed device md123 and bring it back up as md2 – further inspection via

     # mdadm –examine /dev/sda2 | grep Minor
    Preferred Minor : 2

    confirms that now stored minor has changed.

    2. switch back to Fedora’s rescue screen on console 1 (Alt-F1) and let it look for the installed instance.

    3. Now select instance and get into the shell.

    4. do the advised:

    # chroot /mnt/system

    5. make darn sure you record your new MD numbers in /etc/mdadm.conf, one way is to walk through the member devices and do:

    # mdadm –examine –scan /dev/sda2 >> /etc/mdadm.conf

    6. massage /etc/mdadm.conf into something like:

    MAILADDR root
    # AUTO +imsm +1.x -all
    DEVICE /dev/sda*
    DEVICE /dev/sdc*

    ARRAY /dev/md2 level=raid1 num-devices=2 UUID=xxxf82e4:6xxxxa0d0:44xxx7c0xxxxa021

    7. now we need to firm this up and cut initramfs for it (this will include our new /etc/mdadm.conf). Make sure  /etc/dracut.conf has line with  mdadmconf=”yes” uncommented, then run:

    # dracut -f /boot/initramfs-$(uname -r).img $(uname -r)

    8. finally we need to make sure grub2 is on board for this:

    # grub2-install /dev/sdc

    # grub2-install /dev/sda

    9. just to be sure re-generate grub.cfg:

    grub2-mkconfig -o /boot/grub2/grub.cfg

    10. we’re done.

  • Easy way to mount CIFS in (Fedora) linux via autofs

    after struggling with HOWTO Forge’s recipe and Fedora’s modification of the same recipe, CentOS provides some helpful info on how to set things up the easy way:

    # yum install autofs cifs-utils
    # mkdir /mnt/smb

    Add this line to /etc/auto.master:

     

    /mnt/smb /etc/auto.smb.top

    Create /etc/auto.smb.top as:

     

    * -fstype=autofs,-Dhost=& file:/etc/auto.smb.sub

    Create /etc/auto.smb.sub as (adjust as needed):

     

    * -fstype=cifs,credentials=/root/secret.txt,uid=500,gid=100 ://${host}/&

    Now you can access by simply typing:

     

    # cd /mnt/smb/winbox/getme