Liunx Command Logging

Source: Internet
Author: User
Tags disk usage hex code ide hard drive

The management of Linux Disk Management is directly related to the performance of the whole system.

Linux Disk Management commonly uses three commands for DF, Du, and Fdisk.

    • DF: List The overall disk usage of the file system
    • Du: Check Disk space usage
    • FDISK: For disk partitioning

Today, let's take a look at how to use the Fdisk and parted partitioning tools to partition a hard disk, and let me say how these two hard disk partitioning tools are used in Linux systems:
----------fdisk Partitioning Tool----------
In my other article I have already mentioned the concept of hard disk partitioning in Linux systems (http://blog.chinaunix.net/u3/112561/showart_2230401.html), so I won't say much here, If you don't understand, you can read the article.
First,. The following describes the command format for the Fdisk partitioning tool:
Fdisk is a traditional Linux hard disk partitioning tool and is one of the most commonly used hard disk partitioning tools in Linux, and its command format is as follows: 740) this.width=740; "border=0> the common command options are described below:
-B sectorsize: Defines the size of the disk sector, valid values are 512, 1024, and 2048, which are only valid for older versions of the Linux operating system.
-C Cyls: Defines the number of cylinders on a disk, and generally does not need to be defined, using the default is good.
-H heads: Defines the number of hits on the disk used by the partition table, typically 255 or 16.
-S sects: Defines the number of sectors per track, typically 63.
-L: This is the most commonly used command option, which is to display the partition table information for the specified disk device, such as viewing/DEV/SDB1 partition table information for this disk device: Fdisk-l/dev/sdb1
-U: When displaying partitioned tables, sectors instead of cylinders are displayed as units
-S partition: Displays the size of the partition in block units in standard output.
-V: Displays version information for FDISK.
Device: Is the name of the disk, the IDE-type disk device name is [dev/hd[a-h]], and the SCSI or SATA type of disk device is named [Dev/sd[a-p].
If I want to view the partition table information of the first disk on my computer (hehe, I have a hard drive) you can use the following command: Fdisk-l/DEV/SDA (My hard drive is SATA type) display information 740) this.width=740; "Border=0>
Then we can look at each of them corresponding disk device files:
Use the command: ll/dev/sda* to view 740) this.width=740; "Border=0> friends can try the role of other commands, because of the time problem I do not say here! Let's take a look at how to use the Fdisk tool to partition a hard disk.
Second, Fdisk interactive mode:
When we use the command "fdisk+ device name", we can enter the interactive mode of the Fdisk program, in the interactive mode can be entered by the instructions provided by the FDISK program to complete the corresponding operation, the result 740) this.width=740; "Border=0> When we enter this mode, we can do the corresponding partition management operation by inputting the instruction of Fdisk, input m can get the instruction help information of Fdisk:: 740) this.width=740; "Border=0> Let's take a look at the instructions for using each instruction:
A: Setting a bootable tag
B: Modify the BSD disk label
C: Set DOS operating system compatibility tag
D: Delete a partition
L: Shows the known partition type, where 82 is a Linux swap partition and 83 is a Linux partition
M: Display Help information
N: Add a new partition
O: Create a new, blank DOS partition table
P: Displays the current partition table of the disk
Q: Quit the FDISK program without saving any changes
S: Create a new blank Sun disk label
T: Change the system number of a partition (e.g. change the Linux swap partition to a Linux partition)
U: Change display recording unit
V: Verify the disk partition table
W: Save the modified result and exit the FDISK program
X: Special function, not recommended for beginners
Knowing the meaning of the above commands, you can say that a piece of hard disk is partitioned. Let me give an example to illustrate:
First I add a hard disk to the virtual machine, the size is 170G, and then partition it:
1. First enter the "fdisk-l" command to see the add on the hard drive does not, and then enter the command "Fdisk/dev/sdb" to enter the Fdisk program interaction mode, such as: 740) this.width=740; "Border=0>
2. Enter the command "n" to create a new partition, this time the system will let you enter whether to create a new primary or extended partition, I select the primary partition (P), and then enter the partition number (because I am a new hard disk, has not been partitioned, so input 1 for the first primary partition), and then the starting cylinder, directly select the Finally enter the size of your partition, I here is the point of almost 50G it! Such a partition will be divided, then you can enter the P command to see, such as: 740) this.width=740; "Border=0>
3. This time I set up an extension partition, first enter the instruction N to create a new partition, then enter E to select the extended partition, and then enter the partition number (2), and then choose the default is OK! Set up after using the command p to see, 740) this.width=740; "Border=0>
4. Next I create two logical partitions inside the extended partition, first enter the instruction N, then select the partition type L (logical partition) starting cylinder Select default, and then enter the size of this logical partition, I divide 40G. Finally enter the command p to see if the success,: 740) this.width=740; "Border=0>
5. The same steps create another logical partition, which is not much to say. Here's a look at how to modify the type of a partition.
6. Enter the instruction T to modify the partition type (just enter the ID number of the partition type), and then enter the partition number to be modified, I am here to modify the SDB5 (that is, enter 5 OK). Finally enter the ID number of the partition type, and if you do not know the ID number of the partition type, you can enter the "L" directive to see the ID number of the partition type. 740) this.width=740; "Border=0>7. After you find the ID number of the partition type, you can enter the corresponding ID number to modify the partition type, and I'll change the Linux partition to the Linux swap type, from the known Linux Swap type of the corresponding ID is 82, enter 82 after the return to complete the modification, you can use the command p to see, 740) this.width=740; "Border=0>
8. These are the whole process of partitioning the hard disk using the Fdisk partitioning tool, oh, don't forget the last step, you have to enter the command W to save the operation you have done, after saving you can use Fdisk-l/dev/sdb to see if the partition is successful. 9. Above we partition the hard disk, the hard disk after the division is not directly used after the format to use, we will format the hard disk. Enter "MKFS.EXT3" to format the hard drive as a ext3 type file system. The use of the specific MKFS command, you can use the man mkfs command to view, here is not explained in detail. 10. Enter the MKFS.EXT3/DEV/SDB1 command to format the hard disk, a partition must be formatted to complete, there is a special partition is swap, you can use the command MKSWAP/DEV/SDB5 to format the partition of swap type. such as: 740) this.width=740; "border=0>740) this.width=740;" Border=0>
11. After formatting the file system, you need to mount the disk before it can be used normally, Mount command is mount, using the following format:
Mount [-T file system type] storage device mount point (usually file system type can be omitted, the system will automatically recognize)
12. Before mounting you need to create a new mount point, which is where you want to mount the disk, and then you can set the mount point where it is OK. For example, in the example above, I'm going to mount the/DEV/SDB1 partition, so I'll start by creating a new mount point for it: MKDIR/MEDIA/SDB1, and then execute: MOUNT/DEV/SDB1/MEDIA/SDB1 the name of the mount point can be random, You can write something on the disk after you mount it, 740) this.width=740; "Border=0>
13. For the sake of convenience, we can also modify the relevant configuration file, so that the system to automatically mount a partition, specifically to modify the/etc/fstab configuration file to implement, I use the above example to configure the/DEV/SDB1 partition to automatically mount to the/media/each time the system starts SDB1 below, you can modify the configuration file as follows, 740) this.width=740; "Border=0>
14. According to the above, when the system starts each time, it automatically mounts the/DEV/SDB1 partition to the/MEDIA/SDB1 without having to mount it manually each time.
15. If we do not want to use a partition, we need to uninstall it, you can use the "Umount + device mount point" command to uninstall. As in the example above: UMOUNT/MEDIA/SDB1 command to uninstall.
Note: Sometimes you encounter a situation that cannot be uninstalled because the file system is being accessed by another user or process, and in a Linux system, the file system that is being accessed is not allowed to unload, only if all access users or processes on the file system have completed the operation and exited , the file system can be uninstalled normally. We have two methods to deal with this situation, one is to use the command "Lsof + mount point" to see exactly which processes are accessing the file system, find out, use the KILL command to kill the process to uninstall. The second is to use the command "Fuser-k + mount point". The plus-k option is to use the command Fuser to find out which process is accessing the file system, plus the-k option to find it and kill it. These two methods allow you to uninstall some file systems that cannot be uninstalled.
----------parted Partitioning Tool----------
Parted is another partition software that comes with RHEL5, it is more convenient to use than Fdisk, and it also provides the ability to dynamically resize partitions. Here's how to create, delete, and view partitioned tables, change partition sizes, create file systems, and use parted interaction mode with parted.
First, parted introduction:
Parted is another partition software commonly used under Linux, and it supports a wide range of partition types, including ext2, Ext3, Linux-swap, FAT, FAT32, ReiserFS, HFS, JSF, NTFS, UFS, and XFS. Its command format is as follows:
parted [options] [Device [command [Options ...] ...] ]
The command options are described below:
-H: Displays help information.
-I: Interactive mode.
-S: script mode.
-V: Displays the version information for the parted.
Device: Disk device name, such as/DEV/SDA.
command:parted instruction, if no instruction is set, then parted will enter interactive mode.
Second, parted interactive mode:
Similar to Fdisk, parted can enter interactive mode using the command "parted+ device name". After entering interactive mode, the disk partition can be managed by various directives of parted, very similar to Fdisk. I also take the hard drive on my computer as an example, is entering the parted interactive mode and enter the Help command interface:-_-! Khan, there is a picture missing, may not be copied on it ... You can enter parted interactive mode by entering "parted/dev/a device" under terminal.
Parted's various operating instructions and detailed instructions are as follows:
Check number checks file system
CP [from-device]from-number to-number Copy file system to another partition
Help[command] Show all help information or specify a command's help
Mklabel,mktable Label-type Create a new disk label in the partition table
MKFS number Fs-type Create a file system of the specified type on the partition
Mkpart Part-type[fs-type]start END Create a partition
Mkparts Part-type[fs-type]start END Creates a partition and creates the specified file system on the partition
Move number START END mobile partition
Name Number name names the partition numbers with the specified name
Print [free| Number|all] Show partition table, specified partition, or all devices
Quit Quit parted program
Rescue START END repairs the missing partition
Resize number START END to change the size of the partition
RM Number Delete Partition
Select device selects devices that need to be changed
Set number flag state changes the partition's markup
Toggle [Number[flag]] Sets or cancels a partition's markup
Unit Unit Set Default unit
Version displays the release information for parted
Third, partition management
1. View partitions
Enter the Print command in parted interactive mode to view the partition (equivalent to the p instruction of Fdisk), 740) this.width=740; "Border=0> 2. Creating a Partition
To create a disk partition by entering the Mkpart directive in parted interactive mode, if you want to create a logical partition with a start location of 50G and an end position of 100G and a file system type of ext3, you can use the following command to create:
Mkpart logical ext3 50G 100G 740) this.width=740; "Border=0>
Of course, you can only enter the mkpart instruction without any parameters, parted will prompt the user to enter the relevant information and finally complete the partition creation, 740) this.width=740; "border=0>3. Creating a file system
After you create the partition, you can use the MKFS directive to create the file system on the partition (that is, format), parted currently only support ext2 file system, and ext3,740) this.width=740; "Border=0>
4. Change the partition size
Use the Resize directive to change the size of the specified partition. partitions that need to be resized must have a file system already created, otherwise you will be prompted: Error:could not detect file systems. Below I take dev/sdb6 as an example to reduce 22G, because I now have run out of disk, so can not add! Just reduce it! 740) this.width=740; "Border=0>
5. Deleting a partition
The RM instruction allows you to delete the specified disk partition, which must be unloaded before the delete operation, for example, if I want to delete/dev/sdb6 is to enter the "rm" instruction in parted interactive mode and enter the partition number to be deleted. 740) this.width=740; "Border=0> ... shit! Finally finished, not easy ah, exhausted me. It's almost 1 O '-_-! hurry to go to bed! Friends have what do not understand the message to me, I flash ... ~~~~~~~~~~~~~~~~~

7.2.1 Hard disk partition

In the past, the PC hard disk has been using the 32-bit Pc-bios partition table and master boot record (MBR), so the maximum partition size cannot exceed 2TB, and each hard disk can contain up to 4 primary partitions. Using an extended partition can break the limit of 4 primary partitions. To solve the 2TB limitation, the GPT (GUID Partition tables,guid partition table) is being used instead of the Pc-bios partition table.

Fdisk was a standard command for manipulating disk partitions. However, because Fdisk cannot manipulate the GPT partition, it has been slowly discarded. Instead, the parted command is stronger, more supportive and more active.

Note If you prefer to use the graphical interface tool to partition hard disk partitions, resize partitions, and other hard disk operations, try the GParted or qtparted partitioning tool. The commands for both tools have the same name as the package.

1. modifying disk partitions with FDISK

The FDISK command can list and modify disk partitions. Remember, modifying or deleting a partition may remove important data, and you must be aware of the changes you have made before writing to disk. Type the following command with root permission to list information about the hard disk partition:

  1. # FDISK-L lists individual disk partitions
  2. disk/dev/sda:82.3 GB, 82348277760 bytes
  3. 255 heads, Sectors/track, 10011 cylinders
  4. Units = Cylinders of 16065 * 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /DEV/SDA1 * 1 104391 Linux
  7. /dev/sda2 9881 79264710 Linux
  8. /dev/sda3 9882 10011 1044225, Linux swap

From the command output, this 80GB drive is divided into 3 partitions. The first (/DEV/SDA1) is a smaller/boot partition configured as a LINUXEXT3 file system (Id 83). Note that the asterisk (*) indicates that the partition is a bootable partition. The second partition is the root file system partition, which also uses the Ext3 file system. The last partition is the swap partition (Linux swap).

Note in Fedora 7 and subsequent versions, both IDE and SCSI disks use the/DEV/SD device name, where? Represents a letter (a, B, or C, etc.). In RHEL5 and earlier versions of Fedora, only SCSI disks and USB drives use the/dev/sd?,ide hard drive using/DEV/HD.

If you have more than one disk, Fdisk-l will list all the disks unless you explicitly specify which disks to view:

    1. # fdisk-l/DEV/SDB list partition of a disk

When using the Fdisk command, specify a disk directly and without other options to manipulate the specified disk:

  1. # FDISK/DEV/SDA initiates an interactive fdisk session and operates on the first disk
  2. Command (M for help): M type M to list the following helpful information
  3. Command Action
  4. A toggle a bootable flag
  5. b Edit BSD Disklabel
  6. C Toggle the DOS compatibility flag
  7. D Delete a partition
  8. L list known partition types
  9. M Print this menu
  10. n Add a new partition
  11. o Create a new empty DOS partition table
  12. P Print the partition table
  13. Q Quit without saving changes
  14. s create a new empty Sun Disklabel
  15. t change a partition ' s system ID
  16. U Change display/entry units
  17. V Verify the partition table
  18. W Write table to disk and exit
  19. X Extra functionality (experts only)
  20. Command (M for help):

After the prompt is displayed, you can use the commands listed above to manipulate the hard disk. Specifically, you can use P (which shows the same results as Fdisk-l), N (Create a new partition), d (delete an existing partition), L (list known file system types), or T (change the partition file system type). The following examples illustrate several FDISK commands:

  1. Command (M for help): D prepare to delete a partition
  2. Partition number (1-4): 4 Type the partition numbers you want to delete
  3. Command (M for help): n Create a new disk partition
  4. First cylinder (1-4983, default 1): 1 Sets the starting cylinder number (or direct carriage return)
  5. Last cylinder ... (Default 4983): 4983 Set End cylinder number (or direct carriage return)
  6. Command (M for help): A sets the bootable partition
  7. Partition number (1-3): 1 Type the bootable partition numbers
  8. Command (M for help): T Select File System type
  9. Partition number (1-3): 3 Select the partition you want to modify
  10. Hex code (type L to list codes): 82 designate partition as Swap partition

Unless explicitly specified, the new partition uses the Linux ext3 file System (83) by default. The l command is equivalent to the L command and can display the file system type and hexadecimal code. As shown above, type 82 to designate the partition as swap. Other more common Linux partitions include Linux extensions (85), Linux LVM (8e), Linux software RAID (FD), and EFI/GTP (EE).

The Windows partition can be specified as Hpfs/ntfs (7), Windows FAT32 (b), FAT16 (6), or Windows FAT32 LBA (c). Other Unix class file systems include Minix (be or BF), Bsd/os (E4), FreeBSD (EE), OpenBSD (EF), NeXTSTEP (F0), Darwin UFS (F1), and NetBSD (F4). These file systems can come in handy, such as when you need to restore backup storage media with the above file system.

At this point, the partition table does not actually make any changes. If you are sure that the previous settings are correct, just type W to write the above changes to the partition table. If you are ready to discard any changes (or exit after writing to the partition table), you can exit the Fdisk session by typing Q directly.

2. Copy the partition table with Sfdisk

Use Sfdisk to back up or copy disk partition tables:

    1. # sfdisk-d/DEV/SDA > sda-table back up the partition table to a file
    2. # SFDISK/DEV/SDA < sda-table recover partition table from file
    3. # sfdisk-d/DEV/SDA | SFDISK/DEV/SDB copying partitioned tables between two disks

3. Modifying disk partitions with parted

Like Fdisk, parted can also list or modify disk partitions. In addition, parted also has some other useful functions. The following example uses parted to list partitions:

  1. # parted-l
  2. Model:ata FUJITSU mpg3409a (SCSI)
  3. disk/dev/sda:41.0gb
  4. Sector size (logical/physical): 512b/512b
  5. Partition Table:msdos
  6. Number Start End Size Type File system Flags
  7. 1 32.3kB 206MB 206MB primary ext3 Boot
  8. 2 206MB 39.5GB 39.3GB primary ext3
  9. 3 39.5GB 41.0GB 1536MB primary Linux-swap

From the command output, you can see the traditional MSDOS disk label (partition table) or GPT label used by the disk. Here is the MSDOS partition table.

Typing parted, followed by the name of the storage device you want to manipulate (such as/DEV/SDA), runs parted interactively. If you have only one storage device, you can type parted directly:

    1. # parted
    2. GNU Parted 1.8.6
    3. Using/dev/sda
    4. Welcome to GNU parted! Type ' help ' to view a list of commands.
    5. (parted)

When using parted interactively, you can type the entire command, or you can just type the first part of the character and use the TAB key to complete the entire command (as in the Bash shell). Once these commands are known to the heart, just type a certain number of letters, allowing parted to guess which command to enter. As with Ciscoios's usage: P stands for print,mkl on behalf of Mklabel.

Warning Unlike Fdisk, changes made to the partition using parted will take effect immediately without having to write to the disk separately. In short, do not mistakenly think that directly exiting parted can undo all changes.

For each command in a parted session, you can choose to type all parameters together when entering a command (for example, Mkpart logical ext3 10.7GB 17.0GB) or just the command itself (Mkpart), and parted will instruct the subsequent actions interactively:

    1. (parted) Mkpart create a new partition
    2. Partition type? [Logical]? Primary
    3. File system type? [Ext2]? Ext3
    4. Start? 17GB
    5. End? 24GB

Try not to use MKPARTFS, which does not create the ext3 partition correctly. You can use the Mkpart override to create a ext3 partition (shown above) and then format the partition with the MKFS.EXT3 command after exiting parted. When creating new partitions, it is often necessary to adjust the size of the common Linux partitions, as shown in the following example:

    1. (parted) Resize 2 resizing the partition
    2. Start? [1.2GB] 1.2GB
    3. End? [24GB] 10GB

Warning If you are not using LVM, the above command will destroy the entire file system.

Use the Ntfsresize command to adjust the NTFS partition size. In Fedora, the command belongs to the Ntfsprogs package. This package also contains commands for creating (MKFS.NTFS), Repairing (ntfsfix), and getting NTFS partition-related information (ntfsinfo).

Liunx Command Logging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.