2020年5月29日 星期五

Ubuntu - New Disk Attached

1. Login with root or sudo on user account

2. List disk with command: fdisk -l
root@ub01-VM01:/home/ub01# fdisk -l
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x64e55ca7

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 18970623 18968576    9G 83 Linux
/dev/sda2       18972670 20969471  1996802  975M  5 Extended
/dev/sda5       18972672 20969471  1996800  975M 82 Linux swap / Solaris

# New Disk /dev/sdb
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 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

3. Create partition on new disk with command: fdisk <new disk> → n→ p→ <Enter>→w
root@ub01-VM01:/home/ub01# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


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):<Enter to default>
First sector (2048-20971519, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519):

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


4. Format partition with command: mkfs -t ext3 /dev/sdb1

root@ub01-VM01:/home/ub01# mkfs -t ext3 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 2621184 4k blocks and 655360 inodes
Filesystem UUID: 2350fe29-dc99-4a86-82cc-3b391b177957
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

5. Create mount point with command: mkdir /datadk

6. Mount disk with command: mount /dev/sdb1 /datadk
ub01@ub01-VM01:~$ sudo mount /dev/sdb1 /datadk
ub01@ub01-VM01:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
udev              990892       0    990892   0% /dev
tmpfs             204132    3632    200500   2% /run
/dev/sda1        9204224 4434504   4279124  51% /
tmpfs            1020648     188   1020460   1% /dev/shm
tmpfs               5120       4      5116   1% /run/lock
tmpfs            1020648       0   1020648   0% /sys/fs/cgroup
tmpfs             204132      40    204092   1% /run/user/108
tmpfs             204132       0    204132   0% /run/user/1000
/dev/sdb1       10189112   23160   9641716   1% /datadk

7. Auto mount when boot up

a. Get uuid by command below:

    UUID by ls -lh /dev/disk/by-uuid

b. Edit /etc/fstab

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
UUID=<UUID> /data               ext4    errors=remount-ro 0       1

<file system>  Device UUID on 7.a

<mount point> Where to mount (mount to /data folder)

<type> ext4 or other type ntfs

<options> defaults

<dump> dump no=0 yes=1

<pass> self-examination no=0 yes=1