LINUX 1. Linux install 2. Booting sequence 3. Kernel rebuilding 4. Patch 5. RPM (Red Hat Package Manager) 6. NFS (Network File System) 7. NIS (Network Information System) 8. Cluster 9. Daemon programming 10. Review -
1. Linux install 1. Repartition partition table - MBR(master boot record) primary, extended, logical partition tablesize 4 1 driveprimary partition extended - logical partition container Dual OS system: MS-DOS partitionlinux OS repartition 1. MS-DOS fdisk MS-DOS size partition and MS-DOS format 2. fips - partition paririon ** data ** maginpartition Drives and partitions under Linux First floppy - /dev/fd0 Second floppy - /dev/fd1 First hard disk (entire) - /dev/hda First hard disk, primary partition 1 - /dev/hda1 First hard disk, primary partition 2 - /dev/hda2 First hard disk, primary partition 3 - /dev/hda3 First hard disk, primary partition 4 - /dev/hda4 First hard disk, logical partition 1 - /dev/hda5 First hard disk, logical partition 2 - /dev/hda6... Second hard disk -- hda -> hdb SCSI -- hda -> sda First MS-DOS partition (C:) - /dev/hda1 Second MS-DOS partition (D:) - /dev/hda2 First Linux logical partition - /dev/hda5 Second Linux logical partition - /dev/hda6 2. Boot the Linux installation media * CD booting boot floppy - rawrite small Linux diskette
: rawrite boot.img a: 3. Create Linux partition # fdisk /dev/hda 4. Create filesystems (formatting) # mke2fs -c /dev/hda2 82080! second extended filesystem make 82080 blocks(1024bytes) on /dev/hda2 # mount -t ext2 /dev/hda2 /home /etc/fstab boot mount 5. Create swap space swap space - virtual space filesystem # mkswap -c partition size # swapon partition # mkswap -c /dev/hda3 10336 # swapon /dev/hda3 6. Install the software on the new filesystems 7. Booting using LILO (1) /etc/lilo.conf :boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=5 image=/boot/vmlinuz-2.2.5-22 # Linux kernel label=linux root=/dev/hda2 # root partition other=/dev/hda1 # partition table=/dev/hda # partition table for /dev/hda1 label=win98 (2) # lilo Install Xfree86
X server, mouse, keyboard # xf86config /etc/x11/xf86config /usr/x11r6/bin/x : X server driver link file # ls -l X lrwxrwxrwx 1 root root 8 Mar 23 22:53 X -> XF86_Mach64 # ln -s /usr/x11r6/bin/xf86_mono /usr/x11r6/bin/x Network Configuration 1. hostname /etc/hostname hpc.kangnung.ac.kr 2. IP addres /etc/hosts 127.0.0.1 localhost localhost.localdomain 211.114.217.xxx hpc.kangnung.ac.kr hpc 3. nameserver /etc/resolv.conf nameserver 211.114.216.1 4. router(gateway) /etc/sysconfig/network NETWORKING=yes FORWARD_IPV4=no HOSTNAME=hpc.kangnung.ac.kr DOMAINNAME=kangnung.ac.kr GATEWAY=211.114.217.98 GATEWAYDEV=eth0 * # route add * UNIX - /etc/defaultrouter
5. network interface /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 IPADDR=211.114.217.xxx NETMASK=255.255.255.0 NETWORK=211.114.225.0 BROADCAST=211.114.225.255 ONBOOT=yes BOOTPROTO=none USERCTL=no /etc/sysconfig/network-scripts/ifcfg-lo DEVICE=lo IPADDR=127.0.0.1 NETMASK=255.0.0.0 NETWORK=127.0.0.0 BROADCAST=127.255.255.255 ONBOOT=yes BOOTPROTO=none * # ifconfig *** # netcfg Add an user 1. user id /etc/passwd ykim::1000:1000:youngtae Kim:/home/ykim:/bin/tcsh /etc/shadow ykim:143:0:99999:7:::134535364 2. user home directory # cd /home # mkdir ykim # chown ykim ykim # chgrp 1000 ykim ** delete an user
2. Booting sequence Booting sequence (* lilo booting) 1. /etc/lilo.conf Linux kernel booting 2. kernel /sbin/init /etc/inittab : init 2.1 /etc/rc.d/rc.sysinit 2.1.1 network <- /etc/sysconfig/network 2.2 /etc/rc.d/rc 5 2.2.2 /etc/rc.d/rc5.d /etc booting 2.2.2.1 /etc/rc.d/init.d (daemon) 2.2.2.1 /etc/rc.d/rc.local - /etc/inittab booting /sbin/init /etc/rc resource configuration /etc/fstab mount /etc/exports NFS network /etc/hosts /etc/resolv.conf /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-lo user administration /etc/passwd /etc/shadow
directories /bin UNIX, ls. /usr/bin/ /bin.. /sbin /usr/sbin root. /boot Booting kernel. /etc networking, NFS, mount. /var log. /var/spool. /lib /usr/lib. -l directory. /usr/lib/x11 X windows. /usr/include C #include /usr/src source /home home directory
3. Kernel rebuilding Kernel rebuilding - upgrade, kernel, device 0. cd /usr/src/linux 1. driver configuration - make config 2. makefile file dependency - make dep 3. object - make clean 4. kernel compile - make bzimage /usr/src/linux-2.2.5/arch/i386/boot/bzimage 5. module - make modules, make modules_install ** lib/modules/2.2.5-22 object 6. Go have a coffee 7. Install the new kernel via LILO & rebooting kernel /etc/lilo.conf lilo /etc/lilo.conf image=/usr/src/linux-2.2.5/arch/i386/boot/bzimage label=linux_new root=/dev/hda1 read-only Loadable driver(module) # insmod module(object ) # lsmod # rmmod module # insmod /boot/ftape.o # lsmod Module: #pages ftape 40
# rmmod ftape
4. Patch,. A1: Hello World Happy Hours A2: Hello World HAPPY HOURS # diff -c A1 A2 > A.patch -- patch # patch -p0 < A.patch -- patch patching file `A1' -- A1 A2 0. kernel source down (2.2.5) 0.1 ftp.kernel.org/pub/linux/kernel/v2.2/linux-2.2.5.tar.gz /usr/src 0.2 tar zvxf linux-2.2.5.tar.gz http://sources.redhat.com/gdb/papers/linux/ 1. http://sources.redhat.com/gdb/papers/linux/jimb.linux-2.2.5-sse-ptrace-2.patch root userhome directory 2. $ cd /usr/src/linux 3. $ patch -p0 < ~/jimb.linux-2.2.12-sse-ptrace-2.patch 4. kernel recompile
5. RPM (Redhat Package Manager) Redhat Linux. ** Slakware *.tar.gz. (tar zvxf *.tar.gz - ) rpm : mc-4.5.39-0.91kr.i386.rpm mc: 4.5.39: version 0.91kr: release i386: architectre rpm: rpm rpm (-q) $ rpm -qa : rpm ** rpm -qa grep mc : mc $ rpm -qf /usr/bin/mc : /usr/bin/mc $ rpm -qi mc : mc $ rpm -qs mc : mc $ rpm -ql mc : mc rpm (-e) (a) $ rpm -e gmc $ rpm -e mc (b) mc dependency(gmcmc ). $ rpm -e --nodeps mc (dependency ) $ rpm -e gmc rpm _(-i) (CD )
1. mount CD ROM $ mount -t iso9660 /dev/cdrom /mnt/cdrom ** down. 2. $ cd mnt/cdrom/redhat/rpms 3. rpm. (a) $ rpm -ivh mc-4.5.39-0.91kr.i386.rpm $ rpm -ivh gmc-4.5.39-0.91kr.i386.rpm -v -h (b) mc gmc dependency. $ rpm -ivh --nodeps gmc-4.5.39-0.91kr.i386.rpm $ rpm -ivh mc-4.5.39-0.91kr.i386.rpm RPM RPM. *.src.rpm. 1. rpm source $ rpm --rebuild bitchx-75p3-1kr.src.rpm /usr/src/redhat/rpms/i386/bitchx-75p3-1kr.rpm 2. rpm $ rpm -ivh /usr/src/redhat/rpms/i386/bitchx-75p3-1kr.rpm
6. NFS (Network File System) NFS server (211.114.217.210) 1. /etc/exports (UNIX: /etc/dfs/dfstab) /root 211.114.217.214(rw) : 2. $ /etc/rc.d/init.d/nfs stop $ /etc/rc.d/init.d/nfs start ( $ /etc/rc.d/init.d/nfs restart) ** Booting nfs start. NFS client(211.114.217.214) 1. $ mkdir /root2 (/root2.) 2. $ mount -t nfs -o bg -o soft 211.114.217.210:/root /root2 ** /etc/fstab (UNIX: /etc/vfstab) booting mount. 211.114.217.210:/root /root2 nfs rw,bg,soft
7. NIS (Network Information System) -ID, yellowpage. NIS Server (211.114.217.210) 1. ypserv (rpm ) ** $ tftp hpc > get /tftpboot/ypserv-1.3.7-3.i386.rpm 2. /etc/sysconfig/network NISDOMAIN="210.kangnung.ac.kr" ** NISDOMAIN booting $ domainname 210.kangnung.ac.kr". 3. /etc/yp.config domain 210.kangnung.ac.kr server 211.114.217.210 4. NIS database $ /usr/lib/yp/ypinit -m 5. Daemon restart (ypserv) $ /etc/rc.d/init.d/ypserv stop $ /etc/rc.d/init.d/ypserv start ( $ /etc/rc.d/init.d/ypserv restart) *** User-ID /etc/passwd, /etc/shadow 4 & 5
NIS Client 1. /etc/sysconfig/network NISDOMAIN="210.kangnung.ac.kr" ** NISDOMAIN booting $ domainname 210.kangnung.ac.kr". 2. /etc/yp.conf domain 210.kangnung.ac.kr server 211.114.217.210 ** 1 & 2 "$ /usr/sbin/setup" Authentication configuration. 3. Daemon restart /etc/rc.d/init.d/ypbind stop /etc/rc.d/init.d/ypbind start ( /etc/rc.d/init.d/ypbind restart)
8. Cluster (message passing), - NFS, NIS - MPI(Message Passing Interface) (root user) 1. NFS, NIS 2. MPI (1) source down - http://www-unix.mcs.anl.gov/mpi/mpich/ mpich.tar.gz /usr/local directorydown (2) untar - $ tar zvxf mpich.tar.gz (3) $ cd mpich (4) $./configure $ make
( user) 1. (1) home directory.hosts ) user0 4.rhosts jauser10.kangnung.ac.kr user0 jauser11.kangnung.ac.kr user0 jauser12.kangnung.ac.kr user0 jauser14.kangnung.ac.kr user0 ** rsh(remote Shell). (2) directorymachines machines jauser10.kangnung.ac.kr jauser11.kangnung.ac.kr jauser12.kangnung.ac.kr jauser14.kangnung.ac.kr 2. test (1) $ tftp hpc -> get /tftpboot/greetings.c (sample program down) (2) $ /usr/local/mpich/bin/mpicc -o greetings greetings.c -lm (3) $ /usr/local/mpich/bin/mpirun -np 4 -machinefile machines greetings
9. Daemon programming daemon process client service server. **tip** fork() child processparent process, child process. Sample Program #include<stdio.h> #include<stdlib.h> #include<signal.h> #include<string.h> #include<sys/param.h> #include<sys/types.h> #include<sys/socket.h> #include<sys/stat.h> #include<netinet/in.h> #include<arpa/inet.h> #include<sys/file.h> #include<sys/ioctl.h> int main(int argc, char *argv[]) { int serverfd, clientfd; /* the file descriptors */ struct sockaddr_in server_addr, client_addr; int addr_length=sizeof(client_addr); int port=6001; int childpid; /* used for a daemon */ int dataleft; char data[100]; int index; signal(sigttou,sig_ign); signal(sigttin,sig_ign); signal(sigtstp,sig_ign); childpid = fork(); if (childpid > 0) exit(0); #ifdef SITSTP setgrp(0, getpid()); if((index=open("/dev/tty", O_RDWR))>=0) { ioctl(index, TIOCNOTTY, (char *)NULL); close(index); } #else setpgrp(); signal(sighup, SIG_IGN); childpid=fork(); if(childpid > 0) exit(0); #endif serverfd = socket(af_inet, SOCK_STREAM,0); bzero((char *) &server_addr, sizeof(server_addr)); server_addr.sin_family=af_inet; server_addr.sin_addr.s_addr=htonl(inaddr_any); server_addr.sin_port=htons(port); bind(serverfd,(struct sockaddr *) &server_addr, sizeof(server_addr)); listen(serverfd, 2); sprintf(data,"hello from ykim at 211.114.210.210"); while (1) { clientfd = accept(serverfd, (struct sockaddr *) &client_addr, &addr_length); dataleft=sizeof(data); while(dataleft>0) { dataleft-=send(clientfd,data,dataleft,0); } close(clientfd); } }
client #include<stdio.h> #include<unistd.h> #include<strings.h> #include<stdlib.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> int main(int argc, char *argv[]) { int index=0; int dataleft; struct sockaddr_in server_addr; int serverfd; int port=6001; char data[100]; bzero((char *) &server_addr, sizeof(server_addr)); /* usage: client -a address */ while((index=getopt(argc,argv,"a:"))!=-1) server_addr.sin_addr.s_addr=inet_addr(optarg); server_addr.sin_family=af_inet; server_addr.sin_port=htons(port); serverfd=socket(af_inet,sock_stream,0); connect(serverfd, (struct sockaddr *) &server_addr, sizeof(server_addr)); dataleft=sizeof(data); while(dataleft>0) dataleft-=recv(serverfd,&data,dataleft,0); printf("%s\n",data); close(serverfd); exit(0); }