You are using linux on virtual machine (e.g VMWARE) or real PC. I will show you the way how to add new hard disk in ubuntu
Check new device:
1 2 |
thanhson1085@sonnst:~$ ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb |
/dev/sdb is new hard disk that you needed. In case, you do not see new devive, it means that the OS system does know about new device. So you should reboot your system, If still not, you need install driver software for new device (read device specification and download drivers from device provider)
Start with command:
1 |
fdisk /dev/sdb |
Follow the guide to add a new partition
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x2a749bbb. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): p Disk /dev/sdc: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 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 Disk identifier: 0x2a749bbb Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. |
And build Linux file sytem in new hard disk (I chose ext4)
1 |
mkfs -t ext4 /dev/sdb1 |
And try to mount new hard disk to directory
1 2 |
mkdir /var/data mount /dev/sdb1 /var/data |
Test with df command
1 2 3 4 5 6 7 8 9 10 11 |
thanhson1085@sonnst:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/sonnst--vg-root 39G 32G 4.7G 87% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 483M 4.0K 483M 1% /dev tmpfs 99M 676K 99M 1% /run none 5.0M 0 5.0M 0% /run/lock none 494M 0 494M 0% /run/shm none 100M 0 100M 0% /run/user /dev/sda1 236M 37M 188M 17% /boot /dev/sdb1 40G 4.7G 33G 13% /var/data |
Finally, add the mount to fstab to automatically mount disk when system start.
1 |
sudo vi /etc/fstab |
Add line:
1 |
/dev/sdb1 /var/data ext4 rw,user,auto,exec 0 0 |
To apply the new change of fstab file. We use command:
1 |
mount -a |
In case the automation fails, you can troubleshoot with command:
1 2 |
sudo vi /var/log/syslog sudo dmesg|grep mount |
A error case:
1 2 3 4 5 6 |
thanhson1085@sonnst:~$ sudo dmesg | grep mount 1531:[ 2.587995] EXT4-fs (dm-0): mounted filesystem with ordered data mode. Opts: (null) 1542:[ 10.259551] EXT4-fs (dm-0): re-mounted. Opts: errors=remount-ro 1556:[ 10.503269] EXT4-fs (sda1): mounting ext2 file system using the ext4 subsystem 1557:[ 10.547261] EXT4-fs (sda1): mounted filesystem without journal. Opts: (null) 1558:[ 10.553733] EXT4-fs (sdb4): Unrecognized mount option "utf8" or missing value |