Sunday, September 30, 2018

How to display your Windows installation on GRUB during boot after Centos 7 installation




Sometimes when you install Centos 7, your Windlows installation may fil to siaplay in GRUB. To resolve this, you need to run a script to detect operating systems installed then generate the grub configuartion file a new.

1. Check if Windows is detected. This is done by running grub2-mkconfig but discard it’s output

$  sudo grub2-mkconfig > /dev/null 
[sudo] password for wm: 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ae7675c335964b24b4eef02de916ece2
Found initrd image: /boot/initramfs-0-rescue-ae7675c335964b24b4eef02de916ece2.img
Found Windows 7 (loader) on /dev/sda1
done

2. If Windows is listed as above, now run the command again and save the configuration file. It’s good to first make a backup of current configuration file.

$ sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

3. Now if all went well, you should boot into Windows.

Extra
If you would like to edit the names of operating systems displayed by grub, simply access the grub config file and make the edits.

$ sudo vim /boot/grub2/grub.cfg

Friday, September 28, 2018

How to manually move the owncloud data directory to another location


These are the steps taken to manually move a data directory from it’s current location to a new location in ownCloud. Some of the reasons you’d like to move your data directory are:
  • You need to migrate your data to bigger space if your current drive is running out of space
  • You may have issues with your Apache loading .htaccess files needed to secure your data directory from internet access. Instead of enabling .htaccess processing, you could just move the data directory to a new location

Prerequisites
OwnCloud already installed and running on Apache web server, Centos 7
In this tutorial, I assume the following:
  • Your current data directory is /var/www/html/owncloud/data
  • Your new directory is /mnt/new/owncloud

Move the data directory
First of all, copy a backup of your data directory. It’s always important to have a backup.
1. Stop apache web server

[root@centos7box]# systemctl stop httpd

2. Copy/Move the files from current data directory to new data directory. You can use cp, rsync or mv commands to achieve this. Here, I use rsync command with -a option to make sure file attributes are maintained while copying to the new location

[root@centos7box]#rsync -avz /var/www/html/owncloud/data /mnt/new/owncloud

3. Create a symbolic link from the new directory to the old one. For me, this was the step I was missing. Without this, the new owncloud directory would have permission issues. Files would be displayed on the web browser accounts but you can’t open them or download. You also wouldn't be able to upload new files.

[root@centos7box]# ln -s /mnt/new/owncloud /var/www/html/owncloud/data


4. Check if your directory permissions are okay. You should have your directory permissions matching those of the old data directory location. Here is a simple table with the old and new permissions, owners and group

OLD
/var/ root:root 755
/www/ root:root 755
/html/ root:apache 755
/owncloud/ root:apache 755
/data/ apache:apache 770

NEW
/mnt/ root:root 755
/new/ root:apache 755
/owncloud/ apache:apache 770

5. Start apache
[root@centos7box]# systemctl start httpd

Refernces


Thursday, September 27, 2018

How to create your private nameservers


Prerequisites/Requirements

  • VPS installed with CentOS and a web server such as Apache
  • Registered domain name
  • First, point your domain to a working hosting and create two A records in the Zone Editor, each for your two name servers. Eg ns1.example.com and ns2.example.com. Point each of this A records to your server’s IP. Test to see that when you access the nameservers above, they display the landing page of your VPS. You can also ping them to see if they respond with your server IP.
  • In your client area, click on Register Private Nameservers and add the two ns1.example.com and it’s IP and ns2.example.com and it’s IP.
  •  Great, now you are ready to create the DNS files.  
Set up DNS zone on your VPS


1. Access the VPS via SSH

ssh user@hostname
2. Install bind and dnsutils, which will allow us to use the dig command later on

Centos or Fedora: yum install bind dnsutils
Ubuntu ir Debian: apt-get install bind9 dnsutils


3. Create a DNS zone file for the domain that will use the name servers. If the domain is called example.com, here is a sample zone file for the domain. The zone file will be called example.com.db. Save this zone file in /var/named. I will assume your server IP is 10.10.10.10. This file will help map your domain name to the IP.

;
; BIND data file for  example.com
;
$TTL    3h
@       IN      SOA     ns1.example.com. admin.example.com. (
                          1        ; Serial
                          3h       ; Refresh after 3 hours
                          1h       ; Retry after 1 hour
                          1w       ; Expire after 1 week
                          1h )     ; Negative caching TTL of 1 day
;
@       IN      NS      ns1.example.com.
@       IN      NS      ns2.example.com.


example.com.    IN      MX      10      mail.example.com.
example.com.    IN      A       10.10.10.10
ns1                     IN      A       10.10.10.10
ns2                     IN      A       10.10.10.10
www                     IN      CNAME   example.com.
mail                    IN      A       10.10.10.10
ftp                     IN      CNAME   example.com.

 
4. Create similar DNS records as above for your two nameservers, ns1.example.com and ns2.example.com Only replace example.com with ns1.example.com and ns2.example.com in the respective files.

5. Configure reverse DNS records. This zone file teaches our nameservers to resolve a host from an IP address. The file will be called  10.10.10.10.db Also, save this zone file in /var/named

;
; BIND reverse data file for 0.10.10.in-addr.arpa
;
$TTL    604800
0.10.10.in-addr.arpa.      IN      SOA     ns1.example.com.
admin.example.com. (
                          1         ; Serial
                          3h       ; Refresh after 3 hours
                          1h       ; Retry after 1 hour
                          1w       ; Expire after 1 week
                          1h )     ; Negative caching TTL of 1 day
;
0.10.10.in-addr.arpa.       IN      NS      ns1.example.com.
0.10.10.in-addr.arpa.       IN      NS      ns2.example.com.
10.10.10.10.in-addr.arpa.   IN      PTR     example.com.


 
6. Update the BIND configuration file. Note that, at this point, you should have these two files ready. Ie

/var/named/example.com.db
/var/named/10.10.10.10.db

Now, simply open the Bind configuration file using your favourite editor.

vim /etc/named.conf

Then add the following code. Remeber to change example.com to your domain name

zone "example.com" {
       type master;
       file "/var/named/example.com.db";
};

zone "0.217.144.in-addr.arpa" {
       type master;
       file "/var/named/10.10.10.10.db";
};

7. Lastly, add an IP address of a stable DNS server in your /etc/resolv.conf file. For example, if you wish to add google’s DNS server, comment our the content of /etc/resolv.conf and add the following line:

nameserver 8.8.4.4

8. Check binds zone files and configuration
 To  check the configuration files run the following command:

named-checkconf

To check a DNS zone files we can use named-checkzone command:

named-checkzone example.com /var/named/example.com.db

zone example.com/IN: loaded serial 1
OK
For the reverse zone file check

named-checkzone 0.10.10.in-addr.arpa /var/named/10.10.10.10.db

zone 0.168.192.in-addr.arpa/IN: loaded serial 2
OK

9. Restart bind

service named restart

10. You can test the bind server configuration using dig command

dig @10.10.10.10 www.example.com

; <<>> DiG 9.6-ESV-R1 <<>> @10.10.10.10 www.example.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<

Thursday, August 23, 2018

Configuring a Safaricom modem to work in Centos – illustrated using huawei model e303s-1 modem


Requirements
1. Hardware
-computer installed with Centos (I used Centos 6.7)
-safaricom modem with a valid sim card (I used huawei e303s-1)

2. Packages
- wvdial
- usb_modeswitch
These packages can be installed using yum if they are not already in your Centos box:
yum install wvdial
yum install usb_modeswitch

Configuration steps
1. Plug the usb modem and check if it has been detected using the lsusb command.

[WM@Wallace ~]$ lsusb
Bus 002 Device 004: ID 12d1:14fe Huawei Technologies Co., Ltd. Mass Storage Mode

The mode of the dongle could be either Modem/Networkcard mode or Mass storage mode, indicated at the end of the line as above. For the dongle to work, it has to be in Modem mode.

From the output of lsusb, you need to note two codes, 12d1 and 14fe. 12d1 is known as vendor code while 14fe is the product code which indicates the mode the dongle is currently operating in, in this case Mass Storage Mode.

Note: Depending on your USB dongle, these codes may vary. If they don’t match mine, just make sure to note what your codes are and replace mine with yours in this process.

2. If your dongle is not in modem mode, change it by running the following command in terminal

usb_modeswitch -v 0x12d1 -p 0x1506 -H -W

3. Now access the file /etc/usb_modeswitch.conf using an editor. Make sure to have root privileges as editing files in /etc/ require root permission.
[WM@Wallace ~]$ su
Password:
[root@Wallace WM]# vim /etc/usb_modeswitch.conf

Add the following content to that file:

DefaultVendor= 0x12d1
DefaultProduct=0x14fe

TargetVendor= 0x12d1
TargetProductList="1001,1406,140b,140c,141b,14ac,1506"

CheckSuccess=20 MessageContent="55534243123456780000000000000011060000000000000000000000000000"
NB
Question:
Where do we get the content to add to /etc/usb_modeswitch.conf?
Answer:
DefaultVendor and DefaultProduct are obtained from lsusb command when running the command after connecting the dongle for the first time. Note that in my case, these are the codes I obtained in step 1 above.

TargetVendor, TargetProductList and Message Content are obtained from /etc/usb_modeswitch.d. Inside this directory are several custom files of the form DefaultVendor:DefaultProduct e.g 03f0:002a, 19d2:2000 etc. Find the one whose name matches your codes and get into it. The TargetProductList can be replaced with TargetProduct=0x1506, where 1506 is the code of the dongle in Modem Mode. If you use the TargetProductList, make sure one of the codes in the list is for your dongle in Modem mode.

However for my computer there was no file 12d1:14fe as needed for my dongle, so I took the content of my usb_modeswitch.conf file from Sachin Sharma's blog and edited it appropriately.

4. Now open /etc/wvdial.conf in an editor, copy the following contents to it and save.

[Dialer Defaults]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Init3 = AT+CGDCONT=1,"IP","safaricom"
Password = data
Phone = *99#
Modem Type = Analog Modem
Stupid Mode = 1
Baud = 9600
New PPPD = yes
Modem = /dev/ttyUSB_utps_modem
ISDN = 0
Username = saf
Carrier Check = no
FlowControl = Hardware(CRTSCTS)
Init3 = AT+CPIN=xxxx

In the last line of the above content, replace xxxx with the pin of your safaricom sim card. If the sim card doesn’t have a pin, remove that line from the file.

5. Once you’ve done all these, connect using wvdial command.

[root@Wallace WM]# wvdial
--> WvDial: Internet dialer version 1.60
--> Cannot get information for serial port.
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2
ATQ0 V1 E1 S0=0 &C1 &D2
OK
--> Sending: AT+CPIN=5362
AT+CPIN=5362
OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier.
ATDT*99#
CONNECT
--> Carrier detected. Starting PPP immediately.
--> Starting pppd at Thu Sep 7 10:08:43 2017
--> Pid of pppd: 31703
--> Using interface ppp0
--> pppd: 5
--> pppd: 5
--> pppd: 5
--> pppd: 5
--> pppd: 5
--> local IP address 105.160.80.173
--> pppd: 5
--> remote IP address 10.64.64.64
--> pppd: 5
--> primary DNS address 196.201.216.21
--> pppd: 5
--> secondary DNS address 196.201.217.7
--> pppd: 5
--> pppd: 5


Modem connects now!

Scipt to do this for you.

#!/bin/bash
sleep 2
cat /home/WM/pswd | sudo usb_modeswitch -v 0x12d1 -p 0x1506 -H -W
sleep 2
cat /home/WM/pswd | sudo wvdialconf
wvdial


Troubleshoot
Issue 1: Device or resource busy.
Ensure you run dongle as root.

Issue 2: +CME ERROR 11. Sim PIN required.
Occurs when you try to access sim card that has a pin without providing the pin. Refer to the Step 4 in this article to see the line you ought to add to your /etc/wvdial.conf file.

Issue 3: +CME ERROR 3. Operation not allowed.
I haven’t quite figured out what causes this error. But what I realized was that, every time you run wvdial the wvdial.conf file is edited. The following line is removed
Init3 = AT+CGDCONT=1,"IP","safaricom"
Perhaps its got something to do with this error. Don’t know though! But thought I should mention it!
Also, make sure your sim card is inserted properly. These micro sim cards are hard to align with the big slots of modems sometimes.

Issue 4: +CME ERROR number, where number is an integer between 0 – 772. Refer to this link obtained from Micromedia about CME errors and their description.


References
2. sachinsharm.wordpress.com/2013/08/11/installing-and-configuring-usb-3g-datacard-on-centosrhel-6-3/
3. https://bbs.archlinux.org/viewtopic.php?id=171617
4. https://www.thefanclub.co.za/how-to/how-setup-usb-3g-modem-raspberry-pi-using-usbmodeswitch-and-wvdial
5. http://blog.magiksys.net/linux-umts-modem-wvdial-usb_modeswitch-mobistar
7. man pages for wvdial and usb_modeswitch