wiley publishing suse linux 9 bible phần 7 pps

88 334 0
wiley publishing suse linux 9 bible phần 7 pps

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

315 Chapter 13 ✦ Working with Files According to the permissions that you see in the listing, you should certainly be able to delete the file, but attempting to do so gives “Operation not permitted.” Also, if you try to edit the file, you’ll find that you can’t save to it. But the situation is even stranger than that: user@bible:~> su Password: root@bible: /home/user/ # rm afile rm: remove write-protected regular file `afile’? y rm: cannot remove `afile’: Operation not permitted This looks very odd indeed: The owner can’t delete the file although he appears to have the right to do so, but even root can’t delete the file. The reason is that the file has the immutable bit set: root@bible: /home/user/ # lsattr afile i afile The file has the special file attribute “immutable” set, which effectively means that no one has the right to change the file. To set a file to be immutable, do the following: root@bible: /home/user/ # chattr +i afile This adds (+) the immutable attribute (i). To remove the attribute, do the following: root@bible: /home/user/ # chattr -i afile root@bible: /home/user/ # lsattr afile afile There are easily imagined practical situations in which you might want to use this functional- ity to prevent accidental deletion. For example, you might want to set this attribute on certain configuration files so as to force yourself to think very hard before modifying them. Use of the immutable attribute on particular system files is also often recommended as a way of adding an additional level of security to the system. For further details, see the chattr and lsattr man pages. File ACLs Relatively recently, Linux has gained the concept of file and directory ACLs (access control lists). In contrast to the file attributes discussed previously, which control the behavior of the file itself (making it undeletable or immutable, for example), file ACLs are all about who can access the file and in what way. These ACLs mean that the sharing of files and directories with specifically named users can now be achieved, where previously a complex design of users and multiple groups was the only way to bring this about. The particular application where this is of importance is Samba, and it means that the owner of a file who is accessing that file by Samba from a Windows client can set sharing on that file in the same way as if the file were on a Windows machine. Chapter 18 contains more on Samba. Cross- Reference 21_577395 ch13.qxd 12/15/04 12:14 AM Page 315 316 Part III ✦ Using the Command Line in SUSE Linux To use this ACL functionality, it is necessary that the partition on which the filesystem resides be mounted with the acl option. ACL functionality is now available regardless of which of the common filesystems you use ( ext2, ext3, or reiserfs).To set ACLs on the command line, you use the command setfacl. getfacl reads the ACLs of a file. If ACLs have been set, when you do an ls -l command, you will see this: tom@bible:~> ls -l afile -rw-r r + 1 tom users 81 2004-06-23 15:59 afile Note the extra plus (+) symbol after the permissions string. This shows that ACLs have been set on this file, but to actually find out what they are, you will need the getfacl command described later in this section. If tom wants to modify the ACL to allow tanya to write to the file, he does this: tom@bible:~> setfacl -m u:tanya:w bfile Here tom is modifying (-m) the ACL to allow the user (u) tanya to write (w) to the file. You can then get the ACL for the file like this: tom@bible:~> getfacl bfile # file: bfile # owner: tom # group: users user::rw- user:tanya:-w- group::r mask::rw- other::r So the change was made. For each user, you see the permissions shown in the usual rwx (read, write, execute) format. The user tanya now has write permission. To remove the ACL that was just set: tom@bible:~> setfacl -x u:tanya bfile Here the -x means remove, so tom is removing the ACL that the user (u) tanya had on the file. tom@bible:~> getfacl bfile # file: bfile # owner: tom # group: users user::rw- group::r mask::r other::r Here tanya’s special write permission has gone away. Finally, familiarity with the techniques and concepts introduced in this chapter, as well as the content of Chapter 2, is necessary for anyone who wants to be able to work comfortably with a Linux system and their files. Some of the commands have a bewildering variety of options, but practicing with the examples given here and building on them is the best way to increase your facility and gain understanding. ✦✦✦ 21_577395 ch13.qxd 12/15/04 12:14 AM Page 316 Working with the System I n this chapter we look at some of the more useful tools for working with your SUSE Linux system. First, we examine some of the tools that are available to you to deal with emergencies; if your system won’t boot or is otherwise seriously damaged, SUSE’s Rescue System and YaST System Repair running from the installation media can be very useful. We also look at different ways to deal with partitions and disk images and how to create CDs. We touch on the use of Webmin as an alternative to YaST for administrative tasks, and we give a (nec- essarily brief) introduction to shell scripting and scripting languages. What all these sections have in common is that they all concern tools that give you more power over your system, and working with these tools will add to your understanding. You should not be afraid to experiment, even with — indeed partic- ularly with — the more scary and destructive examples given in this chapter. If you can, by all means set up a “sacrificial” system and play with the rescue and repair systems, with the partitioning tools, and so on. The knowledge that you gain may well be useful when (not “if”) things eventually go wrong. System Rescue and Repair You may find occasionally that you have problems you cannot solve from within the system itself. Most commonly, there may be some- thing that is preventing the system from booting at all. This could be a misconfigured boot manager or a root partition that needs to have a filesystem check run on it manually. There is also the possibility that you have forgotten the root password and you need to remove it. Booting from the hard disk with special boot parameters Sometimes it is enough to boot the system from hard disk, but into runlevel 1 (by simply typing the digit 1 as a boot parameter (in the initial boot screen). Runlevel 1 is “single user” mode, with no net- working and without starting most services. So if there is a problem that is causing the boot process to fail at a later stage, you may be able to solve the problem by booting into runlevel 1 and making the Tip 14 14 CHAPTER ✦✦✦✦ In This Chapter Using the rescue and repair systems to recover from problems Working with partitions and disk images Using Webmin Using shell aliases Automating with shell scripts and scripting languages ✦✦✦✦ 22_577395 ch14.qxd 12/15/04 12:20 AM Page 317 318 Part III ✦ Using the Command Line in SUSE Linux necessary changes. You can run YaST or edit configuration files in this state, and then reboot or bring the system up to runlevel 3 or 5 with one of the commands init 3 or init 5. Chapter 4 has more information on booting into specific runlevels. If you have lost the root password, you can boot with the following parameter: init=/bin/bash rw This starts the system but bypasses the normal init system, instead taking you straight to a shell, without the need to log in, and mounting the root partition read-write. You can then, if necessary, remove the root password by editing the file /etc/shadow using vi and removing the encrypted password. You need to change it from looking something like the first line below to something like the second. root:cJLgWo7eN1gqk:12629:0:10000:::: root::12629:0:10000:::: Booting into the Rescue System The SUSE installation media offer a special option when you boot from them: One of the menu items is Rescue System. If you boot from the first CD or DVD and choose this option, a Linux system that runs in memory loads and does not mount any hard disk partitions. You can log into it as root without a password. You can then mount any of the partitions on the hard disk to /mnt and make changes before rebooting. For example, if your root partition is /dev/hda1, you could do: Rescue:~ # mount /dev/hda1 /mnt followed by, for example: Rescue:~ # vi /mnt/etc/fstab if you needed to correct a problem with the file /etc/fstab. Booting into YaST System Repair mode SUSE also provides a System Repair mode with YaST. If you boot from the installation media and choose the option Installation, but add the boot parameter repair=1, you enter a system similar to the Rescue System (running in memory and with no hard disk partitions mounted), but with YaST running in graphical mode. In this system you can use parts of YaST’s standard functionality to repair a broken system. The main screen offers three options: Automatic Repair, Customized Repair, and Expert Tools. If you choose Automatic Repair, the YaST system check repair runs through a series of tests and shows a commentary on the screen. Among the tests it runs are filesystem checks, verification of the package database, a check on the boot loader configuration, and a check of the initrd (the initial ramdisk used at boot time). If problems are found, it offers to attempt a repair. Cross- Reference 22_577395 ch14.qxd 12/15/04 12:20 AM Page 318 319 Chapter 14 ✦ Working with the System The Customized Repair screen If you choose Customized Repair (see Figure 14-1), you can select or deselect the particular tests that you want to be run. If you have a good idea of what might be at fault, this reduces the time the tests and repairs need to run. The options are: ✦ Check Partition Tables ✦ Check Swap Areas ✦ Check File Systems ✦ Check fstab Entries ✦ Check Package Database ✦ Check Minimal Package Selection ✦ Verify Base Packages ✦ Check Boot Loader Configuration Figure 14-1: The YaST System Repair mode Customized Repair screen 22_577395 ch14.qxd 12/15/04 12:20 AM Page 319 320 Part III ✦ Using the Command Line in SUSE Linux The most useful of these are those concerned with filesystems and boot loaders. ✦ Although journaling filesystems mean that filesystem corruption is unlikely, if it occurs and prevents the system from booting normally, this filesystem option is useful because it will run a filesystem check for you with the correct options. ✦ If you have a dual-boot system, and you have reinstalled Windows, the Windows installer may overwrite the Master Boot Record and prevent Linux from booting at all. The boot loader check can rewrite the boot loader (usually grub) so that both systems can be booted correctly. If the package database does not correspond to the packages that are actually on the system, or if packages have become corrupt, the package checking tools can correct the problem. The Expert Tools screen The Expert Tools screen (see Figure 14-2) offers some additional tools: ✦ Boot Loader Install ✦ Partitioning Tool ✦ Repair File System ✦ Recover Lost Partitions ✦ Save System Settings to Floppy Disk ✦ Verify Installed Software Figure 14-2: The YaST System Repair mode Expert Tools screen 22_577395 ch14.qxd 12/15/04 12:20 AM Page 320 321 Chapter 14 ✦ Working with the System The boot loader tool allows you to create a new boot loader configuration from scratch and install it to the Master Boot Record. The partitioning tool is YaST’s standard partitioning mod- ule (clearly a dangerous tool; see the next section of this chapter). The Repair File System and Verify Installed Software options have the same function as the equivalent items discussed in the previous section. Recover Lost Partitions scans the disk and attempts to restore any partitions that might have been deleted from the partition table (possibly by reckless use of the partitioning tool or fdisk). Finally, Save System Settings to Floppy Disk backs up important system files and the Master Boot Record to a floppy disk. Working with Partitions Each hard disk that you use in a Linux system will have a number of partitions on it (except in the rather rare cases when we write to raw disk devices). To find out what disks and parti- tions the system can see, type: root@bible:/tmp # fdisk -l Disk /dev/hda: 40.0 GB, 40007761920 bytes 16 heads, 63 sectors/track, 77520 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 12484 6291904+ 83 Linux /dev/hda2 12485 16646 2097648 82 Linux swap /dev/hda3 16647 47854 15728832 83 Linux /dev/hda4 47855 77520 14951664 83 Linux This shows you the partitions the system can see, whether or not they are mounted. It provides in more digestible form the information that can also be seen in the virtual file /proc/partitions. root@bible:/tmp # cat /proc/partitions major minor #blocks name 3 0 39070080 hda 3 1 6291904 hda1 3 2 2097648 hda2 3 3 15728832 hda3 3 4 14951664 hda4 The fdisk -l command together with the outputs of mount and df -h are useful for under- standing what you’ve got, how much of it, and where: user@bible:~> mount /dev/hda1 on / type reiserfs (rw,acl,user_xattr) proc on /proc type proc (rw) tmpfs on /dev/shm type tmpfs (rw) devpts on /dev/pts type devpts (rw,mode=0620,gid=5) /dev/hda3 on /home type ext3 (rw) /dev/hda4 on /space type ext3 (rw) usbfs on /proc/bus/usb type usbfs (rw) 22_577395 ch14.qxd 12/15/04 12:20 AM Page 321 322 Part III ✦ Using the Command Line in SUSE Linux user@bible:~> df -h Filesystem Size Used Avail Use% Mounted on /dev/hda1 6.1G 5.5G 599M 91% / tmpfs 253M 8.0K 253M 1% /dev/shm /dev/hda3 15G 12G 2.8G 81% /home /dev/hda4 15G 12G 1.5G 89% /space Before doing anything with your partitions, you should at least run the three commands we just mentioned. Together they should reassure you that you know what partitions exist and what they contain and make it less likely that you will accidentally do something destructive. When you work with partitions, most of your time is spent when you install the system, and at that time you will be using YaST’s partitioning capabilities. At other times, if you simply want to create partitions on a new disk, you are likely to do this using fdisk, but you can use YaST’s partitioning module at any time from the YaST menu or by typing (as root): yast2 disk You will first see a warning (see Figure 14-3). Figure 14-3: YaST’s partitioning warning Take that warning seriously, whatever tool you are using to do partitioning: One false move and you can destroy your system. The main YaST partitioning scheme looks like what is shown in Figure 14-4. You may notice that YaST reports the starting and ending cylinders differently from fdisk. That is because fdisk starts counting from 0, whereas YaST counts from 1. YaST uses the functionality of parted rather than fdisk to do its job: This means that as well as creating and destroying partitions, it is also capable of resizing them. It can also call ntfsresize to resize NTFS partitions. Partitions and the principles of partitioning are discussed in further detail in Chapters 1 and 3. Cross- Reference Note 22_577395 ch14.qxd 12/15/04 12:20 AM Page 322 323 Chapter 14 ✦ Working with the System Figure 14-4: YaST’s partitioning module Partitioning examples On the x86 architecture, there are limitations on the number of partitions a disk can contain: There can be at most four primary partitions, one of which can be an extended partition. The extended partition can contain multiple logical partitions (up to a maximum of 60 on an IDE disk or 12 on a SCSI disk). When working with partitioning tools, you should always ensure that any partitions you are going to change are not mounted before you start. You should also be absolutely sure that you know what partitions exist on the system and what they contain (as we stressed before): Keep a printed copy of the output of at least the commands fdisk -l, mount, and df -h on hand during the process. fdisk To use fdisk to partition a disk, type the command fdisk followed by the device name of the disk concerned. Suppose that you had just added a new disk as the first disk on the second IDE controller: root@bible : ~ # fdisk /dev/hdc Command (m for help): Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition 22_577395 ch14.qxd 12/15/04 12:20 AM Page 323 324 Part III ✦ Using the Command Line in SUSE Linux l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition’s system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Type m to see the menu as shown, and then n to add a new partition. At this point, p will cre- ate a primary partition; e will create an extended partition: Command (m for help): n Command action e extended p primary partition (1-4) If you choose p, you will see something like the following: p Partition number (1-4): 1 First cylinder (2-77520, default 2): Using default value 2 Last cylinder or +size or +sizeM or +sizeK (2-1000, default 1000): +2000M You can specify the size of the partition in terms of disk cylinders, or (more usefully) by typ- ing a size in megabytes (here the +2000M). By default fdisk creates partitions of type Linux (with the hex code 83). If you want to change the partition type, you need to do t and then the relevant code (which is typically 83 for a data partition and 82 for swap, but you can cre- ate any number of “foreign” partition types). When you think the correct partitions have been created, you can type p to print the parti- tion table and then w to write it to disk. Using YaST YaST’s partitioning module has the ability to create and delete partitions. It can also resize (non-destructively) certain types of partitions (including Windows partitions, which is a fea- ture in great demand for dual-boot installations on previously Windows-only machines). YaST uses parted to do this but provides a user-friendly interface. Although the procedure is very reliable, we recommend that you back up all the data on the partition you want to resize before doing this. If, for example, the power suddenly failed during the resizing process, it’s possible that the result would be a completely corrupt partition. YaST’s partitioning tool can be accessed from the main menu, or by typing (as root) the com- mand yast2 disk (for a graphical interface) or yast disk for a text interface. You cannot make changes to any partition that is mounted. Note 22_577395 ch14.qxd 12/15/04 12:20 AM Page 324 [...]... with the version of Webmin that ships with SUSE Professional 9. 1; it fails to install correctly without a little help You need to do the following: 1 Back up the file /etc /SuSE- release: root @bible: /etc # cp SuSE- release SuSE- release.real 2 Then edit /etc /SuSE- release so that it refers to 9. 0 instead of 9. 1 3 Now install Webmin from the command line: root @bible: /tmp # rpm –Uvh webmin-1.130-42.noarch.rpm... ########################################### [100%] Operating system is SuSE Linux 9. 1 1:webmin ########################################### [100%] Webmin install complete You can now login to http:/ /bible: 10000/ as root with your root password 4 Then revert to the original /etc /SuSE- release file and start Webmin with: root @bible: /tmp # cp /etc /SuSE- release.real /etc /SuSE- release root @bible: /tmp # rcwebmin start Chapter 14 ✦ Working... ( 192 .168.2.4) The Squid log contains entries like these: Chapter 14 ✦ Working with the System 10582 698 43.343 5 478 2 192 .168.2.4 TCP_MISS/000 0 POST http://journeyplanner.tfl.gov.uk/user/XSLT_TRIP_REQUEST2 DIRECT/journeyplanner.tfl.gov.uk 10582 698 47. 816 40315 192 .168.2.4 TCP_MISS/200 4 372 8 POST http://journeyplanner.tfl.gov.uk/user/XSLT_TRIP_REQUEST2 DIRECT/journeyplanner.tfl.gov.uk text/html 10582 698 48.652... Command Line in SUSE Linux Listing 15-1: Output of the ifconfig Command bible: ~ # ifconfig eth0 Link encap:Ethernet HWaddr 00:03:FF: 69: 68:12 inet addr: 192 .168.131 .70 Bcast: 192 .168.131.255 Mask:255.255.255.0 inet6 addr: fe80::203:ffff:fe 69: 6812/64 Scope:Link UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1 RX packets:30256 errors:0 dropped:0 overruns:0 frame:0 TX packets:35 690 errors:0 dropped:0... 344 Part III ✦ Using the Command Line in SUSE Linux Shell script resources You can find many good books available on shell scripting, including the following: ✦ Mastering UNIX Shell Scripting by Randal K Michael (Wiley, 2003) ✦ Linux Shell Scripting with Bash by Ken Burtch (Sams, 2004) ✦ Learning the bash Shell by Cameron Newham and Bill Rosenblatt (O’Reilly, 199 8) ✦ Wicked Cool Shell Scripts by Dave... for /dev/hdc: 0.000-14324.625 megabytes Disk label type: msdos Minor Start End Type Filesystem Flags 1 0.016 4042.000 primary fat32 lba, type=0c 2 6 677 .000 83 07. 000 primary ext2 type=83 3 83 07. 000 14324.000 primary reiserfs type=83 (parted) resize 2 6 677 8000 parted allows you to copy a filesystem from a partition onto another partition and can create a filesystem on the partition as soon as it creates... included with all current versions of SUSE At the time of this writing, there is a minor bug in the version of k3b shipped with SUSE regarding the way it displays the speed at which it is going to burn the disk, but this does not affect the functionality of the program Figure 14 -7 shows a CD being burned in k3b 3 29 330 Part III ✦ Using the Command Line in SUSE Linux If you want to burn disks from the... is.) But you won’t be able (easily) to read the resulting CD on a non -Linux system You may also have to mount it manually on Linux (with a command such as mount /dev/hdc /mnt) as subfs on current versions of SUSE will expect an iso9660 filesystem Webmin Webmin is a modular web-based administration tool that works on a wide variety of Linux versions and other Unix and Unix-like operating systems It allows... System These steps are needed because the Webmin RPM package in SUSE 9. 1, although configured for 9. 1, has an incorrect check for the OS version built into it, which has not been updated from the version for 9. 0 Contacting a running Webmin process When Webmin has been started, you should be able to access it via a browser by going to http:/ /bible: 10000 (or if name services are not available, the equivalent... web 331 332 Part III ✦ Using the Command Line in SUSE Linux page and perform administration tasks Webmin then “does the right thing” and makes the necessary appropriate changes to configuration files Webmin is included in the SUSE Professional distribution and works well with SUSE, even on SLES (though at the time of this writing it does not support SLES 9, that will undoubtedly change very soon) In some . System /dev/hda1 * 1 12484 6 291 904+ 83 Linux /dev/hda2 12485 16646 2 0 97 648 82 Linux swap /dev/hda3 166 47 478 54 1 572 8832 83 Linux /dev/hda4 478 55 77 520 1 495 1664 83 Linux This shows you the partitions. file /proc/partitions. root @bible: /tmp # cat /proc/partitions major minor #blocks name 3 0 390 70 080 hda 3 1 6 291 904 hda1 3 2 2 0 97 648 hda2 3 3 1 572 8832 hda3 3 4 1 495 1664 hda4 The fdisk -l command. (rw) 22_ 577 395 ch14.qxd 12/15/04 12:20 AM Page 321 322 Part III ✦ Using the Command Line in SUSE Linux user @bible: ~> df -h Filesystem Size Used Avail Use% Mounted on /dev/hda1 6.1G 5.5G 599 M 91 %

Ngày đăng: 24/07/2014, 02:20

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan