Выбрать главу

Command (m for help): p

Disk /dev/sdb: 8 MB, 8192000 bytes

4 heads, 16 sectors/track, 250 cylinders

Units = cylinders of 64 * 512 = 32768 bytes

Device   Boot Start End Blocks Id System

/dev/sdb1 *       1 250 7987+    1 FAT12

There is only one partition on this particular disk, and it is bootable (note the * in the Boot column). Use the a (activate) command to toggle the boot flag:

Command (m for help): a

Partition number (1-4):

 1

Then use w to write the partition table to disk and exit:

Command (m for help): w

The partition table has been altered!

Calling ioctl( ) to re-read partition table.

Syncing disks.

You can now rerun the graphical LVM administration tool and initialize the partition for use with LVM. This gives you a new physical volume that you can work with.

The next step is to add the new physical volume to the volume group. You'll see the newly initialized partition under Unallocated Volumes in the left pane. Click on it, and then click on the button labeled "Add Volume to existing Volume Group." A menu of volume groups will appear; select the one to add it to, and then click Add.

Once you've added a PV, you can use the extra space to create new logical volumes or grow an existing volume.

6.1.1.2.5. Removing a partition

To take a physical volume (partition) out of a volume group, select the PV in the left pane, and then click "Remove Volume from Volume Group." You will be prompted for confirmation (including any move of data to another device), and the PV will be removed (as long as the free space in the VG exceeds the size of the PV; otherwise, removing the PV would destroy data).

6.1.1.3. Managing LVMs from the command line

Logical volumes are almost always used to contain filesystems (the other common use is to hold swapspace). In essence, an LV serves as a container for a filesystem. This has several ramifications:

 The LV must be created before the filesystem can be created.

 The filesystem must be removed before the LV is destroyed.

 When growing an LV and filesystem, the LV must be grown first.

 When shrinking an LV and filesystem, the filesystem must be reduced first.

Fedora's LVM2 system provides the lvm command for administration. Typing lvm by itself starts a specialized shelclass="underline"

# lvm

lvm>

At the lvm> prompt, you can enter any of the subcommands shown in Table 6-1.

Table 6-1. LVM subcommands

LVM subcommand Description
vgs Displays details about volume groups (compact)
pvs Displays details about physical volumes (compact)
lvs Displays details about logical volumes (compact)
vgdisplay Displays details about volume groups (verbose)
pvdisplay Displays details about physical volumes (verbose)
lvdisplay Displays details about logical volumes (verbose)
vgcreate Creates a volume group
vgremove Removes a volume group
pvcreate Prepares a block device (such as a disk partition) for inclusion in a volume group by adding a disk label to the start of the block device
pvremove Wipes out the disk label created by pvcreate
vgextend Adds a physical volume to a volume group
vgremove Removes a physical volume from a volume group
pvmove Migrates data from one physical volume to another
lvcreate Creates a logical volume or snapshot LV
lvextend Grows a logical volume
lvreduce Shrinks a logical volume
lvresize Grows or shrinks a logical volume
vgscan Scans block devices for volume groups (necessary when using a rescue-mode boot)

You can also enter any of these subcommands as the first argument on the lvm command line:

# lvm lvs

LV VG Attr LSize Origin Snap% Move Log Copy%

home main -wi-ao 1.00G

multimedia main -wi-ao 512.00M

root main -wi-ao 9.77G

swap main -wi-ao 1.00G

Symbolic links have been set up from /usr/sbin/<subcommand > to /usr/sbin/lvm , so you can just type the name of the subcommand at the regular bash shell prompt:

# ls -l /usr/sbin/lvs

lrwxrwxrwx 1 root root 3 Mar 20 14:49 /usr/sbin/lvs -> lvm

# lvs

LV VG Attr LSize Origin Snap% Move Log Copy%

home main -wi-ao 1.00G

multimedia main -wi-ao 512.00M