-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinux-100TipsandTricks.txt
2068 lines (1565 loc) · 100 KB
/
Linux-100TipsandTricks.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
100 Linux Tips and Tricks
by Patrick Lambert
100 Linux Tips and Tricks
Table of Contents
Introduction.........................................................................................................................................................1
Copyright.................................................................................................................................................1
About the author......................................................................................................................................1
Aknowledgements....................................................................................................................................1
Audience..................................................................................................................................................1
Organization.............................................................................................................................................2
Web resources..........................................................................................................................................2
Installation...........................................................................................................................................................4
What this chapter covers..........................................................................................................................4
Tip 1: Which distribution is good for you..................................................................................5
Tip 2: How to find a Linux CD-ROM at low cost......................................................................6
Tip 3: Multiple operating systems..............................................................................................7
Tip 4: Installing with no CD-ROM drive or modem..................................................................8
Tip 5: Swap and memory............................................................................................................9
Tip 6: More swap with a swap file...........................................................................................10
Tip 7: Kernel size and modules................................................................................................11
Tip 8: The boot prompt.............................................................................................................12
Tip 9: Wrong memory size found.............................................................................................13
Tip 10: Master boot record and LILO......................................................................................14
Tip 11: LILO can't find a kernel on a big drive.......................................................................15
Tip 12: X Window configuration options.................................................................................16
Tip 13: Allowing users to mount drives...................................................................................17
Tip 14: Allowing users to run root programs...........................................................................18
Tip 15: Linux and NT booting..................................................................................................19
Tip 16: Annoying boot messages..............................................................................................20
Tip 17: Programs on CD-ROM................................................................................................21
Tip 18: International console....................................................................................................22
Tip 19: Multiple kernels choices..............................................................................................23
Tip 20: Default file permissions...............................................................................................24
Tip 21: Default boot mode........................................................................................................25
Tip 22: More information from usenet.....................................................................................26
Tip 23: Bytes per inodes...........................................................................................................27
Tip 24: LILO and boot problems..............................................................................................28
Tip 25: Making CD-ROM images............................................................................................29
Tip 26: FTP access restrictions.................................................................................................30
Hardware...........................................................................................................................................................32
What this chapter covers........................................................................................................................32
Tip 1: Detecting 2 ethernet cards..............................................................................................33
Tip 2: Everything on sound cards.............................................................................................34
Tip 3: Non-PostScript printers..................................................................................................35
Tip 4: Use Windows special keys in Linux..............................................................................36
Tip 5: Added processors...........................................................................................................37
Tip 6: Detecting an ISA device.................................................................................................38
Tip 7: Find hardware information.............................................................................................39
Tip 8: Blinking leds on the keyboard........................................................................................40
i
100 Linux Tips and Tricks
Table of Contents
Tip 9: Reading a foreign file system.........................................................................................41
Tip 10: Can't mount root fs......................................................................................................42
Tip 11: Linux on a 286?............................................................................................................43
Tip 12: Linux without a hard drive...........................................................................................44
Tip 13: Shutdown and power off..............................................................................................45
Tip 14: LPD started but no device found..................................................................................46
Tip 15: Read files from FAT32 drives......................................................................................47
Tip 16: TV on Linux.................................................................................................................48
Tip 17: Device drivers..............................................................................................................49
Tip 18: Mouse problems...........................................................................................................50
Tip 19: International keyboards................................................................................................51
Software.............................................................................................................................................................53
What this chapter covers........................................................................................................................53
Tip 1: Background image in X Window...................................................................................54
Tip 2: Customize Netscape Communicator..............................................................................55
Tip 3: POP3 in Pine..................................................................................................................56
Tip 4: Multiple accounts in Pine...............................................................................................57
Tip 5: Running Java programs..................................................................................................58
Tip 6: Virtual hosts in Apache..................................................................................................59
Tip 7: Libc versus Glibc...........................................................................................................60
Tip 8: Aliases with Qmail.........................................................................................................61
Tip 9: Samba with Windows 98 or NT 4..................................................................................62
Tip 10: KDE drag and drop icons.............................................................................................63
Tip 11: Find files.......................................................................................................................64
Tip 12: asm or linux include files not found.............................................................................65
Tip 13: ICQ on Linux...............................................................................................................66
Tip 14: Reading foreign documents..........................................................................................67
Tip 15: Scanning with Linux....................................................................................................68
Tip 16: Real audio and video....................................................................................................69
Tip 17: Emulation.....................................................................................................................70
Tip 18: Shared library not found...............................................................................................71
Tip 19: Hard to erase files.........................................................................................................72
Tip 20: Files permissions..........................................................................................................73
Tip 21: Changing file permissions............................................................................................74
Tip 22: An international background........................................................................................75
Tip 23: Powerful file transfer system.......................................................................................76
Tip 24: Editing in text editors...................................................................................................77
Tip 25: Documentation and manual..........................................................................................78
Networking........................................................................................................................................................80
What this chapter covers........................................................................................................................80
Tip 1: Easy PPP dialup.............................................................................................................81
Tip 2: Internet for your LAN....................................................................................................82
Tip 3: Domains to search in......................................................................................................83
Tip 4: Display IP rather than hostname....................................................................................84
Tip 5: Is my modem a winmodem?..........................................................................................85
ii
100 Linux Tips and Tricks
Table of Contents
Tip 6: Sharing files from a Windows system...........................................................................86
Tip 7: Sorry but this host is not in my list................................................................................87
Tip 8: Access to various networks............................................................................................88
Tip 9: Accessing remote file systems.......................................................................................89
Tip 10: Secure Web server........................................................................................................90
Tip 11: Secure alternative to telnet...........................................................................................91
Tip 12: Speed problems on a PPP connection..........................................................................92
Tip 13: Names and name servers..............................................................................................93
Tip 14: Who owns this port......................................................................................................94
Tip 15: Network printers...........................................................................................................95
Development......................................................................................................................................................97
What this chapter covers........................................................................................................................97
Tip 1: Graphical messages to the world....................................................................................98
Tip 2: Code reuse......................................................................................................................99
Tip 3: Makefile don't equal C.................................................................................................100
Tip 4: Parsing the command line in BASH............................................................................101
Tip 5: Don't grep grep............................................................................................................102
Tip 6: Move a text into upper case letters...............................................................................103
Tip 7: Using PASCAL on Linux............................................................................................104
Tip 8: Segmentation fault.......................................................................................................105
Tip 9: Who is online?..............................................................................................................106
Tip 10: Graphical toolkits.......................................................................................................107
Tip 11: IDE and visual interfaces...........................................................................................108
Tip 12: Free software and copyleft.........................................................................................109
Tip 13: Talking to the terminal...............................................................................................110
Tip 14: Internet technologies..................................................................................................111
Tip 15: Library types..............................................................................................................112
iii
Introduction
Copyright
This book is copyright by Patrick Lambert. It is provided free of charge in the hope that it will be useful. You
may copy, distribute and print this book. You may not modify it without prior written consent from the
author.
The tips in this book are given AS-IS. This means that I shall not be responsible for any damage that may
occur from their use. You use them at your own risks.
Linux is a trademark of Linus Torvalds
RedHat is a trademark of RedHat Software Inc.
Windows and DOS are trademarks of Microsoft Corp.
Sound Blaster is a trademark of Creative Labs
PostScript is a trademark of Adobe
Other trademarks and copyrights may apply.
About the author
Patrick Lambert is currently a student in Computer Science at the University of Montreal in Quebec, Canada.
He is the author of various Web sites for the Linux community, and of various software packages including
GXedit
Although he does everything from systems administration to software programming, he spends most of his
time working on Web sites for the Linux community. You can contact Patrick at drow@darkelf.net
Aknowledgements
I would like to thank Tuomas Kuosmanen for the logo and the images on the Web site.
Audience
This book was written for anyone using Linux, from new users to experts who want to explore this wonderful
operating system. The tips and tricks in this book were discovered by myself over years of experience using
Linux, and learning about it. Some are very basic tips to make your computing life easier, others are
advanced tricks that can save you days of work.
I tried to cover all distributions of Linux in this book. I personaly use Slackware and RedHat on PC systems.
If you find any error in the book, feel free to contact me so a future second edition could correct them.
1
100 Linux Tips and Tricks
Organization
This book is divided into 5 chapters. Each chapter covers a specific topic:
•
Chapter 2 covers installation of Linux. These are tips and tricks useful when installing Linux
itself or any new program. Some tips will cover new means of installing Linux on non-typical
hardware, others will explain how to take Linux distributions from an FTP server and make
your own CD-ROM with them, or where to find Linux CD-ROMs for as little as $2.
•
Chapter 3 covers hardware related matters. You will learn tips there on how to get your
non-PostScript compatible printer to work, or how to get a sound card detected.
•
Chapter 4 covers software. You will find tips there about all kinds of Linux software,
including where to find and how to install the Java Development Kit port, and everything
about the Pine mail and news program.
•
Chapter 5 covers networking in all its forms. There you will see how to setup a PPP
connection quickly, without editing all of the configuration files yourself, as well as some nice
programs that were made to ease dialup procedures. You will also see tricks on how to make
your local LAN network without unexpected problems.
•
Chapter 6 is the last chapter but covers an important part of Linux: development. Here you will
find a lot of tips on how to write powerful scripts to make your system easier to handle, and a
full overview of what to do and what you don't want to do in C to avoid problems like
memory leaks, and how to allow easy scalability.
Web resources
This book has a sister Web site at http://tipoftheweek.darkelf.net where some of the tips from this book can
be found, and where you can submit your own tips to the site, to help the Linux community.
2
100 Linux Tips and Tricks
3
Installation
What this chapter covers
Installation is a very important part of any operating system. This is why I cover this topic first. The next
most important thing is installation of programs and software to get your system to do useful tasks. This
chapter covers both of these aspects.
4
100 Linux Tips and Tricks
Tip 1: Which distribution is good for you
They are all good. But that's not a real tip. What you should be looking for is which distribution you feel the
most comfortable with. RedHat has the reputation of being very easy to install. They provide special tools to
make the configuration easier. Debian also has some tools, but will usually require you to go on the command
line more often to configure the system. If you want to be on your own, and really learn how to edit
configuration files then Slackware is for you. The Web site http://www.linux.org lists all the available
distributions.
In the end, the best person to decide which distribution you like, is yourself.
5
100 Linux Tips and Tricks
Tip 2: How to find a Linux CD-ROM at low cost
The Linux market started from a few distributions available only from FTP servers, to full feature
commercial distributions available in stores and online including a printed manual and phone support.
Here are the main choices you have when looking for a Linux distribution:
•
You can download any Linux distribution from its FTP server. To take a few examples,
RedHat can be downloaded from ftp://ftp.redhat.com, Slackware from ftp://ftp.cdrom.com and
Debian from ftp://ftp.debian.org. That method is free, but requires you to have a fast Internet
connection. Downloading a full Linux distribution over a 56Kbps modem will take you quite a
few hours.
•
An other way is to buy a full distribution. RedHat, for example, can be bought online for about
$50. This will include a box, a CD-ROM, a boot diskette, a manual and support from RedHat.
•
The last way is to buy only the CD-ROM. There are a few places selling CD-ROMs of various
distributions for $2. One of them is http://www.cheapbytes.com. You will only get the
CD-ROM, but this is all you need to install Linux if you are comfortable with the fact that you
don't get a printed manual or free support. You can find the manual and other documentation
on the CD-ROM.
6
100 Linux Tips and Tricks
Tip 3: Multiple operating systems
A computer only needs one operating system to work. But what if you just want to try out a new system? Do
you need to forget about the old one and erase your hard drive? No, you can have as many operating systems
on your computer as you wish.
Linux requires 2 partitions to work. Partitions are sections of the hard drive. When you install Linux, it will
provide a program called fdisk or disk druid allowing you to create the needed partitions. The main problems
people have is that they don't have empty partitions to use for Linux, and they don't want to erase the current
Windows or DOS partition. The trick is to resize your current partition to create empty space. Then you will
be able to make the partitions needed by Linux to install properly.
Fdisk doesn't allow you to resize a partition. You will need to use another program to do the job, before using
fdisk to create the Linux partitions. A very popular commercial product to do this is Partition Magic from
http://www.powerquest.com.
Let's see step by step what is needed to resize an existing partition to allow the creation of a new one for
Linux:
•
Buy Partition Magic, or get any other tool that can safely resize partitions.
•
Make sure you have at least 150 megs free on your main partition, the required amount for
Linux.
•
Resize the partitions so you have at least 150 megs free, outside of any current partition.
•
Reboot and launch the Linux installation.
•
Run fdisk or any partitioning program that comes with the Linux distribution, and follow the
installation instructions to make the required Linux partitions.
7
100 Linux Tips and Tricks
Tip 4: Installing with no CD-ROM drive or modem
Most Linux distributions come on a CD-ROM. You can also download them from an FTP site, but that
requires an Internet connection. What if you have a system with no CD-ROM drive or Internet connection,
like an old 486 laptop? The trick here is to have another desktop system with a CD-ROM drive, and a
null-modem serial cable.
I will show you how to do it with Slackware. It is also possible with most other Linux distributions. Insert the
Linux CD-ROM in the drive on the desktop and copy the A (base) and N (networking) packages on diskettes.
You need at least those in order to use a serial cable to transfer the rest of the packages.
Now you need to enable NFS networking on the desktop, and allow the laptop to connect. You can give a
temporary IP address to the laptop, like 192.168.1.11 that you need to add to your /etc/exports file on your
desktop.
To link the two systems together, this is what you need to type on the laptop:
/usr/sbin/pppd -detach crtscts lock 192.168.1.11:192.168.1.10 /dev/ttyS1 115200
And this on the PC:
/usr/sbin/pppd -detach crtscts lock 192.168.1.10:192.168.1.11 /dev/ttyS1 115200
This is assuming the cable is linked to ttyS1 (COM2) on both systems.
With NFS, you can mount the CD-ROM drive remotely and tell the installation program to use a specific
path to install the remaining packages. Mount the CD-ROM with a command like this:
mount -tnfs 192.168.1.10:/cdrom /mnt
Then run the installation program:
setup
and enter the new path for the packages files.
8
100 Linux Tips and Tricks
Tip 5: Swap and memory
One important setting in any protected mode operating system like Linux is the swap space. In the
installation, you will need to create a swap partition. A common question is what size should the partition be?
The proper size depends on 2 things: The size of your hard drive and the size of your RAM memory. The less
RAM you have, the more swap you will need. Usually you will want to set your swap space size to be twice
the RAM size, with a maximum of 128 megs. This of course requires you to have a hard drive with enough
free space to create such a partition.
If you have 16 megs of RAM, making the swap space 32 megs or even 64 megs is very important. You will
need it. If you have 128 megs of RAM on the other hand, you won't need much swap because the system will
already have 128 megs to fill before using swap space. So a swap partition of 128 megs or even 32 megs
could be enough.
If you don't select enough swap, you may add more later.
9
100 Linux Tips and Tricks
Tip 6: More swap with a swap file
You installed a new Linux system, but forgot to set enough swap space for your needs. Do you need to
repartition and reinstall? No, the swap utilities on Linux allow you to make a real file and use it as swap
space.
The trick is to make a file and then tell the swapon program to use it. Here's how to create, for example, a 64
megs swap file on your root partition (of course make sure you have at least 64 megs free):
dd if=/dev/zero of=/swapfile bs=1024 count=65536
This will make a 64 megs (about 67 millions bytes) file on your hard drive. You now need to initialize it:
mkswap /swapfile 65536
sync
And you can then add it to your swap pool:
swapon /swapfile
With that you have 64 megs of swap added. Don't forget to add the swapon command to your startup files so
the command will be repeated at each reboot.
10
100 Linux Tips and Tricks
Tip 7: Kernel size and modules
To configure Linux to detect a new hardware part, especially on a new kernel, you may need to recompile the
kernel. If you add too many devices in the kernel configuration, you may get an error message telling you that
the kernel is too big. The trick is to enable modules.
The kernel itself must be a certain size because it needs to be loaded in a fixed memory size. This is one
reason why modules can be very handy. If you enable modules, you will need to make them:
make modules
and install them:
make modules_install
Then using the modprobe utility you can load selected modules on bootup. This way the kernel will be
smaller and will compile with no error.
11
100 Linux Tips and Tricks
Tip 8: The boot prompt
The Linux system uses a program called LILO to boot itself. This is the LInux LOader, and will load a kernel
and can pass various parameters. This is what the "boot:" prompt is for.
At the "boot:" prompt, you can enter a lot of parameters. You can send parameters to drivers like the ethernet
driver, telling it at which IRQ the ethernet card is located, or you can pass parameters to the kernel, like
memory size or what to do in a panic. Reading the LILO manual will tell you all of the nice things LILO can
be used for.
Note that for device drivers compiled as modules, you need to pass values when you load these drivers, and
not on the "boot:" prompt.
12
100 Linux Tips and Tricks
Tip 9: Wrong memory size found
The Linux kernel will detect various settings from your computer configuration. This includes the size of
memory you have. In some cases, it will find the wrong size. For example, it could find only 64 megs of
memory when in fact you have 128 megs.
The trick here is to specify the amount of RAM memory you have with the "mem=" parameter. Here is what
you would type when your system boots if you have 128 megs of memory:
LILO boot: linux mem=128M
This will tell LILO to load the linux kernel with 128 megs of memory.
13
100 Linux Tips and Tricks
Tip 10: Master boot record and LILO
What is the master boot record (MBR) and why does LILO erase the old boot loader? Every hard drive has a
top space called the MBR where the BIOS will try to load an operating system. Every system has its own
loader. DOS has DOS-MBR, Windows NT has the NTLDR and Linux has LILO.
When you install LILO, you can install it in the MBR or in a boot record for the Linux partition. If you want
to keep your current boot loader, you can select the Linux partition, and make sure it is the active partition in
fdisk. This way you will be able to boot to LILO, and then boot the old loader from the MBR.
If you plan on only using Linux on your system, you can tell LILO to boot right into Linux and not display a
"boot:" prompt, and you can install it in the MBR.
14
100 Linux Tips and Tricks
Tip 11: LILO can't find a kernel on a big drive
On some big hard drives, LILO can have problems loading your kernel. The problem is because the hard
drive has more then 1024 cylinders.
The trick is to make sure your kernel is in the first 1024 cylinders so LILO can find it. The way to do this is
to make a small /boot partition at the begining of the drive, and make sure the kernel is in the /boot directory.
You can set the partitions in fdisk, and select the right path for the kernel in /etc/lilo.conf so LILO knows
where it is. When you compile your kernel, simply move the new kernel in that directory so LILO can load it.
15
100 Linux Tips and Tricks
Tip 12: X Window configuration options
Each Linux distribution has its own X Window configuration program. XFree86 also has a text-based
configuration program which is complex to use. But what if both the distribution program and xf86config, the
text-based configuration for XFree86, do not seem to do what you need? XFree86 also comes with a
graphical configuration tool.
The name of the graphical program is XF86Setup. This will launch a graphical window and allow you to
configure the X Window Server. So if you don't like the console configuration programs, you can use this
one:
16
100 Linux Tips and Tricks
Tip 13: Allowing users to mount drives
By default, Linux will not allow users to mount drives. Only root can do it, and making the mount binary suid
root is not a good idea. With a special command in the /etc/fstab file, you can change that.
This is a typical line for the fd0 (A:) drive in /etc/fstab:
/dev/fd0
/mnt
auto
noauto,user 1
1
The keywords here are noauto and user. Noauto tells mount not the try to mount a diskette on boot, and user
allows any user to mount the drive into /mnt. The auto keyword is also interesting. It tells mount to try to find
out which file system is on the diskette. You could also use msdos or ext2.
17
100 Linux Tips and Tricks
Tip 14: Allowing users to run root programs
When a user starts a command, it runs with the permissions of that user. What if you want to allow them to
run some commands with root permissions? You can, and that's called suid.
You can set a command to be suid root with the chmod command. This will make it run as root even if a user
starts it. Here is how to set mybin suid root:
chmod +s mybin
Note that you must be very careful with this option. If the command has any security hole, or allows the user
to access other files or programs, the user could take over the root account and the whole system.
18
100 Linux Tips and Tricks
Tip 15: Linux and NT booting
Some people choose to have both Windows NT and Linux on the same system. Windows NT has its own
boot loader called NTLDR and Linux has LILO. Which should go on the MBR?
The safest way is to install Windows NT first, and give it the MBR. Then, when you install Linux, tell LILO
to install on the Linux partition. Also set the Linux partition as the active partition. When the system boots,
LILO will be loaded, and if you want to boot Windows NT, then LILO can load the MBR with NTLDR in it.
There is a mini HOWTO text covering this subject available at
http://metalab.unc.edu/pub/Linux/docs/HOWTO.
19
100 Linux Tips and Tricks
Tip 16: Annoying boot messages
When recompiling your kernel, you might end up seeing strange messages on bootup like:
modprobe: cannot find net-pf-5
modprobe: cannot find char-major-14
These are messages from the modules loader telling you that he can't find specific modules. This usualy
happens when you compile modules, but modprobe tries to load modules that were not compiled and it can't
find them. The way to remove those messages is to set the modules to off. In the file /etc/conf.modules you
may want to add:
alias net-pf-5 off
alias char-major-14 off
This will stop modprobe from trying to load them. Of course you could also try to resove the problem by
compiling the modules and make sure modprobe knows where they are.
20
100 Linux Tips and Tricks
Tip 17: Programs on CD-ROM
http://metalab.unc.edu, ftp://ftp.cdrom.com and more are sites with a lot of programs available freely for
Linux. But you may not want to download gigabytes of data over a slow Internet link.
Several places offer a bunch of free programs on CD-ROM. http://www.cheapbytes.com and
http://www.linuxmall.com are 2 places that can sell multiple CD-ROMs with all those programs for a very
low price:
21
100 Linux Tips and Tricks
Tip 18: International console
Most Linux distributions are configured to use a US english keyboard. If you need to write on a french or any
other kind of keyboard, you will want to change the locale so special keys like accents appear in the console.
The way to do this is to change the system locale with a program called loadkeys. For example, to enable a
canadian-french locale, you need to add this line in your startup files:
loadkeys cf
Here cf means the canadian-french keyboard. Other locales are us, fr and more.
22
100 Linux Tips and Tricks
Tip 19: Multiple kernels choices
When you compile a new kernel, you will often change your configuration. This means you may forget to
include an important driver, like the IDE driver, or otherwise make your system unbootable. The solution is
to always keep your old kernel.
When you compile your kernel, the compilation procedure will often copy your old kernel into vmlinuz.old.
If it does not, you can do it manually. What you should do is add an entry to /etc/lilo.conf allowing you to
boot your old kernel. You should view the lilo man page for the complete syntax. You could also add entries
for different kernels, for example if you want to have an older stable version of the kernel and the newest
development version on your system.
Note that some distributions name their kernel with the version they represent. For example, your current
kernel may be /boot/vmlinuz-2.0.36-0.7
23
100 Linux Tips and Tricks
Tip 20: Default file permissions
When you create a file, the system gives it default permissions. On most systems the permissions are 755
(read, write and execute for the owner, and read and execute for others).
This default is setup with the umask command. To use the command, you need to find the right octal number
to give it. The permissions in the umask are turned off from 666. This means that a umask of 022 will give
you the default of 755. To change your default permissions from 755 to 700, you would use this command:
umask 077
24
100 Linux Tips and Tricks
Tip 21: Default boot mode
When a Linux system boots, it loads the kernel, all its drivers, and the networking servers, then the system
will display a text login prompt. There, users can enter their user names and their passwords. But it doesn't
have to boot this way.
There are 3 modes defined in most Linux distributions that can be used for booting. They are defined in
/etc/inittab and have specific numbers. The first mode, also called runlevel 1, is single user mode. That mode
will only boot the system for 1 user, with no networking. Runlevel 3 is the default mode. It will load the
networking servers and display a text login prompt. Runlevel 5 is the graphical mode. If you have X Window
installed and configured, you can use it to display a graphical login prompt.
The way to change this is to edit /etc/inittab and change the initdefault line:
id:3:initdefault:
Changing a 3 to a 5 will make the system display a xdm graphical screen on bootup.
25
100 Linux Tips and Tricks
Tip 22: More information from usenet
There are newsgroups about everything. Newsgroups on the latest TV show, on gardening, and more. There
also are newsgroups on Linux. In fact, the best help can be obtained from newsgroups. But which ones?
Here is a list of a few newsgroups dedicated to Linux, and what they are used for:
•
comp.os.linux.advocacy: This newsgroup is used for advocacy. People stating their opinions
about Linux or Linux applications, and about Linux competitors. Some post facts, some will
flame other people.
•
comp.os.linux.setup: This is a general purpose setup help group. Users will post questions and
get answers there.
•
linux.*: There now is a linux section on usenet. Currently there are more than 150 groups in
linux.* and they are all about Linux!
Make sure you read the FAQ and rules of every newsgroup you want to post to.
26
100 Linux Tips and Tricks
Tip 23: Bytes per inodes
When you format a partition using Linux's primary file system, ext2, you have the choice of how many bytes
per inode you want. From the man page:
-i bytes-per-inode
Specify the bytes/inode ratio. mke2fs creates an
inode for every bytes-per-inode bytes of space on
the disk.
This value defaults to 4096 bytes.
bytes-per-inode must be at least 1024.
This means that by using a smaller size, you will save disk space but may slow down the system. It is a
space/speed trade off.
This is similar to one of FAT16/FAT32' major differences.
27
100 Linux Tips and Tricks
Tip 24: LILO and boot problems
When a computer starts, the number of beeps the BIOS outputs tells you the state of the computer. On some
computers, one beep means all is ok, but 2 beeps mean there is an error. LILO uses the same kind of codes.
The number of letters you see from the word LILO on the screen says what is wrong. The whole word means
everything is fine, only LI means only the first part of LILO could be loaded. A full description of this is
available from the Bootdisk HOWTO.
When LILO can't load, it's a major problem. This often means that the boot code was corrupted. The only
way to boot is from a floppy disk. In RedHat, you can use the rescue disk, in Slackware, you can use the boot
disk with the "mount" image.
When LILO is fine, it's often easier to figure a boot problem. If the kernel panics when it tries to boot, it is
usualy due to a configuration error. You can tell LILO to mount another kernel you may have, like a "safe" or
"old" image you kept for these cases. If the problem is in initialization scripts, you can tell LILO to boot
directly into a shell with the following boot command line:
LILO boot: linux init=/bin/sh
Where "linux" would be your kernel image.
28
100 Linux Tips and Tricks
Tip 25: Making CD-ROM images
With other operating systems, such as Microsoft Windows or IBM OS/2, you are not allowed in the license to
make your own CD-ROM with the OS on it and then distribute it.
Linux, being Open Source and free, can be copied. You can download a distribution or buy it from an online
store and burn your own copy, and then install it on many computers, or give it to your friends. Usually, you
will find instructions on how to do that on the FTP server for your favorite distribution. You will need the
main directory on the CD-ROM. The sources are not needed since they are available from the FTP site.
Some distributions also come with ISO images of their CD-ROM. This is a single file that can be put onto a
CD-ROM, and will create a full file system with files on it.
One thing you have to be careful is not to copy commercial programs. The basic CD-ROM where the Linux
distribution is located is composed of free software. But some distributions may come with other commercial
programs, and you should read the license first.
29
100 Linux Tips and Tricks
Tip 26: FTP access restrictions
When you first install Linux, it comes with a lot of Internet services running, including mail, telnet, finger
and FTP. You really should disable all those that you don't need from /etc/inetd.conf and your startup scripts.
FTP may be very useful, but must be configured correctly. It can allow people to log into their accounts, it
can allow anonymous users to login to a public software directory, and it can display nice messages to them.
The files that you will probably want to modify are /etc/ftpusers and /etc/ftpaccess.
The file /etc/ftpusers is very simple. It lists the people that will not be allowed to use FTP to your system. The
root account, and other system accounts should be in that file.
The file /etc/ftpaccess is a bit more complex and controls the behaviour of the FTP server. It tells it what to
use as README file to display on a directory listing, what kind of logs to create and what messages to
display.
Note that if you create an anonymous FTP area, you will need to read the FTP man page and do exactly what
it tells you to avoid possible security risks.
30
100 Linux Tips and Tricks
31
Hardware
What this chapter covers
Hardware support has once been a very big problem with Linux. Generic hardware always was well
supported, but most of the hardware today is unfortunately non-generic. 100% Sound Blaster compatible
cards often are not detected by the Sound Blaster driver, and non-PostScript printers don't accept PostScript
input unless a program previously converted it. These are the kind of problems we solve here.
32
100 Linux Tips and Tricks
Tip 1: Detecting 2 ethernet cards
To configure an ethernet card in Linux, you need to enable it in the kernel. Then the kernel will detect your
ethernet card if it is at a common IO port. But it will stop there, and will never check if you have 2 ethernet
cards.
The trick is to tell the ethernet driver that there are 2 cards in the system. The following line will tell the
kernel that there is an ethernet card at IRQ 10 and IO 0x300, and another one at IRQ 9 and IO 0x340:
ether=10,0x300,eth0 ether=9,0x340,eth1
You can add that line on bootup at the "boot:" prompt, or in the /etc/lilo.conf file. Don't forget to run:
lilo
That will reload the lilo.conf file and enable changes.
33
100 Linux Tips and Tricks
Tip 2: Everything on sound cards
A sound card can be easy or hard to detect. It depends on who made it. Many Sound Blaster Compatible
cards in fact are not compatible with the Linux Sound Blaster driver. Other cards will be compatible with a
driver you would never have thought of.
There are multiple drivers for Linux. Currently the kernel comes with its own set of sound drivers, plus the
OSS/Free drivers. These will support most generic cards. In the installation program, or when compiling your
kernel, you can pick the sound card that matches yours, or the one that matches the chipset on your sound
card (for example, the Sound Blaster PCI64 card uses the AudioPCI chipset).
If your sound card is not supported by the kernel, you will need to get another driver. 2 popular ones are
ALSA available from http://alsa.jcu.cz and OSS/Linux available from http://www.opensound.com
OSS/Linux is a commercial product that supports a lot of cards not available in other drivers because of card
specification restrictions. You will need to see the list of supported cards in each driver and pick the driver
you need.
34
100 Linux Tips and Tricks
Tip 3: Non-PostScript printers
Unfortunately, most printers are non-PostScript compatible. This means that your LPR program won't like it.
You will probably notice that when you first use 'lpr' to print, the output looks weird on your printer. This is
because these models do not support PostScript. You will need a converting program for it.
Note that newer versions of RedHat already have those programs or similar filters so it may not apply to all
Linux systems.
First, you need to go read the Printing HOWTO to find out how to use lpr and related printing programs.
Then, you'll need to get 2 programs from http://metalab.unc.edu:
•
bjf
•
aps
These are the filters to convert text and PostScript to your printer's format.
First, install bjf which will be used to print text. Installation is very simple. type:
make
cp bjf /bin/bjf
Then, make a simple shell script to print text files and call it print.sh:
#!/bin/sh
/bin/bjf <$1> /dev/lp0
Where /dev/lp0 is your printer.
Now, install aps by running the SETUP script in its package. It's really easy to setup, but you do need to have
the GhostScript program installed prior to installation. You are now ready to print PostScript files from, for
example, Netscape or XV.
35
100 Linux Tips and Tricks
Tip 4: Use Windows special keys in Linux
Why are all the new keyboards sold with Win95 keys on them? How about making them do real keyboard
functions while in X Window? Here is how.
First you need to find out which key mapping you are using. Usually it will be US, it might also be en_US, ca
or else. Locate the file, usually in /usr/X11/lib/X11/xkb and edit it with your favorite editor. For me the file is
called /usr/X11/lib/X11/xkb/symbols/ca.
The file lists all the key codes and what they do. The key codes for the Win95 special keys are LWIN, RWIN
and MENU. All you need to do is add them to the list, with the functions for them. I decided to map the left
WIN key to "@" and the right WIN key and MENU keys to "{" and "}". Here are the lines I added:
key <RWIN> { [ braceleft ] };
key <LWIN> { [ at ] };
key <MENU> { [ braceright ] };
By browsing the file you can find all the other symbols and what they do. You can also add multiple
functions to a key, by using ALT and SHIFT.
The changes will take effect when you restart X Window. With the XKB extension (you do need to have it
enabled in /etc/XF86Config btw) it's easy to change the mapping of any key.
36
100 Linux Tips and Tricks
Tip 5: Added processors
Dual processors are becoming more and more popular in computers. Of course, you won't be able to see
much performance increase in Linux unless you tell Linux about the second CPU. Here is how to do it.
Go in the kernel, and enable SMP. SMP means Symetric Multi-Processing and tells the kernel that more than
one processor can be used.
After a reboot, Linux should tell you that it has detected 2 processors and what their status are.
37
100 Linux Tips and Tricks
Tip 6: Detecting an ISA device
ISA devices like modems should be detected automatically by the kernel. One case where they would not be
detected is if the device is Plug and Play. The kernel won't be able to detect ISA PnP devices unless they
have been prepared by a program called isapnptools.
The trick is to use this program in initiation scripts. It will detect the ISA PnP devices and make them
available to kernel modules and applications.
For example if you want to access an ISA PnP sound card, you will need to compile sound as a module in the
kernel, and use isapnptools before loading the module.
38
100 Linux Tips and Tricks
Tip 7: Find hardware information
When the Linux system boots, it will try to detect the hardware installed in the computer. It will then make a
fake file system called procfs and will store important information about your system in it.
You can get information about your system simply by browsing the directory /proc. The files in there will
contain information such as the processor you have, the amount of memory and the file systems the kernel
currently supports.
A usefull application exists to browse the /proc file system. It is called Xproc and is available from
http://devplanet.fastethernet.net/files.html:
39
100 Linux Tips and Tricks
Tip 8: Blinking leds on the keyboard
Keyboard leds are pretty boring. Usualy you know if the num lock is on or if you are writing in upper case
letters. Could we make them do something more useful? Of course.
The keyboard leds can be controlled by a device driver called the misc driver. That driver can control all
kinds of misc things. You could write your own driver to make them blink or light up at any system event.
A program called tleds is available from http://www.hut.fi/~jlohikos/tleds.html. That program will have them
blink based on network usage. One will blink when packets go in, and the other when packets go out.
40
100 Linux Tips and Tricks
Tip 9: Reading a foreign file system
File systems are defined in the kernel. The kernel supports many file systems, but they need to be compiled
in, or compiled as a module. When you compile a file system in the kernel, all you need to do is use mount
with the -t option and the right file system type.
If you have compiled a driver for a file system as a module, then you need to load the module first.
Here are a few of the available file systems:
•
msdos: This is the FAT file system used by DOS.
•
vfat: This is the FAT32 file system used by Windows 95 and Windows 98.
•
ext2: This is the default Linux file system.
•
iso9660: This is the default CD-ROM format.
41
100 Linux Tips and Tricks
Tip 10: Can't mount root fs
When you boot a system, this is an error that will halt the system. This error means that the kernel can't
mount the root file system, so it can't get all of its configuration files.
There are a few cases where this happens:
•
No IDE support in the kernel. If your main hard drive is an IDE, and you have recompiled
without including "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support" or some other
basic IDE device drivers.
•
File system not supported. Usually the root file system should be of type ext2. You need to
make sure that ext2 is compiled in the kernel, and not as a module because you can't load
modules without first mounting the root file system.
•
The drive is not ready. If you have removed the drive, the hard disk died or the BIOS didn't
detect the device for some reason, then the kernel won't be able to mount it.
42
100 Linux Tips and Tricks
Tip 11: Linux on a 286?
Linux is a multi-user, multitasking operating system which requires a 386 processor or more to run. This is
because the lower PC processors don't have what is needed for the Linux kernel.
Linux being open source, is being ported to many architectures. And one group decided to modify the kernel
so it would run on a 286 processor. The project page is http://www.uk.linux.org/ELKS-Home/index.html.
43
100 Linux Tips and Tricks
Tip 12: Linux without a hard drive
Modern Linux distributions require around 100 megs to 200 megs of hard disk space to install. But is it
possible to run Linux on a system without a hard drive? Yes it is.
The Linux Router Project is a full-featured Linux distribution that fits on one diskette. It was made for
routers, and use modules to add the software packages you need, including DNS servers, Web servers, email
and routing. You can find more information on the Linux Router Project at http://www.linuxrouter.org.
44
100 Linux Tips and Tricks
Tip 13: Shutdown and power off
Linux, like most other operating systems, must be shutdown in a specified manner. You can't turn the power
off on a computer running Linux, or you may lose some data.
Here are the steps that need to be done when you want to shutdown:
•
The operating system needs to stop all the running processes and logout the users.
•
Various servers need to be shutdown in a proper way.
•
All the mounted file systems need to be unmounted safely and unwritten data need to be stored
on the disk.
The system can then be turned off safely.
To accomplish all these tasks, the shutdown command exists. That command has a lot of options, and you
should explore them before trying anything at random. Another way to shutdown a Linux system is to set the
runlevel to 0, the default shutdown level, with the init program.
45
100 Linux Tips and Tricks
Tip 14: LPD started but no device found
The printer daemon is called LPD. It will be started at boot time and assume that a printer is connected to the
printer port. But a problem may occur when the daemon is started and no device is found.
The most common cause for this problem is a configuration problem in the kernel. Make sure that parallel
port, PC-style parallel port, and printer support is enabled in the configuration, and that modules are loaded.
46
100 Linux Tips and Tricks
Tip 15: Read files from FAT32 drives
The Linux utility mount can read any file system that the kernel supports. Since version 2.0.34, the kernel
supports FAT32, which is the main file system used by Windows 98.
To read the FAT32 file system you need to specify the -tvfat option to mount. Here is an example:
mount -tvfat /dev/hdb1 /mnt
47
100 Linux Tips and Tricks
Tip 16: TV on Linux
A number of cards exist allowing you to watch and record TV on your PC. Most come with software for
Windows only, like so many things, but it is possible to do the same thing on Linux.
Linux comes with several drivers which make up the Video4Linux drivers. Several cards are supported by
these drivers, and a list of them is available at http://roadrunner.swansea.linux.org.uk/v4l.shtml. This is the
driver side. You also need software to use the devices.
Several programs are available to watch TV, capture images and even Web applications. A list of some of the
programs is available at http://www.thp.uni-koeln.de/~rjkm/linux/bttv.html including datasheets.
48
100 Linux Tips and Tricks
Tip 17: Device drivers
Hardware devices are not of much use without device drivers. Fortunately, the Linux kernel, like every other
operating system, comes with a lot of them.
When you configure a kernel, the menu from which you must choose which devices you have in your
computer is actually a list of device drivers available to you. Here is how to configure your kernel:
cd /usr/src/linux
make menuconfig
Linux, still not being as popular as some other operating systems, can't support all of the existing hardware.
If you have a device that is not in the list, then you will need to search for it on the Web. Some drivers may
exist for Linux and not be in the default kernel. But if a device is not currently supported by any driver for
Linux, then you will have to wait for someone to make one, or make one yourself.
If you want to write your own driver, the best place to start is at The Kernel Hacker's Guide, available at
http://khg.redhat.com/HyperNews/get/khg.html