• Aucun résultat trouvé

This partition type is used to indicate that it is an extended partition

Creating Partitions

05 This partition type is used to indicate that it is an extended partition

8e Use this partition type if you want to use the partition as an LVM physical volume.

Many additional partition types are available, but you’ll hardly ever use them.

Once you’ve created the partition, you’ll write the changes to disk. Writing the new par-tition table to disk doesn’t automatically mean your server can start using it right away. In many cases, you’ll get an error message indicating that the device on which you’ve created the partition is busy. If this happens, you’ll need to restart your server to activate the new partition. Exercise 5.1 shows how to create a partition.

E X E R C I S E 5 . 1

Creating Partitions

In this exercise, you’ll create three partitions: a primary partition, an extended partition, and, within the latter, one logical partition. You can perform this exercise on the remaining free space on your hard drive. If you followed the procedures described in Chapter 1, you should have free and unallocated disk space. However, it is better to perform this proce-dure on an external storage device, such as a USB fl ash drive. Any 1GB or greater USB fl ash drive allows you to perform this procedure.

In this exercise, I’ll describe how to work with an external medium, which is known to this server as /dev/sdb. You will learn how to recognize the device so that you do not mess up your current installation of Red Hat Enterprise Linux.

c05.indd 124

c05.indd 124 1/8/2013 10:44:21 AM1/8/2013 10:44:21 AM

1. Insert the USB fl ash drive that you want to use with your server. If a window opens showing you the contents of the USB fl ash drive, close it.

2. Open a root shell, and type the command dmesg. You should see messages indicating that a new device has been found, and you should also see the device name of the USB fl ash drive. Listing 5.1 shows what these messages look like. In this listing, you can see that the name of this device is sdb.

Listing 5.1: Verifying the device name with dmesg VFS: busy inodes on changed media or resized disk sdb VFS: busy inodes on changed media or resized disk sdb

usb 2-1.4: new high speed USB device using ehci_hcd and address 4 usb 2-1.4: New USB device found, idVendor=0951, idProduct=1603 usb 2-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3 usb 2-1.4: Product: DataTraveler 2.0

usb 2-1.4: Manufacturer: Kingston

usb 2-1.4: SerialNumber: 899000000000000000000185 usb 2-1.4: configuration #1 chosen from 1 choice scsi7 : SCSI emulation for USB Mass Storage devices usb-storage: device found at 4

usb-storage: waiting for device to settle before scanning usb-storage: device scan complete

scsi 7:0:0:0: Direct-Access Kingston DataTraveler 2.0 1.00 PQ: 0 ANSI: 2 sd 7:0:0:0: Attached scsi generic sg2 type 0

sd 7:0:0:0: [sdb] 2007040 512-byte logical blocks: (1.02 GB/980 MiB) sd 7:0:0:0: [sdb] Write Protect is off

sd 7:0:0:0: [sdb] Mode Sense: 23 00 00 00

sd 7:0:0:0: [sdb] Assuming drive cache: write through sd 7:0:0:0: [sdb] Assuming drive cache: write through sdb: unknown partition table

sd 7:0:0:0: [sdb] Assuming drive cache: write through sd 7:0:0:0: [sdb] Attached SCSI removable disk [root@hnl ~]#

3. Now that you have found the name of the USB fl ash drive, use the following com-mand to wipe out its contents completely: dd if=/dev/zero of=/dev/sdb.

The dd if=/dev/zero of=/dev/sdb command assumes that the USB flash drive with which you are working has the device name /dev/sdb. Make sure you are working with the right device before executing this command!

If you are not sure, do not continue; you risk wiping all data on your com-puter if it is the wrong device. There is no way to recover your data after overwriting it with dd!

c05.indd 125

c05.indd 125 1/8/2013 10:44:22 AM1/8/2013 10:44:22 AM

4. At this point, the USB fl ash drive is completely empty. Use fdisk -cu /dev/sdb to open fdisk on the device, and create new partitions on it. Listing 5.2 shows the fdisk output.

Listing 5.2: Opening the device in fdisk

[root@hnl ~]# fdisk -cu /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x3f075c76.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help):

5. From within the fdisk menu-driven interface, type m to see an overview of all com-mands that are available in fdisk. Listing 5.3 shows the results of this action.

Listing 5.3: Showing fdisk commands

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): m x extra functionality (experts only) Command (m for help):

c05.indd 126

c05.indd 126 1/8/2013 10:44:22 AM1/8/2013 10:44:22 AM

6. Now type n to indicate you want to create a new partition. fdisk then asks you to choose between a primary and an extended partition. Type p for primary. Now you have to enter a partition number. Because there are no partitions currently on the USB fl ash drive, you can use partition 1. Next you have to enter the fi rst sector of the partition. Press Enter to accept the default value of sector 2048. When asked for the last sector, type +256M and press Enter. At this point, you have created the new parti-tion, but, by default, fdisk doesn’t provide any confi rmation. Type p to print a list of current partitions. Listing 5.4 shows all steps you performed.

Listing 5.4: Creating a new partition in fdisk

Command (m for help): n

Last sector, +sectors or +size{K,M,G} (2048-2007039, default 2007039): +256M Command (m for help): p

Disk /dev/sdb: 1027 MB, 1027604480 bytes

32 heads, 62 sectors/track, 1011 cylinders, total 2007040 sectors Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x3f075c76

Device Boot Start End Blocks Id System /dev/sdb1 2048 526335 262144 83 Linux Command (m for help):

7. You have now created a primary partition. Let’s continue and create an extended parti-tion with a logical partiparti-tion inside. Type n again to add this new partiparti-tion. Now choose option e to indicate that you want to add an extended partition. When asked for the partition number, enter 2. Next press Enter to accept the default starting sector that fdisk suggests for this partition. When asked for the last sector, hit Enter to accept the default. This will claim the rest of the available disk space for the extended partition.

This is a good idea in general, because you are going to fi ll the extended partition with logical partitions anyway. You have now created the extended partition.

c05.indd 127

c05.indd 127 1/8/2013 10:44:22 AM1/8/2013 10:44:22 AM

8. Since an extended partition by itself is useful only for holding logical partitions, press n again from the fdisk interface to add another partition. fdisk displays two different options: p to create another primary partition and l to create a logical tion. Because you have no more disk space available to add another primary parti-tion, you have to enter l to create a logical partition. When asked for the fi rst sector to use, press Enter. Next enter +100M to specify the size of the partition. At this point, it’s a good idea to use the p command to print the current partition overview. Listing 5.5 shows what this all should look like.

Listing 5.5: Verifying current partitioning

Last sector, +sectors or +size{K,M,G} (526336-2007039, default 2007039):

Using default value 2007039

Last sector, +sectors or +size{K,M,G} (528384-2007039, default 2007039): +100M Command (m for help): p

Disk /dev/sdb: 1027 MB, 1027604480 bytes

32 heads, 62 sectors/track, 1011 cylinders, total 2007040 sectors Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x3f075c76

c05.indd 128

c05.indd 128 1/8/2013 10:44:22 AM1/8/2013 10:44:22 AM

Device Boot Start End Blocks Id System /dev/sdb1 2048 526335 262144 83 Linux /dev/sdb2 526336 2007039 740352 5 Extended /dev/sdb5 528384 733183 102400 83 Linux Command (m for help):

9. If you are happy with the current partitioning, type the w command to write the new partitions to disk and exit. If you think something has gone wrong, type x to exit with-out saving and to keep the original confi guration. In case you have any doubt, using x is a good idea because it won’t change the original partitioning scheme in any way.

10. If you see a message indicating an error while activating the new partitions, reboot your server.

Red Hat suggests that you need to reboot your server to activate new parti-tions if they cannot be activated automatically. There is an unsupported alternative, though: use command partx -a /dev/sdb to update the kernel partition table. You should be aware, however, that this is an unsup-ported option and you risk losing data!

At this point, you have added partitions to your system. The next step is to do some-thing with them. Since you created normal partitions, you would now typically go ahead and format them. In the next section, you’ll learn how to do just that.