[ Pobierz całość w formacie PDF ]
.The interesting partsof the output are the repeated references to [sdb] which matches our expectation of aSCSI disk device name.Knowing this, two lines become particularly illuminating:Jul 23 10:07:59 linuxbox kernel: sdb: sdb1Jul 23 10:07:59 linuxbox kernel: sd 3:0:0:0: [sdb] Attached SCSIremovable diskThis tells us the device name is /dev/sdb for the entire device and /dev/sdb1 forthe first partition on the device.As we have seen, working with Linux is full of interest-ing detective work!Tip: Using the tail -f /var/log/messages technique is a great way towatch what the system is doing in near real-time.With our device name in hand, we can now mount the flash drive:184Mounting And Unmounting Storage Devices[me@linuxbox ~]$ sudo mkdir /mnt/flash[me@linuxbox ~]$ sudo mount /dev/sdb1 /mnt/flash[me@linuxbox ~]$ dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/sda2 15115452 5186944 9775164 35% //dev/sda5 59631908 31777376 24776480 57% /home/dev/sda1 147764 17277 122858 13% /boottmpfs 776808 0 776808 0% /dev/shm/dev/sdb1 15560 0 15560 0% /mnt/flashThe device name will remain the same as long as it remains physically attached to thecomputer and the computer is not rebooted.Creating New File SystemsLet's say that we want to reformat the flash drive with a Linux native file system, ratherthan the FAT32 system it has now.This involves two steps: 1.(optional) create a new par-tition layout if the existing one is not to our liking, and 2.create a new, empty file systemon the drive.Warning! In the following exercise, we are going to format a flash drive.Use adrive that contains nothing you care about because it will be erased! Again, makeabsolutely sure you are specifying the correct device name for your system, notthe one shown in the text.Failure to heed this warning could result in you for-matting (i.e., erasing) the wrong drive!Manipulating Partitions With fdiskThe fdisk program allows us to interact directly with disk-like devices (such as harddisk drives and flash drives) at a very low level.With this tool we can edit, delete, andcreate partitions on the device.To work with our flash drive, we must first unmount it (ifneeded) and then invoke the fdisk program as follows:[me@linuxbox ~]$ sudo umount /dev/sdb1[me@linuxbox ~]$ sudo fdisk /dev/sdbNotice that we must specify the device in terms of the entire device, not by partition num-ber.After the program starts up, we will see the following prompt:18515 Storage MediaCommand (m for help):Entering an m will display the program menu:Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitionl list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)Command (m for help):The first thing we want to do is examine the existing partition layout.We do this by en-tering p to print the partition table for the device:Command (m for help): pDisk /dev/sdb: 16 MB, 16006656 bytes1 heads, 31 sectors/track, 1008 cylindersUnits = cylinders of 31 * 512 = 15872 bytesDevice Boot Start End Blocks Id System/dev/sdb1 2 1008 15608+ b W95 FAT32In this example, we see a 16 MB device with a single partition (1) that uses 1006 of theavailable 1008 cylinders on the device.The partition is identified as a Windows 95FAT32 partition.Some programs will use this identifier to limit the kinds of operationthat can be done to the disk, but most of the time it is not critical to change it.However,186Creating New File Systemsin the interest of demonstration, we will change it to indicate a Linux partition.To do this,we must first find out what ID is used to identify a Linux partition.In the listing above,we see that the ID b is used to specify the existing partition.To see a list of the avail-able partition types, we refer back to the program menu.There we can see the followingchoice:l list known partition typesIf we enter l at the prompt, a large list of possible types is displayed.Among them wesee b for our existing partition type and 83 for Linux.Going back to the menu, we see this choice to change a partition ID:t change a partition's system idWe enter t at the prompt enter the new ID:Command (m for help): tSelected partition 1Hex code (type L to list codes): 83Changed system type of partition 1 to 83 (Linux)This completes all the changes that we need to make.Up to this point, the device hasbeen untouched (all the changes have been stored in memory, not on the physical device),so we will write the modified partition table to the device and exit.To do this, we enter w at the prompt:Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation.Syncing disks.[me@linuxbox ~]$If we had decided to leave the device unaltered, we could have entered q at the prompt,18715 Storage Mediawhich would have exited the program without writing the changes.We can safely ignorethe ominous sounding warning message.Creating A New File System With mkfsWith our partition editing done (lightweight though it might have been) it s time to createa new file system on our flash drive.To do this, we will use mkfs (short for make filesystem ), which can create file systems in a variety of formats
[ Pobierz całość w formacie PDF ]