常用的磁盘操作命令有fdisk, cfdisk, sfdisk, mkfs, parted, partprobe kpartx, 在Linux中挂载一个新磁盘时,常用到如下操作:

1. fdisk



# fdisk -l

Disk /dev/vda: 26.8 GB, 26843545600 bytes, 52428800 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 label type: dos
Disk identifier: 0x0008f170

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    52428749    26213351   83  Linux


# fdisk -h
 fdisk [options]     change partition table
 fdisk [options] -l  list partition table(s)
 fdisk -s       give partition size(s) in blocks

 -b              sector size (512, 1024, 2048 or 4096)
 -c[=]           compatible mode: 'dos' or 'nondos' (default)
 -h                    print this help text
 -u[=]           display units: 'cylinders' or 'sectors' (default)
 -v                    print program version
 -C            specify the number of cylinders
 -H            specify the number of heads
 -S            specify the number of sectors per track


# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

2. mkfs 


# mkfs -t ext4 /dev/sdb1

# mkfs.ext4 /dev/sdb1


# mkfs --help
 mkfs [options] [-t ] [fs-options]  []

 -t, --type=  filesystem type; when unspecified, ext2 is used
     fs-options     parameters for the real filesystem builder
            path to the device to be used
              number of blocks to be used on the device
 -V, --verbose      explain what is being done;
                      specifying -V more than once will cause a dry-run
 -V, --version      display version information and exit;
                      -V as --version must be the only option
 -h, --help         display this help text and exit

3. df

# df -h

4. blkid
显示block devices信息:

# blkid
/dev/sda2: UUID="cc648f16-2695-451d-a133-e90b5ea8add3" TYPE="ext3"
/dev/sda1: UUID="3cb0a414-123d-4728-aca2-6d18e24e272e" TYPE="ext3"
/dev/sda3: UUID="dc6e8463-90c7-419b-8ce0-0f6adf6d870f" TYPE="swap"
/dev/sdb: UUID="840d4ffe-00ce-4a2e-83c8-b8b94e6d005b" TYPE="ext4"

5. mount

# mount -t ext4 /dev/sdb1 /data



# mount -t ext4 -U 840d4ffe-00ce-4a2e-83c8-b8b94e6d005b /data

# mount -t ext4 UUID="840d4ffe-00ce-4a2e-83c8-b8b94e6d005b" /data

mount –all则装载/etc/fstab中的所有配置。

5. /etc/fstab

UUID=cc648f16-2695-451d-a133-e90b5ea8add3   /                       ext3    defaults        1 1
UUID=3cb0a414-123d-4728-aca2-6d18e24e272e   /boot                   ext3    defaults        1 2
UUID=dc6e8463-90c7-419b-8ce0-0f6adf6d870f   swap                    swap    defaults        0 0
UUID=840d4ffe-00ce-4a2e-83c8-b8b94e6d005b   /var/opt                ext4    defaults        1 0