2015年12月10日 星期四

Ubuntu 14.10 如何新增硬碟

PS 現在的Ubuntu的帳號有權限限制,需要加sudo才可以順利執行,據說是為了安全性考量...既然要加,就給他加一下唄
例如關機也要加sudo...

example@a07ubuntu:~$ sudo poweroff

正文開始:

先用df -h看一下系統硬碟,目前新增的硬碟是看不到的,輸入df -h

example@a07ubuntu:~$ df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/a07ubuntu--vg-root   47G  905M   44G   2% /
none                            4.0K     0  4.0K   0% /sys/fs/cgroup
udev                            987M  4.0K  987M   1% /dev
tmpfs                           200M  324K  200M   1% /run
none                            5.0M     0  5.0M   0% /run/lock
none                            998M     0  998M   0% /run/shm
none                            100M     0  100M   0% /run/user
/dev/xvda1                      236M   39M  186M  18% /boot
example@a07ubuntu:~$

然後看一下/dev,輸入ls /dev/[sh]d*

ls /dev/[sh]d*

因為此處用的是XenServer環境,所以下的指令如下,可以看到多了xvdb (接下來皆以xvdb為範例)

example@a07ubuntu:~$ ls /dev/xvd*
/dev/xvda  /dev/xvda1  /dev/xvda2  /dev/xvda5  /dev/xvdb

再用fdisk確認沒有磁碟分割表的訊息,輸入sudo fdisk -l /dev/xvdb

example@a07ubuntu:~$ sudo fdisk -l /dev/xvdb
[sudo] password for example:
Disk /dev/xvdb: 20 GiB, 21474836480 bytes, 41943040 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

直接新增分割磁區,輸入sudo fdisk /dev/xvdb
n : 新增partition
p : 選擇primary
1 : 選擇partition代號
First cylinder : 使用預設值,直接按Enter
Last cylinder : 使用預設值,直接按Enter
w : 儲存結果

example@a07ubuntu:~$ sudo fdisk /dev/xvdb
Welcome to fdisk (util-linux 2.25.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x40c61974.
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): <<直接Enter>>
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): <<直接Enter>>
Created a new partition 1 of type 'Linux' and of size 20 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

用mkfs格式化硬碟,輸入sudo mkfs -t ext4 /dev/xvdb

example@a07ubuntu:~$ sudo mkfs -t ext4 /dev/xvdb
mke2fs 1.42.10 (18-May-2014)
/dev/xvdb contains a ext4 file system
        created on Fri Dec 11 14:41:55 2015
Proceed anyway? (y,n) y
Creating filesystem with 5242880 4k blocks and 1310720 inodes
Filesystem UUID: d70e9575-adea-4d63-8031-1f4cae954b89
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

找新硬碟的UUID,輸入sudo blkid,新硬碟的UUID應該就是如紅色標示

example@a07ubuntu:~$ sudo blkid
/dev/xvda1: UUID="408015d8-1b6d-49e9-829c-72b4179c39bd" TYPE="ext2" PARTUUID="37d5d4c5-01"
/dev/xvda5: UUID="Zxb2DP-WOna-xsPH-zfDB-HbYK-KP3C-zc01d9" TYPE="LVM2_member" PARTUUID="37d5d4c5-05"
/dev/mapper/a07ubuntu--vg-root: UUID="a338245f-8233-4ae9-bed3-0facf58861cf" TYPE="ext4"
/dev/mapper/a07ubuntu--vg-swap_1: UUID="2aa895ad-1200-42ee-bcbb-a2c8f36c250a" TYPE="swap"

把新硬碟寫到/etc/fstab,輸入sudo vi /etc/fstab,新增紅色那行,:wq儲存編輯

example@a07ubuntu:~$ sudo vi /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/a07ubuntu--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/xvda1 during installation
UUID=408015d8-1b6d-49e9-829c-72b4179c39bd /boot           ext2    defaults        0       2
/dev/mapper/a07ubuntu--vg-swap_1 none            swap    sw              0       0
UUID=a338245f-8233-4ae9-bed3-0facf58861cf /data2 ext4 defaults 0 2

然後重開機就大功告成了!!

example@a07ubuntu:~$ sudo reboot


你可能會想看:
如何開啟Ubuntu的root帳號
如何開啟Ubuntu的root ssh連線?


參考資料:
替 Linux 新增硬碟


如有侵權請來信告知,謝謝。

沒有留言:

張貼留言