<<

KNOW-HOW Ask Klaus! ASK KLAUS!

during unmounting, and lost data results I edit an existing script that already on a frequent basis when I disconnect comes with Fedora 7 (as used by the the device. desktop), to resolve the problem? Or is The drive heads are not stopped ei- this behavior compiled in? Klaus Knopper is the creator of ther, and a strange whirring chirp sound I believe the “eject” feature used by and co-founder of the occurs when unplugging the drive while Gnome is only meant for flash memory the platters are still spinning. drives such as USB keys, where there is LinuxTag expo. He currently I searched Google and found a shell no concept of flushing the data in RAM script to properly unmount the drive, to the magnetic storage medium and works as a teacher, program- and it uses a tool called sdparm to sync stopping the heads, and hence it is a mer, and consultant. If you have and stop the drive heads before physi- rather simple solution for unmounting cally disconnecting the USB hard drive. I that is not suitable for external portable a configuration problem, or if did not have sdparm installed by default hard drives. from my Fedora 7 distribution (obtained Thanks in advance for considering this you just want to learn more through a Magazine DVD) and Linux hardware challenge. about how Linux works, send had to search and install the tool myself using the package manager. (Zenity mes- The quite long script you sent your questions to: sage boxes also had to be installed for can be reduced to (more or less) this script.) this skeleton: klaus@linux-magazine. com I have attached the script in its current working state. The script solves the #!/bin/bash problem and prevents lost data and exec >/dev/null 2>&1 U stops the drive, as long as I remember # No error messages to switch to root before calling it from pumount $1 || umount $1 External USB Hard Drive the shell. Otherwise, I am down in the sdparm --command=sync $1 I enjoy your column in Linux trenches trying to sync my drive before sdparm --command=stop $1 Magazine because I am a new unplugging. The script, however, is lim- Linux user and electrical engi- ited to only one drive at a time, as the pumount only works if it’s installed, and neer trying to understand how the sys- mount point is hard coded to a specific if the normal desktop user is a member tem works. location in /media/WDPASSPORT. of the group plugdev; otherwise, the My question is related to the Western I would like to know how to take a command will fail (and the script will Digital “Passport” 250GB external USB shell script like this one, which manually use umount instead). In that case, the hard drive and how the mounting and unmounts and sync’s my USB drives cor- desktop keeps the disk busy at the mo- synchronization of the data cache oper- rectly, and associate it with the icon that ment of the umount call. ates in Fedora 7 with the Gnome desk- is automatically created for the drive in Lazy umount (umount -l) could be top. Automatic mounting of the drive the Gnome desktop so that when I use called instead, which will umount the takes place when the device is plugged the mouse to in, and an icon is created on the desktop “eject” the that can be used to access the data. drive, it calls However, the “eject” feature using the this script. mouse does not properly synchronize Alterna- the data cache with the physical medium tively, can

60 ISSUE 90 MAY 2008

060-062_ask-klaus.indd 60 12.03.2008 14:31:10 Uhr Ask Klaus! KNOW-HOW

drive whenever nobody accesses it any- I know it is more. Because a umount entry should be part of the usual KDE or Gnome ser- Chmod 777 vice menu for a hard disk, the entire umount... command line is not really but what do I write needed, but it probably does not hurt after that? if it’s there, either. I have a folder The SCSI disk control command sd- called church that is parm is available as a package, under htdocs. At the but it is not necessarily preinstalled in prompt every distribution yet. In this example, it will send a “sync,” which will write dull:/srv/www/ U back all pending physically unwritten htdocs # data back to the medium; however, in theory, the umount command should I have typed also have told the (virtual) SCSI driver Figure 1: Type man chmod to call up the chmod manpage. to do this. chmod church/* The most important command in the The preceding command should do example is probably sdparm but when I checked later, I found some what you intended; however, with file --command=stop, which will power off files were not changed. permissions like this, everyone working the motor and park the heads of the re- What am I doing wrong? on the computer will be able to read, movable disk to avoid the noise effect change the content, and delete files. In you mentioned. Noise always means chmod works with options that case your web server uses potentially mechanical friction, which damages disk tell the command what to do. If unsecure scripting extensions, the web surface and heads in the long term. your intention is to make the di- server itself can even change the content Now, to get the script to work with the rectory church, which is a subdirectory of files now, because it has full write ac- right-click context menu, edit this file in of /srv/htdocs, and all files under it read- cess. Be aware of the security implica- KDE: able, writable, and executable for every- tions, and make sure you always have one on the system, the command is: a recent backup. /usr/share/apps/konqueror/U servicemenus/media_eject.desktop chmod -R ugo=rwX U Partitioning /srv/www/htdocs/church I just wrote you these few lines by changing the line that says because I have a couple of ques- Be careful with the spelling. Capitals and tions. I am very new to Linux. Exec=kio_mounthelper -e %u spaces have a meaning. I had installed a new hard drive to my Table 1 shows a description of the op- laptop because the old one was bad. to tions used in this command. Type man I used the recovery disk, and it put back chmod at the command line or consult a the original Windows XP operating sys- Exec=/path/to/your/script %v standard Linux reference for a complete tem on the hard drive. list of chmod options. I would like to partition my hard drive The script must be called with the device If you want to see what’s happening so I can install a Linux SUSE system as name as a parameter, which is what %v while it’s happening, use option -v right well. How can I partition my NTFS hard means. after -R in the preceding command. drive? For Gnome, I have not found a way to The abbreviation 777, which you men- Also, how can I differentiate between do this without changing the source of tioned, is a bitmask that means the same which I want to use at the mount/eject helper applets, but there thing as ugo=rwx (which would also the beginning of the booting process? may be a way to change the settings for force execute permissions for files that manually created icons. are not supposed to have them). Caution: There is no such thing as an “NTFS disk.” A hard disk Permissions Table 1: Options in chmod -R ugo=rwX is independent of the operating One of the frustra- system and can be partitioned into -R (capital R) means “recursive” (i.e., not only the tions I have in directory, but also everything inside). smaller parts that can be used by various Linux is folder ugo Change the settings for: user (file creator), group operating systems with their individual and file permissions. (every file/ dir has one), all others (who are neither filesystems. How do I give a com- user or group) Although Linux can read and write to mand so that a folder and = Set only these permissions; remove all others. NTFS without problems using -3g, all that is underneath rwX Set read and write permission and set the NTFS is still not a good filesystem for it (folders and files) are “executable” flag for directories, which is necessary hosting a Linux operating system be- in order to access their content. completely open? cause it simply does not support all of

MAY 2008 ISSUE 90 61

060-062_ask-klaus.indd 61 12.03.2008 14:31:45 Uhr KNOW-HOW Ask Klaus!

the features and file types that Linux 10.1.1.1 to configure, or the programs If your network card is eth0, you needs. The steps for creating a new can’t reach home to finish updates. would set an IP address for the card ei- partition for Linux – or better, two new Both computers use Firefox and Thun- ther via a graphical configuration front partitions, are: derbird, the same as Windows, using the end of your – use 1. Run an NTFS defragmentation on same asdl modem. As I said, all was DHCP with pump -i eth0 or dhclient eth0 Windows. This should put all files at working well and suddenly stopped. – or set a static address by typing (as the beginning of the NTFS partition, D-Link is advertised as Linux compati- root) so there is enough free space at the ble. I am not a power user – just an old end to resize and create new parti- guy who rebels against Microsoft. ifconfig eth0 10.1.1.3 U tions. netmask 255.0.0.0 U 2. After defragmenting the filesystem, re- You don’t need to be an expert broadcast 10.255.255.255 size the partition holding the NTFS/ or a rebel to use Linux, but you Windows filesystem – reduce the par- are right about the fact that free and add a gateway route through the tition to a size that you think is neces- software is a way out of dependencies. modem with sary. Be aware that Windows is not By the way, I’m unfortunately living in capable of writing to Linux filesystem a DSL-free zone, and I am waiting for route add default gw 10.1.1.1 partitions without additional drivers, bandwidth. Anyway, let’s try to free your but Linux can write to NTFS. You can DSL modem. which should, as soon as the modem do the NTFS resizing on Windows There are two ways to configure the is functional as a router, allow network (there should be an utility in “proper- DSL modem, the easier of which is traffic to and from the Internet. ties”) or use a hard router mode. The default is probably One last thing you need, in case DHCP program under Linux that can handle modem/ pppoe mode. did not set a name server, is the line NTFS (qtparted, , or ntfsre- In router mode, all you need to do is nameserver 10.1.1.1 in the file /etc/ size). send a DHCP request from the network resolv.conf. This tells Linux to use the 3. Create at least two new partitions on card for a complete autoconfiguration. modem as a name server for resolving the remaining free space. One should In modem mode, you need to configure computer names (such as linux-maga- be a swap partition that is used by authentication credentials on your com- zine.com) into IP addresses (which is Linux to extend the available RAM puter, which can be done by using the what every network connection needs). with available hard disk space. (The program pppoeconf (or whatever tool After having configured your local net- size of the swap partition depends on is provided by your distribution). work this way, you should be able to what you plan to do; for large graph- To configure the modem for one or reach the modem with any browser by ics/ video editing programs, use 2GB the other mode, you first need to reach entering http://10.1.1.1/ as a website or more for swap), and use the second it from the computer. If your modem’s address. If the modem is already set to (third, in total) partition for the Linux fixed address is 10.1.1.1, your network router mode, then you’ll already have installation. You can create the Linux card must be configured as a member immediate Internet access. partitions from the installer of most of the same network in order for you to At each step, you can check to see Linux distributions, so you could also connect to the modem. Usually, the whether the modem is reachable from just go straight to step 4. modem is set up to deliver an appropri- the configured network card with the 4. Run the Linux installation disk, and ate local IP address to the connected net- command: be careful to install to the new Linux work card when the card sends a DHCP partition, not the Windows partition. broadcast, but this may depend on the ping 10.1.1.1 Usually, the GNU/Linux installations modem’s preset configuration. (Control-C to quit) will create a master boot record that lets you choose the operating system from a I think that the only thing missing in boot menu. your DSL configuration was the local IP address of the network card, which can Internet be handled with either DHCP or a static I am hoping you can help me. I setting. am writing this under Windows Also, be aware that in rare cases, some (ugh ) because whichever ver- DSL routers/ modems only accept net- sion of Linux I try I cannot get on the In- work cards when they have been ternet or receive email. I was on Linux plugged in prior to switching on the for about a year using SUSE, Xandros, or modem. However, this should not affect Mandrake 9, but one day all connectivity the DSL-504T. I ceased. Both my computers are AMD. I was using a D-LINK ASDL modem router Send your Linux questions to DSL-504T and an Ethernet card. The ma- klaus@linux-magazine. com. chine detects the card , but I cannot call

62 ISSUE 90 MAY 2008

060-062_ask-klaus.indd 62 12.03.2008 14:31:51 Uhr