Linux

From 太極
Jump to navigation Jump to search

Not-so-obvious Linux commands

Compress a folder without full path name

Suppose we want to compress the folder ~/Documents and its subfolders. We want to include Documents folder name but not /home/brb/Documents name.

tar -czvf tmp.tar.gz -C ~/ Documents
tar -tzvf tmp.tar.gz

Show folder size for one level only

du --max-depth=1 -h

Debian/Ubuntu

Set static IP

root@debian:~# cat /etc/network/interfaces
auto lo eth0
iface lo inet loopback
iface eth0 inet dhcp

Now edit the file /etc/network/interfaces

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
gateway 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255

After it, restart network

/etc/init.d/networking restart

Change IP address from the command line

/sbin/ifconfig eth0 192.168.1.17 netmask 255.255.255.0 up
/sbin/ifconfig eth0

Dyndns

See https://help.ubuntu.com/community/DynamicDNS

nano /etc/ddclient.conf

daemon=600
protocol=dyndns2
use=web, web=checkip.dyndns.com, web-skip='IP Address'
server=members.dyndns.org
login=YOURNAME
password='YOURPASSWORD'
taichi.selfip.net

And run ddclient -daemon=0 -debug -verbose -noquiet to confirm it is working.

webmin

See http://www.webmin.com/deb.html

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.600_all.deb
dpkg --install webmin_1.600_all.deb

The install will be done automatically to /usr/share/webmin, the administration username set to root and the password to your current root password. You should now be able to login to Webmin at the URL http://localhost:10000/. Or if accessing it remotely, replace localhost with your system's IP address.

Install guest addition for virtualbox

See the link [1]

apt-get update
apt-get install build-essential module-assistant
m-a prepare
cd Downloads
tar xzvf /media/cdrom0/VMwareTools-9.2.0-799703.tar.gz
cd vmware-tools-distrib
./vmware-install.pl
[Accept all default]
shutdown -r now

Remote desktop connection

  1. Go to System -> Preference -> Remote desktop. Allow other uses to view your desktop & uncheck you must confirm each access & require user to enter this password.
  2. Go to System -> Preference -> Monitor. Change monitor resolution to 1280 x 720.

Instal sshd

apt-get update
apt-get install openssh-server

Install LAMP

See the page [2]

apt-get install apache2
a2enmod rewrite
apt-get install mysql-server   [I choose branch name as MYSQL root password]
apt-get install php5 php-pear php5-suhosin
apt-get install php5-mysql
/etc/init.d/apache2 restart

Another instruction including how to set up user directories for Apache web server http://wiki.debian.org/LaMp

apt-get install mysql-server mysql-client
mysql_secure_installation
apt-get install apache2 apache2-doc
apt-get install php5 php5-mysql libapache2-mod-php5
apt-get install python libapache2-mod-python

The apache configuration file is in /etc/apache2/apache2.conf.

Restarting apache before testing on web browser

/etc/init.d/apache2 restart

Install mediawiki

And also the link http://www.mediawiki.org/wiki/Manual:Running_MediaWiki_on_Debian_GNU/Linux

aptitude install mediawiki php5 apache2 mediawiki-extensions libapache2-mod-php5

This will install latex. After the end, we can use Synaptic package manager to see what were installed. Now following the instruction in https://help.ubuntu.com/community/MediaWiki, we remove the '#' from the third line so that it reads 'Alias /mediawiki /var/lib/mediawiki':

sudo nano /etc/mediawiki/apache.conf
sudo /etc/init.d/apache2 restart

Now we can start mediawiki by opening a browser and pointing it to http://localhost/mediawiki.

We need to enter

Site config
  admin username: WikiSysop
  password:

Database config
  Database name: wikidb
  DB username: 
  DB password: 
  Superuser name: root
  Superuser password: [depend on how it was chosen when installing MYSQL]

Press the button of "Installing mediawiki". We will be welcomed to the wiki page. Following the instruction,

Backup and Restore mediawiki

See docs.google.com note. The process involves 3 parts: mediawiki system, mysql and images.

Install moinmoin

MYSQL security

Just execute mysql_secure_installation from the command line.

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database, which by default can be accessed by anonymous users.

See http://www.mysql-optimization.com/mysql-secure-installation-program.html

Compiling R

Use the following command to download required components before building any R packages. See also ubuntu package for R

sudo apt-get build-dep r-base

Remote desktop connection

If vino failed, then try teamviewer. It works fine. After launching it, the software automatically creates an ID and password. We can change the password so it is fixed. Then launch the software on the client. Use the partner's ID and password to connect to it.

View logs

  • Apache /var/log/apache2/access.log

File does not exist: /var/www/favicon.ico from /var/log/apache2/error.log

The reason? You have not created a favicon, also known as a website icon, for your website. It’s the icon that displays in the address bar of your web browser when you connect to a website. A web browser will request this icon file from every website.

If you choose to create one. Use a program such as Gimp and create a 16×16 pixel image and save it as a .ico filetype. Then upload that file to the DocumentRoot of your website. You will need one for each VirtualHost. If you don’t have Gimp, there are online resources such as favicon.cc where you can create a .ico file and download it for your own use.

As you know by now, not having a favicon.ico file, won’t stop web browsers from requesting it each time. But you can tell Apache not to log the event as an error message. You will still see the request in the access.log, but at least you will have a cleaner error.log file.

Add the following block of code to each VirtualHost, or at least the ones which don’t have a favicon file.

Redirect 404 /favicon.ico
<Location /favicon.ico>
 ErrorDocument 404 "No favicon"
</Location>

Don’t forget to restart apache after making the change. If you want make a “global” change, which would apply to any and all VirtualHosts, you can create a file in Apache’s conf.d folder with a name such as nofavicon.conf and then add that block of code to the file. That would disable favicon across the board and save you from having to edit each VirtualHost.

Or, you create an empty file with the name “favicon.ico” in the directory root of Apache (for exemple /var/www/).

RHEL/CentOS

Pogoplug

Install ArchLinux on pogoplug

See the instruction in http://archlinuxarm.org/platforms/armv5/pogoplug-v2-pinkgray for how to install Archlinux on pogoplug (E02). I make a copy below.

killall hbwd
cd /tmp
wget http://jeff.doozan.com/debian/uboot/install_uboot_mtd0.sh
chmod +x install_uboot_mtd0.sh
./install_uboot_mtd0.sh
/sbin/fdisk /dev/sda

At the fdisk prompt, delete old partitions and create a new one:

  • Type o. This will clear out any partitions on the drive.
  • Type p to list partitions. There should be no partitions left.
  • Now type n, then p for primary, 1 for the first partition on the drive, and then press ENTER, accepting default values.
  • Exit by typing w.
wget http://archlinuxarm.org/os/pogoplug/mke2fs
chmod 755 mke2fs
./mke2fs /dev/sda1
mkdir usb
mount /dev/sda1 usb
cd usb
wget http://archlinuxarm.org/os/ArchLinuxARM-armv5te-latest.tar.gz
tar -xzvf ArchLinuxARM-armv5te-*.tar.gz  # This will take a long time
rm ArchLinuxARM-armv5te-*.tar.gz
sync  # Takes a while when using a flash drive. Not in my case however.
cd ..
umount usb
/sbin/reboot

Log back in after your Pogoplug reboots using username root and password root.

At the end, the system is very lean.

[root@alarm ~]# free
             total       used       free     shared    buffers     cached
Mem:        252492      28292     224200          0       4580      14072
-/+ buffers/cache:       9640     242852
Swap:            0          0          0
[root@alarm ~]# df -lh
Filesystem      Size  Used Avail Use% Mounted on
rootfs          7.4G  443M  6.6G   7% /
/dev/root       7.4G  443M  6.6G   7% /
devtmpfs        124M     0  124M   0% /dev
run             124M  224K  124M   1% /run
shm             124M     0  124M   0% /dev/shm
tmpfs           124M     0  124M   0% /tmp
[root@alarm ~]# uname -a
Linux alarm 3.1.10-13-ARCH #1 PREEMPT Mon Aug 20 15:46:18 UTC 2012 armv5tel GNU/Linux
[root@alarm ~]# cat /proc/cpuinfo
Processor	: Feroceon 88FR131 rev 1 (v5l)
BogoMIPS	: 1191.11
Features	: swp half thumb fastmult edsp 
CPU implementer	: 0x56
CPU architecture: 5TE
CPU variant	: 0x2
CPU part	: 0x131
CPU revision	: 1

Hardware	: Marvell SheevaPlug Reference Board
Revision	: 0000
Serial		: 0000000000000000
[root@alarm ~]# cat /proc/cpuinfo
Processor	: Feroceon 88FR131 rev 1 (v5l)
BogoMIPS	: 1191.11
Features	: swp half thumb fastmult edsp 
CPU implementer	: 0x56
CPU architecture: 5TE
CPU variant	: 0x2
CPU part	: 0x131
CPU revision	: 1

Hardware	: Marvell SheevaPlug Reference Board
Revision	: 0000
Serial		: 0000000000000000
[root@alarm ~]# 

After it, follow the instruction on lifehacker and https://wiki.archlinux.org/index.php/DeveloperWiki:usrlib

pacman -Syu --ignore glibc
pacman -Su
mkinitcpio -p linux

To install rsync, use

pacman -S rsync

Unfortunately, I cannot bypass the error

[root@alarm ~]# pacman -Suy rsync
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 community is up to date
 alarm is up to date
 aur is up to date
:: Starting full system upgrade...
resolving dependencies...
looking for inter-conflicts...

Targets (2): glibc-2.16.0-4  rsync-3.0.9-5

Total Installed Size:   34.26 MiB
Net Upgrade Size:       0.61 MiB

Proceed with installation? [Y/n] 
(2/2) checking package integrity                        [#############################] 100%
(2/2) loading package files                             [#############################] 100%
(2/2) checking for file conflicts                       [#############################] 100%
error: failed to commit transaction (conflicting files)
glibc: /lib exists in filesystem
Errors occurred, no packages were upgraded.

Install Debian on pogoplug

See the instruction on http://projects.doozan.com/debian.

  • Find your devices's IP address and connect via SSH:
  • Partition your flash drive with fdisk:
fdisk /dev/sda
# Configure partion 1 as Linux (I'd recommend making this at least 512Mb. The default bare-bones installation uses 280Mb.)
# Configure partion 2 as Linux Swap (I used 256MB.  Adjust according to your anticipated memory usage.)
# Set partition 1 active
  • Download and run the Debian Wheezy installer:
cd /tmp
wget http://projects.doozan.com/debian/kirkwood.debian-wheezy.sh
chmod +x kirkwood.debian-wheezy.sh
export PATH=$PATH:/usr/sbin:/sbin
./kirkwood.debian-wheezy.sh
  • Alternatively, you can choose to install Debian Squeeze with the following commands:
cd /tmp
wget http://projects.doozan.com/debian/dockstar.debian-squeeze.sh
chmod +x dockstar.debian-squeeze.sh
export PATH=$PATH:/usr/sbin:/sbin
./dockstar.debian-squeeze.sh

The script will take some time to download the debian images and extract them to your flash drive. The total install time will vary with the speed of your flash drive and your Internet connection. On my system, it takes about 20 minutes. Once it's finished, you can reboot into your new Debian install.

After your device reboots, it may have a different IP address (it's identifying as 'Debian' to the DHCP server now instead of 'Pogoplug').

The default root password in Debian is 'root'. After you've logged in, you should change the root password and configure /etc/apt/sources.list to point to a Debian mirror near you.

passwd
nano /etc/apt/sources.list

After reboot, the debian system is very lean too


root@debian:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                3.2G  260M  2.8G   9% /
none                  123M   36K  123M   1% /dev
/dev/sda1             3.2G  260M  2.8G   9% /
tmpfs                 125M     0  125M   0% /lib/init/rw
tmpfs                 125M     0  125M   0% /dev/shm
tmpfs                 125M     0  125M   0% /tmp
root@debian:~# free
             total       used       free     shared    buffers     cached
Mem:        255672      19636     236036          0        816      11104
-/+ buffers/cache:       7716     247956
Swap:       535544          0     535544

After I install LAMP, the memory uses 250MB. However, after I reboot the pogoplug, it reduces to 66MB.

root@debian:~# free
             total       used       free     shared    buffers     cached
Mem:        255672      66076     189596          0       1244      37000
-/+ buffers/cache:      27832     227840
Swap:       535544          0     535544

Other resources: