例如關機也要加sudo...
example@a07ubuntu:~$ sudo poweroff
正文開始:
先用df -h看一下系統硬碟,目前新增的硬碟是看不到的,輸入df -hexample@a07ubuntu:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/a07ubuntu--vg-root 47G 905M 44G 2% /none 4.0K 0 4.0K 0% /sys/fs/cgroupudev 987M 4.0K 987M 1% /devtmpfs 200M 324K 200M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 998M 0 998M 0% /run/shmnone 100M 0 100M 0% /run/user/dev/xvda1 236M 39M 186M 18% /bootexample@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 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/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/xvdbWelcome 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): nPartition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions)Select (default p): pPartition number (1-4, default 1): 1First 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): wThe 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/xvdbmke2fs 1.42.10 (18-May-2014)/dev/xvdb contains a ext4 file systemcreated on Fri Dec 11 14:41:55 2015Proceed anyway? (y,n) yCreating filesystem with 5242880 4k blocks and 1310720 inodesFilesystem UUID: d70e9575-adea-4d63-8031-1f4cae954b89Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting 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 新增硬碟
如有侵權請來信告知,謝謝。
沒有留言:
張貼留言