VPS挂载未使用硬盘教程方法把未被使用的硬盘并入。

命令检查当前硬盘使用情况

运行命令

fdisk ­-l

结果如下:

    Disk /dev/sdb: 26.8 GB, 26843545600 bytes(未被使用的空间)
    255 heads, 63 sectors/track, 3263 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/sda: 10.7 GB, 10737418240 bytes(已经是被使用的空间)
    255 heads, 63 sectors/track, 1305 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000229dd
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        1306     9972736   8e  Linux LVM
    
    Disk /dev/mapper/vg_cloud-lv_root: 9135 MB, 9135194112 bytes
    255 heads, 63 sectors/track, 1110 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    
    
    Disk /dev/mapper/vg_cloud-lv_swap: 1073 MB, 1073741824 bytes
    255 heads, 63 sectors/track, 130 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000

查看已经使用情况

    df ­-hal

    [root@cloud /]# df -hal
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_cloud-lv_root
                          8.3G  2.2G  5.7G  28% /
    proc                     0     0     0    - /proc
    sysfs                    0     0     0    - /sys
    devpts                   0     0     0    - /dev/pts
    tmpfs                 495M     0  495M   0% /dev/shm
    /dev/sda1             477M   28M  424M   7% /boot
    none                     0     0     0    - /proc/sys/fs/binfmt_misc

增加分区

查找我们要的硬盘信息 接下来就是进行分区并挂着

    fdisk /dev/sdb

通过上述的命令进行新增加分区,然后看下图或者按照下面的命令进行操作(//为解释)

  • n //新建分区
  • p //主分区
  • 4 //第4个分区,根据实际分区数,如已有2个分区,然后我们这里就输入3
  • 回车 //回车默认
  • 回车 //默认
  • t //指定分区格式
  • 8e //分区格式为LVM
  • w //保存
  • reboot //重启VPS

以下是操作记录

[root@cloud /]# fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x5a6379c9.
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)
    
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
    
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-3263, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-3263, default 3263): 
Using default value 3263
    
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
    
Command (m for help): w
The partition table has been altered!
    
Calling ioctl() to re-read partition table.
Syncing disks.

重启之后,我们检查看看硬盘分区情况

[root@cloud ~]# fdisk -l
    
Disk /dev/sdb: 26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5a6379c9
(刚才操作的)
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        3263    26210016   8e  Linux LVM
    
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000229dd
    
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1306     9972736   8e  Linux LVM
    
Disk /dev/mapper/vg_cloud-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
    
    
Disk /dev/mapper/vg_cloud-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

格式化 自动挂载

[root@cloud ~]# mkfs.ext3 /dev/sdb1  (格式化)
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1638400 inodes, 6552504 blocks
327625 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
200 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
    
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
    
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@cloud ~]# mount /dev/sdb1 /data (手动挂载)

[root@cloud ~]# df -hal  (查看使用情况)
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloud-lv_root
                      8.3G  2.2G  5.7G  28% /
proc                     0     0     0    - /proc
sysfs                    0     0     0    - /sys
devpts                   0     0     0    - /dev/pts
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1             477M   28M  424M   7% /boot
none                     0     0     0    - /proc/sys/fs/binfmt_misc
/dev/sdb1              25G  173M   24G   1% /data  (手动挂载)
[root@cloud ~]# umount /dev/sdb1 (卸载)
[root@cloud ~]# vim /etc/fstab 
在文件后面添加
/dev/sdb1 /data                 ext3    defaults        1 2

[root@cloud ~]# mount -a  (读取fstab自动挂载哈哈)
[root@cloud ~]# df -hal
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cloud-lv_root
                      8.3G  2.2G  5.7G  28% /
proc                     0     0     0    - /proc
sysfs                    0     0     0    - /sys
devpts                   0     0     0    - /dev/pts
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1             477M   28M  424M   7% /boot
none                     0     0     0    - /proc/sys/fs/binfmt_misc
/dev/sdb1              25G  173M   24G   1% /data(我又出来了)

请联系我 商务合作、广告投放、题目勘误、侵权投诉

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部