CentOS to MS Hyper-V Volume Issues

After making an image of a physical linux box (Dell hardware running CentOS), I converted the IMG file to a VDH file and after booting had many issue. One of which was the following error which caused all databases on the respective volume to fail because the volume was in read-only mode.

EXT3-fs error (device hda3) in start_transaction: Journal has aborted

Turns out, the system is telling me that it’s detected a file system/journal mismatch, and it can’t utilize the journal any longer. When this situation pops up, the file system gets mounted read-only. To fix the situation, I had to boot the system (now in the VM environment) in single user mode, dismount the volume and fix it.

I first started by removing the journal from the file system:

# tune2fs -O ^has_journal /dev/hda3

Then I tried to fsck it to correct any possible problems:

# e2fsck -p -f -v /dev/hda3

Unfortunately this lead me to another error: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY. (i.e., without -a or -p options).

Ugh. fsck again….I had originally run it without the -f option and it found no errors, yet it refused to mount in read-write mode. So now running it sans the -p option, -f forcing it to check it anyway, seems to have helped- but this time I needed to be present to hit y to every single error. There were hundreds.

Once that finished I ran it again with the -y option to see if it picked up anything and it was clean!

Time to make a new journal which makes the partition an ext3 file system again:

# tune2fs -j /dev/hda3

I can now mount the partition as an ext3 partition:

# mount -t ext3 /dev/hda3 /mnt/fixed

After rebooting the system seems happy once again with no mounting errors. Quick and simple!

QNAP NAS SSH Service Commands

I use several QNAP devices from the large 24 drive down to a personal 2 drive. I’ve found that they are pretty good and you can do a lot with them as they’re basically Linux boxes with a pretty web interface.

Here are some useful console commands for restarting specific services.

First, to restart basically everything you can issue this command:

/etc/init.d/services.sh restart

One of the most common ones is to restart smb:

/etc/init.d/smb.sh restart

Here’s a list of other common ones: (They’re all in /etc/init.d)
I believe they will all accept the restart option. They will accept start/stop options.

QMediaService.sh
Qthttpd.sh
StartMediaService.sh
bonjour.sh
crond.sh
ftp.sh
mysqld.sh
network.sh
opentftp.sh
qsyncman.sh
rsyncRR.sh
rsyncd.sh
rsyncd_srv.sh
rsyslog.sh
samba4.sh
services.sh
timemachine.sh
vpn_openvpn.sh
vpn_pptp.sh
webalizer.sh

Enabling SNMP On CentOS / RHEL

Setting up SNMP (Simple Network Management Protocol) on a CentOS machine is a very quick and easy process and I often forget so here’s a quickie on how.

Install the SNMP daemon by running the following command:

yum install net-snmp

Once SNMP is installed you want to install the configuration utility. I always forget this. It makes it easy to configure SNMP for both the community string,  SNMP version and basic security.

yum install net-snmp-utils

Once the configuration tool is installed, run it:

snmpconf -g basic_setup

As you run through the configuration utility it will present you with many options. Depending on how you have your remote monitoring setup (Cacti/Nagios) you will need to choose the options that work for you.

Once done, you will need to copy the configuration file to the correct directory. In most cases it will need to be moved from “/root/snmpd.conf” to “/etc/snmp/snmpd.conf” – You will need to overwrite the existing conf file in the /etc/snmp/ directory.

mv /root/snmpd.conf /etc/snmp/

Once the configuration file has been moved over you can restart SNMP.

service snmpd restart

The last thing you need to do is have SNMP start at boot time. If you do not run the following command you will need to manually start SNMP after a reboot.

chkconfig snmpd on

At this point you should be set. If for some reason you are running the firewall will need to open port 161 for UDP & TCP traffic to allow SNMP to be accessed remotely.

Sending Syslog logs from Ubuntu to a remote syslog server

I don’t know why I didn’t have notes on this already. I’ve done it dozens of times. So here’s the write up.

I use Ubuntu and it uses the syslog facility/daemon called rsyslogd. Its configuration file is located here:

/etc/rsyslog.d/50-default.conf

This file tells the deamon where to log each type of message. For example the follow entry means that all cron message are sent to /var/log/cron.log:

cron.* /var/log/cron.log
Continue reading “Sending Syslog logs from Ubuntu to a remote syslog server”

MySQL Truncating or Dropping All Tables in a Database

I just had the need to truncate all the tables in of my databases. Basically I wanted the data gone but the schema to stay. Below is the linux shell command I used to truncate the tables.

I’ve also included how to straight up drop the tables too- just keep in mind dropping tables dumps the schema and data.

Truncate

mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "truncate table $table" DATABASE_NAME; done

Drop

mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "drop table $table" DATABASE_NAME; done

Make sure the user executing this has privileges to the database in question.

Get You External IP From Linux via the Command Line

I’m always needing to do this so here’s two quick ways.
[code]wget -qO- http://ipecho.net/plain[/code]
Or if you prefer curl:
[code]curl http://ipecho.net/plain[/code]
The ifconfig.me site
If you browse this website with your normal browser it will show how to get a lot of information from the command line, using curl, to get just the IP you can use:
[code]curl ifconfig.me[/code]
Now if windows was just as easy…if you have curl under Windows it is.

Jeff’s Raspberry Pi Setup Notes

Raspberry Pi Setup Notes

These are the notes I keep for initial setups of the base Raspberry Pi Linux images.  They were collected from all over the internet and from personal experiences. If you find errors let me know. I’m always updating it so check back if you’re looking to add a feature that you can’t find
anywhere else.

Everything here relies on what exists on the internet already. Nothing here is original except that it’s all in one place.

LAMP Setup

sudo apt-get install apache2

OR

sudo apt-get install nginx

 

sudo apt-get install mysql-server

sudo apt-get install php5 php5-mysql

Further  LAMP features

sudo apt-get install php5-fpm php5-cgi php5-cli php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-pspell php5-recode php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache

More Stuff

sudo apt-get install chkconfig snmp net-snmp* imagemagick htop webalizer

 

sudo pear channel-update pear.php.net sudo pear install MDB2

sudo pear install pear/MDB2_Driver_mysql

Webmin

To install Webmin open a terminal and add the following repository:

1- Edit /etc/apt/sources.list file

sudo nano /etc/apt/sources.list

2- Add the following lines

deb http://download.webmin.com/download/repository sarge contrib

deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

Save and exit the file

3- Now you need to import GPG key

wget http://www.webmin.com/jcameron-key.asc

sudo apt-key add jcameron-key.asc

4- Update the source list

sudo apt-get update

5- Now install Webmin

sudo apt-get install webmin

Now to access Webmin open your browser and enter:  http://serverip:10000/

You can get your ip address by issuing this command:

ifconfig

 

Remove any unneeded packages

There will eventually be packages that are unneeded. Apt-get can get rid of them by issuing this command:

 

sudo apt-get autoremove

Remote Desktop

Installing this allows you to connect via RDP on Windows.

sudo apt-get install xrdp

Add Chrome/Chromium to Desktop

Adds “Chrome” web browser to the GUI interface.

sudo apt-get install chromium-browser

Check CPU Clock Speed

This will show the current CPU clock speed in hertz

 cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq

Raspi-config

This is the initial configuration utility. I always forget its name..

sudo raspi-config