您的位置:首页 > 运维架构 > Linux

linux挂载磁盘及磁盘格式化

2016-06-06 15:05 405 查看

linux挂载磁盘及磁盘格式化

挂载好硬盘后,查看linux新磁盘的名称。

root帐号登录机器,然后使用命令fdisk -l查看。

host-1*:/home # 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: 0x000de3e1

Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048     4208639     2103296   82  Linux swap / Solaris
/dev/xvda2   *     4208640    83886079    39838720   83  Linux

Disk /dev/xvde: 1099.5 GB, 1099511627776 bytes
255 heads, 63 sectors/track, 133674 cylinders, total 2147483648 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

Disk /dev/sda: 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: 0x000de3e1

Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     4208639     2103296   82  Linux swap / Solaris
/dev/sda2   *     4208640    83886079    39838720   83  Linux


可以看到磁盘 /dev/xvde 未挂载。

接下来使用fdisk /dev/xvde 进行分区

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 选择主分区输入P

Partition number (1-4, default 1): 分区名称输入默认的1即可

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-2147483647, default 2048): 2048

再然后输入分区大小,可根据自己选择输入,我这里输入+800GB,标识是到存储800G的磁盘数, 因为是数据库机器分一个800G的。这个单位可以是K、M、G后面接上B就好了。注意不要掉了+号

First sector (2048-2147483647, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-2147483647, default 2147483647): +800GB

Command (m for help):


由于还未分完,说便宜接下来继续添加一个分区,存储空间使用剩下的那部分;

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

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4, default 3): 3
No free sectors available

Command (m for help):


然后在输入w写入磁盘即标识分区完成:

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

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


再使用fdisk -l命令可以看到这个从磁盘已经被分成了两个区。

host-1*:/home # 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: 0x000de3e1

Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048     4208639     2103296   82  Linux swap / Solaris
/dev/xvda2   *     4208640    83886079    39838720   83  Linux

Disk /dev/xvde: 1099.5 GB, 1099511627776 bytes
255 heads, 63 sectors/track, 133674 cylinders, total 2147483648 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: 0xae5c9a90

Device Boot      Start         End      Blocks   Id  System
/dev/xvde1            2048  1562502047   781250000   83  Linux
/dev/xvde2      1562502048  2147483647   292490800   83  Linux

Disk /dev/sda: 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: 0x000de3e1

Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     4208639     2103296   82  Linux swap / Solaris
/dev/sda2   *     4208640    83886079    39838720   83  Linux


接下来我们来格式化刚才的分区:(格式化可能比较慢)

mkfs -t ext3 -c /dev/xvde1 来格式化分区xvde1为ext3格式

mkfs -t ext3 -c /dev/xvde2 来格式化分区xvde1为ext3格式

格式化完成后即可挂载分区

并将挂载信息写入到自动挂载配置文件

# mkdir /opt
# mount /dev/xvde1 /opt
# mount /dev/xvde2 /home
# vi  /etc/fstab

/dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part1 swap                 swap       defaults              0 0
/dev/disk/by-id/ata-QEMU_HARDDISK_QM00001-part2 /                    ext3       acl,user_xattr        1 1
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
usbfs                /proc/bus/usb        usbfs      noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
/dev/xvde2                /home        auto      auto                0 0
/dev/xvde1                /opt        auto      auto                0 0


最后两行即为添加的自动分区挂载信息,保存即可。

挂载完后使用命令df -l即可查看磁盘使用情况。

host-1*:/opt> df -l
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       39213504 13807128  24370572  37% /
udev             4020072      140   4019932   1% /dev
tmpfs            4020072      728   4019344   1% /dev/shm
/dev/xvde2     292490800  1979336 290511464   1% /home
/dev/xvde1     781250000  2006336 779243664   1% /opt
host-1*:~/opt>


自此,即完成磁盘的分区级挂载操作。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息