• Aucun résultat trouvé

Adding a Disk

7.9 M OUNTING USB DRIVES

#lvextend -L+10G /dev/LVM1/web1 Extending logical volume web1 to 20.00 GB Logical volume web1 successfully resized

#ext2online -d /dev/LVM1/web1 ...

ext2_close

That’s it! Examining the output of df again shows the changes:

#df -h /web1

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/LVM1-web1 20G 7.1G 12G 38% /web1

ReiserFS users must unmount the partition before running lvextend. Additionally, a tool creatively known as resize_reiserfs is used in place of ext2online to resize the filesystem.

7.9 M

OUNTING

USB

DRIVES

Floppy disks have finally gone the way of the dodo, and good riddance. In their place are friendly, fast, and fun USB drives. These devices come in many flavors: personal

“thumb” drives, digital cameras, iPods, and large external disks, to name a few. Re-cent Linux distributions include native kernel support for all these handy gizmos.

When connecting a USB drive, first make sure that Linux recognizes the device. The following command lists the USB devices the kernel has discovered:

$sudo /sbin/lsusb

Bus 001 Device 003: ID 0781:7108 SanDisk Corp.

Bus 001 Device 001: ID 0000:0000

In this case, a SanDisk drive has been attached. If no devices are listed but the device is plugged in, the kernel may not have USB support and will need to be recompiled.

Next, find out how the kernel has identified the drive and what device file it is using to represent it. The kernel messages are recorded through syslog.

$sudo tail -n 20 /var/log/messages | grep kernel8

Jul 27 20:52:13 harp kernel: USB Mass Storage support registered.

Jul 27 21:02:57 harp kernel: usb 1-2: USB disconnect, address 2 Jul 27 21:14:09 harp kernel: ohci_hcd 0000:00:0f.2: wakeup

Jul 27 21:14:09 harp kernel: usb 1-2: new full speed USB device using addr 3 Jul 27 21:14:09 harp kernel: scsi3 : SCSI emulation for USB Storage devices Jul 27 21:14:09 harp kernel: Vendor: SanDisk Model: Cruzer Titanium Rev: 2000 Jul 27 21:14:09 harp kernel: Type: Direct-Access ANSI SCSI revision: 02

Jul 27 21:14:09 harp kernel: SCSI device sde: 512-byte hdwr sectors (520 MB) Jul 27 21:14:09 harp kernel: sde: Write Protect is off

Jul 27 21:14:09 harp kernel: sde: assuming drive cache: write through Jul 27 21:14:10 harp kernel: sde: sde1

Jul 27 21:14:10 harp kernel: Attached scsi removable disk sde at scsi3, channel 0, id 0, lun 0

8. Look in /var/log/kern.log on Debian and Ubuntu systems.

The kernel messages indicate that this is a 520MB SanDisk Cruzer Titanium. (If you’re in the market, this an excellent USB key!) The kernel has associated the device /dev/sde with the disk, and the disk contains only a single partition, sde1.

The drive needs to be mounted by Linux before it can be used. Create a mount point and mount the drive:

$sudo mkdir /mnt/usb

$sudo mount /dev/sde1 /mnt/usb

The drive is now mounted on /mnt/usb and is ready for use. To ease the process the next time you use the drive, you could add the following line to /etc/fstab:

/dev/sde1 /mnt/usb auto users,noauto,uid=ben,gid=users 0 0

The listed options autodetect the filesystem type and allow the user ben to mount and write to the drive.

7.10 E

XERCISES

E7.1 Which SCSI connectors go with which variants of the specification? Ig-noring the differences in connectors, what are the compatibility issues among the various SCSI versions?

E7.2 What’s the difference between formatting a disk and partitioning a disk?

What’s the difference between partitioning and creating a filesystem?

E7.3 List the command and arguments you would use to create a filesystem on a disk in each of the following circumstances.

a) The disk will be used as storage for home directories.

b) The disk will be used as swap space.

c) The disk will store the mail queue at a large spam house.

d) The disk will hold a MySQL InnoDB database.

E7.4 The LVM tool suite is powerful but can be confusing if not well under-stood. Practice adding, removing, and resizing disks in a volume group.

Show how you would successfully remove a device from one volume group and add it to another.

E7.5 Using printed or Internet resources, identify the best-performing SCSI and IDE drives. Do the benchmarks used to evaluate these drives reflect the way that a busy Linux server would use its boot disk? How much of a cost premium would you pay for SCSI, and how much of a performance improvement (if any) would you get for the extra money?

E7.6 Add a disk to your system. Make one partition on the new disk a backup root partition; install a kernel and boot from it. Keep a journal of all the steps required to complete this task. You may find the script command helpful. (Requires root access.)

Adding a Disk

7.10 Exercises 149

E7.7 What is a superblock and what is it used for? Look up the definition of the ext3fs superblock structure in the kernel header files and discuss what each of the fields in the structure represents.

E7.8 Use mdadm and its -f option to simulate a failed disk in a RAID array.

Remove the disk from the array and add it back. How does /proc/md-stat look at each step?

E7.9 What fields are stored in an inode on an ext3fs filesystem? List the con-tents of the inode that represents the /etc/motd file. Where is this file’s filename stored? (Tools such as hexdump and ls -i might help.) E7.10 Examine the contents of a directory file with a program such as

hex-dump or od. Each variable-length record represents a file in that direc-tory. Look up the directory entry structure and explain each field, using an example from a real directory file. Next, look at the lost+found di-rectory on any filesystem. Why are there so many names there when the lost+found directory appears to be empty?

E7.11 Write a program that traverses the filesystem and prints the contents of the /etc/motd and /etc/termcap files. But don’t open the files directly;

open the raw device file for the root partition and use the seek and read system calls to decode the filesystem and find the appropriate data blocks./etc/motd is usually short and will probably contain only direct blocks. /etc/termcap will probably require you to decode indirect blocks. Hint: when reading the system header files, be sure you have found the filesystem’s on-disk inode structure, not the in-core inode structure. (Requires root access.)

150