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

Debian/Ubuntu

Change IP address

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

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

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.

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.

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

Other resources: