неделя, 7 декември 2014 г.

Unable to mount NTFS partition

My external hard drive failed to mount its NTFS partition giving me the following error:
"on-zero exit status 13: $MFT must be non-resident. Failed to load $MFT: Input/output error Failed to mount '/dev/sdd1': Input/output error".
I thought I ruined once again my NTFS partition (this happens every now and then, because of my reckless copying of files), but the answer was quite simple.
I executed:
$sudo ntfsfix /dev/sdd1
and that fixed the problem immediately. Obviously this time I didn't make quite a mess.

сряда, 12 ноември 2014 г.

How to change the comma like a decimal separator

I have absolutely no idea why my Sabayon uses the comma as a decimal separator, but it does. Go figure. Anyway, it turned out, you can see your locale settings by typing
$locale
in BASH. An it will return a list of the setting used for different things like Date, Currency etc. Since I care only about numerical activities, this is the only thing I wanted to change.

So I found that this could be changed from SystemSettings->Locale, but since you need to log out for this to work, I found a simple way.

To do it just for the session, do
$ export LC_NUMERIC="en_US.UTF-8" 
This will change the separator to my beloved point. You can add this to ~/.bashrc or ~/.bash_profile to make it permanent, but I think that SystemSettings will do the trick for you anyway.

сряда, 30 юли 2014 г.

How to make a bootable USB under linux

I'm ashamed to admit it, but it turned out I need to install Windows to check whether all my hardware is working properly (because I have no way to know if it's not working or simple not recognized by Sabayon). So I needed to make a bootable USB.
I tried untebootin and winusb, but both didn't work, for different reasons.I tried also with what seemed most likely to work - dd:
$sudo dd if=/path/to/iso/windows.iso of=/dev/sdg bs=4M; sync
both with ntfs partition and fat32 partition, but somehow dd destroyed the partition table and the USB was unbootable.
So here's what worked for me in the end:
Of course, first you need to locate and empty your USB from everything important.
1. To find the device of your usb:
$sudo fdisk -l
2. Unmount the USB (say it's /dev/sdc1):
$umount /dev/sdc1
3. Format it as FAT 32 - I also have no idea if this is essential, but it worked.
$sudo mkdosfs -n 'USB-Drive-Name' -I /dev/sdc -F 32
4. Mount the ISO you have the usual way:
$mount -o loop /path/to/win.iso /usual/mount/directory
5. Go to your loop directory (it appeared in Dolphine sidebar for me) and copy all the files there to your USB (you'll have to mount it for this).
6. Unmount your USB and reboot to use it.
These steps follow partially this link, I changed only the last steps, where they use dd to copy the iso. I tried this, but again, I got unbootable USB. I tried also partitioning it with gparted and setting a boot flag, but again, after using dd, the partition table was gone. Maybe there is a simple way to do it with dd, I just don't know it and couldn't find it quickly enough.


вторник, 15 юли 2014 г.

kdesu failing to start - bad display name

The problem was simple. I was trying to launch something with kdesu and I got the "bad display name ":0.0" " error.
After some googling, I found this gentoo thread ,where the solution turned out to be to use "xhost +" to allow the connection to the X for root users and then to use "xhost -" to stop it. It worked.

петък, 14 февруари 2014 г.

System boots ridiculously slowly?

After I bough my new laptop (ASUS N550J), quite a decent machine, it turned out it booted very very slowly. Not that I restart that often, but when I do, it was simply ridiculous to watch the system struggle for a minute or so. Additionally my bluetooth didn't work which was quite odd and annoying. The strange part was that kinfo and lspci saw my usb device, it was just BlueDevil which told me "Adapter not found". I installed net-wireless/blueman - but it didn't help.
Anyway, after I reported it on the Sabayon forum, we came up with the following solution.
First, the symptoms (of the slow boot up):
localhost  # systemd-analyze
Startup finished in 4.962s (kernel) + 43.943s (userspace) = 48.906s
localhost # systemd-analyze blame
         32.071s systemd-udev-settle.service
          8.149s NetworkManager.service
          5.167s systemd-logind.service
          3.168s x-setup.service
          3.085s ufw.service
          2.962s systemd-user-sessions.service
          2.635s systemd-fsck-root.service
          2.620s plymouth-start.service
          2.563s avahi-daemon.service
          2.421s systemd-vconsole-setup.service
          2.203s plymouth-quit-wait.service
          2.203s plymouth-quit.service
          2.195s dev-mqueue.mount
          1.955s sys-kernel-debug.mount
          1.955s dev-hugepages.mount
          1.928s dev-disk-by\x2duuid-5de9b296\x2d1968\x2d4ce2\x2db745\x2d79782c4a3819.swap
          1.259s systemd-modules-load.service
          1.230s systemd-udev-trigger.service
           993ms systemd-udevd.service
           984ms var-lock.mount
           984ms var-run.mount
           955ms sys-fs-fuse-connections.mount
           785ms lvm2-activation-early.service
           541ms udisks2.service
           347ms rtkit-daemon.service
           274ms systemd-sysctl.service
           270ms polkit.service
           244ms systemd-tmpfiles-setup-dev.service
           210ms systemd-tmpfiles-setup.service
           182ms lvm2-activation-net.service
           145ms systemd-tmpfiles-clean.service
           121ms bluetooth.service
           116ms wpa_supplicant.service
           101ms systemd-journal-flush.service
            96ms systemd-remount-fs.service
            66ms plymouth-read-write.service
            63ms systemd-random-seed-load.service
            59ms vixie-cron.service
            56ms upower.service
            18ms alsa-restore.service
             5ms lvm2-activation.service
             1ms tmp.mount
localhost # systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.

graphical.target @43.943s
└─kdm.service @43.943s
  └─steambox.service @43.943s
    └─network.target @43.943s
      └─NetworkManager.service @35.793s +8.149s
        └─basic.target @35.775s
          └─timers.target @35.775s
            └─systemd-tmpfiles-clean.timer @35.775s
              └─sysinit.target @35.723s
                └─systemd-tmpfiles-setup.service @35.512s +210ms
                  └─local-fs.target @35.511s
                    └─tmp.mount @5.318s +1ms
                      └─local-fs-pre.target @4.150s
                        └─systemd-remount-fs.service @4.052s +96ms
                          └─systemd-journald.socket @1.354s
                            └─-.mount @1.353s

And in the dmesg I found:
[   16.991818] xhci_hcd 0000:00:14.0: Timeout while waiting for address device command
[   22.197007] xhci_hcd 0000:00:14.0: Timeout while waiting for address device command
[   22.398176] usb 1-5: device not accepting address 3, error -62

(and a lot more similar lines)

Here's what I did (and it worked):
1. Install "acpi". It turned out that merely by installing this package it decreased my boot up time from 48secs to 26 secs. And that is 22 secs difference - approximately 50% reduction!
2. Add to your kernel line in GRB pcie_hp=nomsi, i.e.:
linux   /kernel-genkernel-x86-3.12.0-sabayon root=/dev/sda3 ro splash vga=791 quiet dokeymap keymap=us  resume=/dev/sda5 pcie_hp=nomsi  
This reduces 4 more seconds to :
#systemd-analyze
Startup finished in 5.379s (kernel) + 16.956s (userspace) = 22.336s
3. You can also use this suggestion, though I still have to try it myself:
#systemctl enable systemd-readahead-collect systemd-readahead-replay
It make the system learn which disk sectors are read on boot up and read them ahead, so it should save time.

The best part is that as a side-result from the installation of "acpi", my bluetooth device started working. Well, at least it's on and visible from other devices. Last time I tried to send something, it failed but at least now I know it works.  

понеделник, 13 януари 2014 г.

How to limit bad bandwidth on your site

I think I'm a star for the Chinese bots. Not this blog, but my site where I pay for hosting, I get thousands and thousand of hits, which suck my bandwidth and make me communicate with the hosting sys-admins way too often. So, here is what I found so far in how to protect my precious bandwidth.
1. No hotlinks
I never thought of this, but it turns out this can be a significant drain of your bandwidth and CPU time. Basically, somebody links to your images and use your hosting to display them, thus stealing both your images and costing you money. So how to stop it? I found the answer here and here:
You need to edit your .htaccess to add: 
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?your-site.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ http://i.imgur.com/g7ptdBB.png [NC,R,L]
Where you need to  change your-site.com with your domain.
What this code does is that it redirects all viewers but those from your site to the link on the row number 4. This way, people won't be able to hotlink to your images.

2. Preventing bad bots to crawl your site.
Yes, there are bad bots. In my case, I have some unidentified bot who steals 300MB of traffic per day from my site. A very good tutorial what to do in this case can be found on this post: Protect your site from spam bots which I will summarize below, so that I don't forget what I did.
The steps are as follow:
2.1. Add to your .htaccess the content of this file. It is a list of the known bad bots.
2.2. Create 403.php in your top level/home directory and paste this. This script will log forbidden requests.
2.3. Create forbidden.html  in your top level/home directory and use the content of this file.
2.4. Create a trap directory and name it something interesting to humans, we'll call it /your_trap_directory. 
2.5. Create robots.txt and put in it:
User-agent: *
Disallow: /your_trap_directory
 2.6. In your_trap_directory place the following index.php.
2.7. Make sure both index.php and forbiddent.html have the 644 permissions.
2.8. Put some links to your_trap_directory on your site, so that you can lure bots. You can use something like:
<a href="http://your_site/your_trap_directory/" style="display: none;">check this hot offer</a>
in the html of your site or put it as HTML plugin on your blog.
VERY IMPORTANT! DO NOT VISIT THIS DIRECTORY from your site!
Because you will be added to the ban list and you'll need to go to cpanel, open .htaccess and remove your ip from it. This links are not meant to be read by humans, but only from bots.
I recommend you to visit the source site: Protect your site from spam bots to find a way to check whether what you did is working.
3. Check your AWstats for suspicious ip-s and then ban then from IP Deny Manager or directly in your .htaccess. I know some people ban entire countries, but I find this for too restrictive. We'll see if this will help my problem.
4. Ok, I did some additional research (like source1 and source2), I decided to use :
RewriteEngine on
Options -Indexes
    RewriteEngine on 
RewriteCond %{HTTP_REFERRER} !=http(s)?://(www\.)?mysite.com/index.php [NC] 
RewriteCond %{HTTP_REFERRER} !=http(s)?://(www\.)?mysite.com/*.php [NC] 
RewriteRule ^comment\.php$    -                                   [F]

So far that's what I did. I'll add stuff when I change something else. But for the moment, the bad traffic and cpu use seems under control.