linux 掛載新的硬盤

1.先查看新的盤所在位置 運行命令node

fdisk -l

返回以下docker

Disk /dev/xvda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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: 0x000d7b57

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048     8386559     4192256   82  Linux swap / Solaris
/dev/xvda2   *     8386560    83886079    37749760   83  Linux

Disk /dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders, total 629145600 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: 0x00000000

Disk /dev/xvde doesn't contain a valid partition table

2.發現咱們的那塊硬盤是/dev/xvde,運行格式化命令對硬盤進行格式化app

fdisk /dev/xvde

在格式化的過程當中,要依次輸入 m(查看幫助) n(添加一個新的分區) p(主分區) 1 w(保存)ide

整個過程以下ui

szvphicpra16181:/opt # fdisk /dev/xvde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xad312bcf.
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): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   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)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1): 1
First sector (2048-629145599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599):
Using default value 629145599

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3.通過格式化分區表以後,在用fdisk -l 命令發現已經有分區表了this

szvphicpra16181:/opt # fdisk -l

Disk /dev/xvda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 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: 0x000d7b57

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048     8386559     4192256   82  Linux swap / Solaris
/dev/xvda2   *     8386560    83886079    37749760   83  Linux

Disk /dev/xvde: 322.1 GB, 322122547200 bytes
129 heads, 6 sectors/track, 812849 cylinders, total 629145600 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: 0xad312bcf

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1            2048   629145599   314571776   83  Linux

採用ext3格式進行格式化 運行以下命令,與結果以下:(或者運行mkfs.ext3 /dev/vdb命令)code

szvphicpra16181:/opt # mkfs -t ext3 /dev/xvde1
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
19660800 inodes, 78642944 blocks
3932147 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Checking for bad blocks (read-only test): done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

4.最後將對應的硬盤mount到相關的目錄下orm

szvphicpra16181:/opt # mount /dev/xvde1 /opt/
mount: warning: /opt/ seems to be mounted read-only.

5.經過df -h 命令能夠看到 目錄中硬盤的掛載狀況ci

szvphicpra16181:/opt # df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda2       36G   17G   19G  47% /
udev            7.8G  120K  7.8G   1% /dev
tmpfs           7.8G   72K  7.8G   1% /dev/shm
/dev/xvde1      296G  191M  281G   1% /opt

6.想要系統啓動時,自動掛載該硬盤,則須要以下操做:rem

先找到磁盤的UUID

#sudo blkid
/dev/xvda1: UUID="74be72d4-821a-4003-aabe-eead374660c4" TYPE="ext3"
/dev/xvda2: UUID="12a0fbec-7a65-425d-89cd-b0f50b191a07" TYPE="swap"
/dev/xvde: UUID="ed4b9a47-dab3-4820-9c8b-f82acb4629b1" TYPE="ext3"
/dev/mapper/docker-202:1-1345069-pool: UUID="760c5e93-e079-4f5a-8d2e-319404a7935e" TYPE="xfs"

#vi  /etc/fstab

在最後一行添加

UUID=ed4b9a47-dab3-4820-9c8b-f82acb4629b1 /opt                    ext3    defaults        1 2
相關文章
相關標籤/搜索