Moving From Working PC to Own USB-Disk Based 3

Trouble Shooting

Unfortuately the qemu based pysical disk can’t bootup the machine correctly, so I re-intall the sytem on USB-Disk from the scratch. This time the problem appears as another: It can startup the machine, but failed to boot-up in qemu.
So I have to changed to use VirtualBox for booting the system.
Get the disk id via:

$ ls -l /dev/disk/by-id
lrwxrwxrwx 1 root root  9 May 22 14:45 usb-ATA_ST980811AS_xxxxxxxx-0:0 -> ../../sdb

Then use VirtualBox’s Internal command for creating the vmdk file, this vmdk file actually contains the physical disk.

$ VBoxManage internalcommands createrawvmdk -filename ./rawusb1.vmdk -rawdisk /dev/disk/by-id/usb-ATA_ST980811AS_XXXXXXXXXXX-0:0
RAW host disk access VMDK file ./rawusb1.vmdk created successfully.
$ sudo chown -R Trusty *

Now create a new virtual machine in virtualbox, use the newly created rawusb1.vmdk, bootup and you got the physical disk based virtual machine running.

Continue Install System

Install virtualenvironment via:

sudo pacman -S python2-virtualenv python-virtualenv python-virtualenvwrapper

In company machine, use pip freeze for getting all of the packages:

$ workon venv2
$ pip freeze>requirement.txt

In usb-disk based machine, install from the requirement.txt

$ mkdir .virtualenvs
# Add following lines into the .bashrc
export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
$ mkvirtualenv -p /usr/bin/python2.7 venv
$ pip install -r requirements.txt

After we update the installation, the package is the same as in computer machine.

ZSH

Install zsh and use it for replacing default bash:

$ sudo pacman -S zsh
$ chsh -s $(which zsh)

Now we can download the .zshrc from the company machine to usb disk based system.

Configure GIT Under Proxy

Setting the proxy and set it for git using proxy:

(venv)[Trusty@localhost ~]$ gcc -o connect connect.c 
(venv)[Trusty@localhost ~]$ sudo mv connect /usr/bin/
(venv)[Trusty@localhost ~]$ sudo chmod 777 /usr/bin/connect 
(venv)[Trusty@localhost ~]$ sudo vim /usr/bin/myproxy
(venv)[Trusty@localhost ~]$ sudo chmod 777 /usr/bin/myproxy
(venv)[Trusty@localhost ~]$ cat /usr/bin/myproxy 
/usr/bin/connect -H 1xx.xxx.xxx.xxx:2xxxx $@
(venv)[Trusty@localhost ~]$ git config --global core.gitproxy "/usr/bin/myproxy for *.*"
(venv)[Trusty@localhost ~]$ git config --global user.name "feixxxx"
(venv)[Trusty@localhost ~]$ git config --global user.email "feixxxx@gmail.com"

BlueTooth

Install blueman:

$ sudo pacman -S patch automake autoconf libtool 
$ yaourt blueman
# choose blueman-bzr
$ sudo pacman -S bluez-utils bluez-libs python2-pybluez
$ yaourt -S bluez4
$ yaourt pulseaudio-bluez4

Configure bluetooth:

$ sudo systemctl start bluetooth
$ sudo systemctl enable bluetooth
$ cat /etc/bluetooth/audio.conf

[General]
Enable=Socket

[A2DP]
SBCSources=1
$ 

Later bluemanager will be added into the awesome startup application.
The configuration is pretty complex, this is the start-point for settingup the bluetooth, later we will configure the bluetooth headset.

Tray items

$ sudo pacman -S udiskie wicd wicd-gtk

Awesome Customization

Download the themes from github:

$ sudo pacman -S hddtemp vicious
$ git clone https://github.com/Morley93/awesome-themes-3.5.git

Still have some problems. Need update.
Then get the customized awesome configuration file. Be sure to use the default, because later you can customize yourself.

Solve wicd error:
Error: Could not connect to wicd’s D-Bus interface

$ sudo pacman -R wicd wicd-gtk
$ sudo rm -rf /etc/wicd /var/log/wicd /etc/dbus-1/system.d/wicd*
$ sudo pacman -S wicd wicd-gtk
$ sudo pacman -Syu systemd-sysvcompat
$ sudo gpasswd -a Trusty users
$ sudo systemctl enable wicd
$ sudo systemctl start wicd

Now your wicd is OK for see.

udiskie2 problem, cannot start because lack of PyYAML:

$ sudo pacman -S python2-pip
$ sudo pip2 install PyYAML

Now seems all of your tray icons will be OK.

System Tools

Install the mlocate so we can use updatedb:

$ sudo pacman -S mlocate
$ sudo updatedb

Moving From Working PC To Own USB-Disk Based

Background

Since I want to hava a usb-based OS which could easily be taken by hand, I took this series for resarching how to finish this aim.

Preparation

ArchLinux iso file, USB-3.0 HardDisk, 80GB, later I will use a bigger one.

Qemu Script

I use qemu firstly to install the system. following is the configuraton file for qemu-i386:

#!/bin/bash
USERID=$(whoami)

# Get name of newly created TAP device; see https://bbs.archlinux.org/viewtopic.php?pid=1285079#p1285079
precreationg=$(/usr/bin/ip tuntap list | /usr/bin/cut -d: -f1 | /usr/bin/sort)
sudo /usr/bin/ip tuntap add user $USERID mode tap
postcreation=$(/usr/bin/ip tuntap list | /usr/bin/cut -d: -f1 | /usr/bin/sort)
IFACE=$(comm -13 <(echo "$precreationg") <(echo "$postcreation"))

# This line creates a random MAC address. The downside is the DHCP server will assign a different IP address each time
printf -v macaddr "52:54:%02x:%02x:%02x:%02x" $(( $RANDOM & 0xff)) $(( $RANDOM & 0xff )) $(( $RANDOM & 0xff)) $(( $RANDOM & 0xff ))
# Instead, uncomment and edit this line to set a static MAC address. The benefit is that the DHCP server will assign the same IP address.
# macaddr='52:54:be:36:42:a9'
  
qemu-system-i386 -net nic,macaddr=$macaddr -net tap,ifname="$IFACE" $*
  
sudo ip link set dev $IFACE down &> /dev/null
sudo ip tuntap del $IFACE mode tap &> /dev/null 

Run the virtual machine like following:

$ ./run-qemu-i386 -hda /dev/sdc -m 1024 -boot d -cdrom  ./archlinux-2014.05.01

Installation Of ArchLinux

When your iso bootup, you will enter command-line, use following command for start the ssh :

# passwd root
# systemctl start sshd
# ifconfig 
# ssh root@10.0.0.240

Partition disk:

# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 74.5 GiB, 80026361856 bytes, 156301488 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc001c001

Device    Boot Start       End   Blocks  Id System
/dev/sda1       2048 156301487 78149720  83 Linux

Command (m for help): d

Selected partition 1
Partition 1 has been deleted.

Command (m for help): n

Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-156301487, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-156301487, default 156301487): +1G

Created a new partition 1 of type 'Linux' and of size 1 GiB.

Command (m for help): t
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): n

Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 
First sector (2099200-156301487, default 2099200): 
Last sector, +sectors or +size{K,M,G,T,P} (2099200-156301487, default 156301487): 

Created a new partition 2 of type 'Linux' and of size 73.5 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@archiso ~ # fdisk -l /dev/sda

Disk /dev/sda: 74.5 GiB, 80026361856 bytes, 156301488 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc001c001

Device    Boot     Start       End   Blocks  Id System
/dev/sda1           2048   2099199  1048576  82 Linux swap / Solaris
/dev/sda2        2099200 156301487 77101144  83 Linux

Now your partition is ok, make filesystems.

# mkfs.ext4 /dev/sda2                                                             
root@archiso ~ # mkswap /dev/sda1
root@archiso ~ # swapon /dev/sda1

Now begin to install system:

# mount /dev/sda2 /mnt
# pacstrap /mnt base

Configuraion:

# genfstab -p /mnt >> /mnt/etc/fstab
# arch-chroot /mnt
sh-4.3# cat /etc/hostname 
FreeArch

sh-4.3# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# Uncomment the items in /etc/locale.gen, and run: 
sh-4.3# locale-gen
Generating locales...
  en_US.UTF-8... done
  en_US.ISO-8859-1... done
  zh_CN.GB18030... done
  zh_CN.GBK... done
  zh_CN.UTF-8... done
  zh_CN.GB2312... done
  zh_TW.EUC-TW... done
  zh_TW.UTF-8... done
  zh_TW.BIG5... done
Generation complete.

sh-4.3# mkinitcpio -p linux
sh-4.3# passwd root

Network Configuration:

sh-4.3# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:94:b5:12:24 brd ff:ff:ff:ff:ff:ff
sh-4.3# pacman -S dhcpcd
sh-4.3# systemctl enable dhcpcd@ens3
ln -s '/usr/lib/systemd/system/dhcpcd@.service' '/etc/systemd/system/multi-user.target.wants/dhcpcd@ens3.service'

BootLoad Configuration:

# pacman -S grub
# grub-install --target=i386-pc --recheck --debug /dev/sda
# grub-mkconfig -o /boot/grub/grub.cfg

Umount and reboot:

umount -R /mnt

Configuration Of System

Install openssh firstly, and net-tools for getting the ipaddress using ifconfig:

pacman -S openssh
systemctl enable sshd
systemctl start sshd
pacman -S net-tools

Now you can use terminal for getting to the qemu-based machine, and sshd service should be enabled always.

Quickly setup an account, because using root is a bad idea.

# useradd -m -g root -G audio -s /bin/bash Trusty
# pacman -S sudo
# visudo
##
## User privilege specification
##
root ALL=(ALL) ALL
Trusty ALL=(ALL) NOPASSWD: ALL
## Locale settings
# Defaults env_keep += "LANG LANGUAGE LINGUAS LC_* _XKB_CHARSET"
Defaults env_keep += "http_proxy https_proxy ftp_proxy ftps_proxy"

Now you can use the newly added username “Trusty” for login.

Install yaourt, add following lines into the file /etc/pacman.conf:

[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/$arch

Then update and install yaourt:

sudo pacman -Syu && sudo pacman -S yaourt

Next chapter we will begin to install softwares.

Moving From Working PC To Own USB-Disk Based 2

Install Software

Internet

Chromium, we need this browser absolutesly:

$ sudo pacman -S chromium
Select 1/8

Oh, we forget install X, so first we will install X:

X Window

Install xorg first:

$ sudo pacman -S xorg xorg-xinit

Awesome Window Manager;

$ sudo pacman -S awesome

Edit the .xinitrc file, add following lines:

exec awesome

Necessary video driver:

$ sudo pacman -S xf86-video-intel xf86-video-ati

Continue Internet

Firefox, another browser, pidgin, for chatting, thunderbird for email, wget for downloading:

sudo pacman -S firefox pidgin thunderbird wget

Office

Libreoffice,need download 253MB, so take a break:

$ sudo pacman -S libreoffice
# choose Enter-> 25-> Enter

Terminals

Install xterm first, initial term:

$ sudo pacman -S xterm

xfce4-terminal will be installed in next chapterVncserver.
gnome-terminal is a good option:

$ sudo pacman -S gnome-terminal

Vncserver

Install tigervnc

$ sudo pacman -S tigervnc

Use xfce4 for remote vnc(For many users may not familiar with awesome desktop):

$ sudo pacman -S xfce4 
# choose (default=all)

Configure vncserver:

$ cat ~/.vnc/xstartup 
#!/bin/sh

export XKL_XMODMAP_DISABLE=1
exec startxfce4

With VNC, you can start up the X and let the chromium sync up its bookmarks.

Documents

Install evince for viewing pdf and other documents:

$ sudo pacman -S evince

Install gimp for processing pictures:

$ sudo pacman -S gimp

Video/Fun

Install smplayer:

sudo pacman -S smplayer

Without ALSA, you can do nothing, so install it.

sudo pacman -S alsa-utils

Development

Install gvim and eclipse:

$ sudo pacman -S gvim eclipse

Git and Subversion:

$ sudo pacman -S git subversion

Wireshark and Tcpdump:

$ sudo pacman -S wireshark-gtk tcpdump

ddd and gdb for debugging:

$ sudo pacman -S ddd gdb

meld for comparing files:

$ sudo pacman -S meld

Virtualization

Install qemu and virtualbox:

sudo pacman -S virtualbox qemu

Chinese Localization

Install fonts for chinese:

$ sudo pacman -S wqy-bitmapfont wqy-microhei wqy-microhei-lite wqy-zenhei

Install fcitx input method:

$ sudo pacman -S fcitx fcitx-libpinyin fcitx-configtool fcitx-qt4 fcitx-qt5

Configuration will be wrote later.

System Tools

rox for file browser:

$ sudo pacman -S rox

gpicview for picture viewer:

$ sudo pacman -S gpicview

Conky for viewing the tasks:

$ sudo pacman -S conky

.conky file will be downloaded from the github(Later I will upload). .xinitrc file will be uploaded to github.

Now step2 is OK, we will use usd-disk for rebooting.

Using HardDisk For Booting RaspberryPI

准备

RaspberryPI, SD卡(4G以上), 移动硬盘,操作系统镜像文件,最好有一个外接供电带电路隔离的USB HUB。 鼠标、键盘等。

用SD卡启动

将SD卡插入电脑,将镜像文件写入到SD卡后,将写好的SD卡插入RaspberryPI,加电开机。各种配置(譬如显存大小,是否启动到X等等)完成之后,进入到Linux桌面。

准备硬盘

将硬盘插入USB口,如果之前有分好区的,可以略过这一节,直接到拷贝至硬盘一节。
在RaspberryPI系统里(wheezy or archLinux),搜索gparted, 这个工具可以在图形化界面下对硬盘进行分区。
命令行下你可以通过下列命令查看已挂载的存储设备信息:

[root@alarmpi ~]# fdisk -l

Disk /dev/mmcblk0: 7.3 GiB, 7822376960 bytes, 15278080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00047c7a

Device         Boot     Start       End  Blocks  Id System
/dev/mmcblk0p1           8192    122879   57344   c W95 FAT32 (LBA)
/dev/mmcblk0p2         122880  15278079 7577600  83 Linux


Disk /dev/sda: 465.8 GiB, 500105740288 bytes, 976769024 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0004f23a

Device    Boot     Start       End    Blocks  Id System
/dev/sda1           2048   1050623    524288  82 Linux swap / Solaris
/dev/sda2        1050624 126879743  62914560  83 Linux
/dev/sda3      126879744 546310143 209715200   7 HPFS/NTFS/exFAT
/dev/sda4      546310144 976769023 215229440   5 Extended
/dev/sda5      546312192 588255231  20971520  83 Linux
/dev/sda6      588257280 976769023 194255872  83 Linux

上面的代码中可以看到,我的RaspberryPI上挂载的硬盘大小是500G。分成了若干个区。

拷贝文件系统到硬盘分区

分区决定于你自己,用gparted或者别的分区工具都可以分好,记得选择Linux ext4为文件系统。
这里我选择/dev/sda5作为我的根分区,所以在终端上,执行下列命令:

$ mkfs.ext4 /dev/sda5
$ sudo mount /dev/sda5 /mnt
$ cd /mnt
$ tar cjvf /mnt/rootfs.tar.bz2 /

备份完毕后,解压:

$ tar xjvf /mnt/rootfs.tar.bz2 -C /mnt/

这里用tar备份文件系统时主要是为了防止系统中某些可能的链接/设备文件的丢失,干脆先压缩后再解压,一劳永逸,代价是时间会花多一点。用rsync是既保险又快速的方法,如果你系统上安装了rsync,试下下面的命令:

rsync -rv --exclude=/mnt / /mnt

总之,这一步的目的是把SD卡上的文件系统完整复制到硬盘分区上。

修改启动选项

修改SD的boot分区上内容,文件cmdline.txt以使得其适配硬盘启动:

$ cd /boot
$ cp cmdline.txt cmdline.txt.SD
$ >cmdline.txt
$ echo "smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda5 rootfstype=ext4 elevator=noop rootwait">cmdline.txt

上面命令的作用是把root=参数从root=/dev/mmcblk0p2换到root=/dev/sda5,你的硬盘分区可能不是sda5,这取决于你在上两步中采用了哪块分区。例如sda(1?2?3?4?),这里的数值和你在上两步中应该保持一致。
如果你的移动硬盘上创建了交换分区,即swap分区,记得在/etc/fstab文件中加入相应的条目,下面是的系统上,用sda1作为swap分区时的配置

# cat /etc/fstab
# 
# /etc/fstab: static file system information
#
# <file system>	<dir>	<type>	<options>	<dump>	<pass>
/dev/mmcblk0p1  /boot           vfat    defaults        0       0
/dev/sda1  	none		swap 	defaults        0       0

为了确保写入成功,在操作的最后,麻烦运行一下:

$ sudo sync

这可以保证所有的外接设备上的数据被安全写入。

没有问题的话,现在重新启动RaspberryPI,你的文件系统就应该跑在硬盘上了。

如果有失败的话,把SD卡插入电脑,把cmdline.txt文件恢复成cmdline.txt.SD文件即可。

特别强调

特别强调的一点,彻底从硬盘启动是不可能的!!!也就是说,你依然需要插入一张SD卡在RaspberryPI的槽中。因为RaspberryPI每次都是从固定地址读取启动代码的。
上述做法的好处是避免了频繁读写SD卡,延长了SD卡的使用寿命。
缺点是: USB硬盘的速度,最多也就是USB2.0的极速。 SD卡,CLASS10的速度可能要超过USB2.0的速度。某些时候会慢一点,但是秒杀CLASS4的卡是没问题的。

Node.js Quick Start

Installation

Via following command

$ yaourt -S nodejs

Quick Start

$ node
> console.log("Hello!")
Hello!
undefined

Hit twice “Ctrl+c” you will get out of the terminal.
A simple example is like:

var http = require("http");

http.createServer(function(request, response) {
	  response.writeHead(200, {"Content-Type": "text/plain"});
	    response.write("Hello World");
	      response.end();
}).listen(8888);
$ node server.js

$ curl http://localhost:8888
Hello World%