虛擬機器Linux下擴充硬碟的方法__Linux

來源:互聯網
上載者:User

【原文連結】:http://blog.csdn.net/tianlesoftware/article/details/5642883

裝虛擬機器時空間劃小了,於是又加了5G的空間,折騰了半天,掛上去了。整理下弄個筆記,備用。

 

 

1. 添加磁碟,查看磁碟狀況

    

[root@db1 /]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *         151        1305     9277537+  83  Linux

/dev/sda2               1         150     1204843+  82  Linux swap

Partition table entries are not in disk order

Disk /dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

 

從查詢結果看出,多了一個/dev/sdb的盤

 

2. 用fdisk 對/dev/sdb 進行分區

 

[root@db1 /]# fdisk /dev/sdb

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-652, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-652, default 652):

Using default value 652

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

再次查看分區情況,多出來一個/dev/sdb1 的區,這個1是我們在前面指定的,如果我們指定2,就變成 sdb2了。

 

[root@db1 /]# fdisk -l

 

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *         151        1305     9277537+  83  Linux

/dev/sda2               1         150     1204843+  82  Linux swap

Partition table entries are not in disk order

 

Disk /dev/sdb: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         652     5237158+  83  Linux

[root@db1 /]#

 

如果建立完之後,/proc/partitions 查看不到對應的分區,使用parprobe 命令重新整理一下就可以了:

[root@web1 ~]# cat /proc/partitions 
major minor  #blocks  name


   8     0  175825944 sda
   8     1    1020096 sda1
   8     2   30716280 sda2
   8     3    8193150 sda3
[root@web1 ~]# partprobe /dev/sda
[root@web1 ~]# cat /proc/partitions 
major minor  #blocks  name


   8     0  175825944 sda
   8     1    1020096 sda1
   8     2   30716280 sda2
   8     3    8193150 sda3
   8     4  135893835 sda4
[root@web1 ~]# 



 

3. 格式化 /dev/sdb1 分區

 

[root@db1 /]# mkfs -t ext3 /dev/sdb1

mke2fs 1.35 (28-Feb-2004)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

655360 inodes, 1309289 blocks

65464 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=1342177280

40 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912, 819200, 884736

 

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

4. 建立目錄 並將 /dev/sdb1 掛在到該目錄下

 

[root@db1 /]# ls

backup  dev   initrd      media  opt   sbin     sys       usr

bin     etc   lib         misc   proc  selinux  tftpboot  var

boot    home  lost+found  mnt    root  srv      tmp

[root@db1 /]# mkdir /u01

[root@db1 /]# ls

backup  dev   initrd      media  opt   sbin     sys       u01

bin     etc   lib         misc   proc  selinux  tftpboot  usr

boot    home  lost+found  mnt    root  srv      tmp       var

[root@db1 /]# mount /dev/sdb1 /u01

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.