Linux VPS新硬盤分區與掛載教程

經過fdisk -l咱們能夠看到/dev/xvdb(此名稱因系統而異)容量有23.6G,並且沒有分區,接下來咱們對它進行分區和掛載,(按照以下方式掛載,重裝系統不丟失掛載分區硬盤的數據)node

注: 掛載硬盤過程請按照下面代碼「藍色」標記複製執行既可,不一樣Linux系統,只需途徑名稱修改對應系統名稱。app

  1. fdisk -l ide


[root@MyVPS ~]# fdisk -l
Disk /dev/xvda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          13      104391   83  Linux
/dev/xvda2              14        1044     8281507+  8e  Linux LVM

Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
255 heads, 63 sectors/track, 2871 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot      Start         End      Blocks   Id  System



對/dev/xvdb(此名稱因系統而異)進行分區:
this

  1. fdisk /dev/xvdb spa


[root@MyVPS ~]# fdisk /dev/xvdb
The number of cylinders for this disk is set to 2871.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

輸入n新建分區
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p

/dev/xvdb中第1個分區
Partition number (1-4): 1  (輸入1後請連續按回車鍵 Enter/2次)
First cylinder (1-2871, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2871, default 2871):
Using default value 2871

輸入W保存退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.



將新分區xvdb1(此名稱因系統而異)格式化爲ext3格式orm

  1. mkfs -t ext3 /dev/xvdb1 ip


[root@MyVPS ~]# mkfs -t ext3 /dev/xvdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2883584 inodes, 5765319 blocks
288265 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
176 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, 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 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.



咱們示範將新分區xvdb1掛載到目錄/home1
新建目錄/home1,而後掛載
ci

  1. mkdir /home1 rpc

  2. mount /dev/xvdb1 /home1 it



完成後咱們經過df -hal能夠看到,新分區已經掛載到目錄/home1上了


[root@MyVPS ~]# df -hal
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      5.7G  1.4G  4.1G  25% /
proc                     0     0     0   -  /proc
sysfs                    0     0     0   -  /sys
devpts                   0     0     0   -  /dev/pts
/dev/xvda1             99M   28M   67M  30% /boot
tmpfs                 256M     0  256M   0% /dev/shm
none                     0     0     0   -  /proc/sys/fs/binfmt_misc
sunrpc                   0     0     0   -  /var/lib/nfs/rpc_pipefs
/dev/xvdb1             22G  173M   21G   1% /home1



最後添加開機自動掛載:

  1. echo "/dev/xvdb1 /home1 ext3 defaults 1 2" >> /etc/fstab

相關文章
相關標籤/搜索