Page 1 of 1

Attach new HDD to Ubuntu server

Posted: Wednesday, 30.10.2013 18:31
by geohei
Check if new disk is recognized by Ubuntu.

Code: Select all

root@callisto:~# lshw -C disk
...
  *-disk:1
       description: ATA Disk
       product: WDC WD4000F9YZ-0
       vendor: Western Digital
       physical id: 1
       bus info: scsi@3:0.0.0
       logical name: /dev/sdb
       version: 01.0
       serial: xx-xxxxxxxxxxxx
       size: 3726GiB (4TB)
       configuration: ansiversion=5
       bus info: scsi@6:0.0.0
...
Partition drive using gdisk (1 single partition, GPT). Be sure to get the correct device (sdb in this case).

Code: Select all

root@callisto:~# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.1

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): ?
b       back up GPT data to a file
c       change a partition's name
d       delete a partition
i       show detailed information on a partition
l       list known partition types
n       add a new partition
o       create a new empty GUID partition table (GPT)
p       print the partition table
q       quit without saving changes
r       recovery and transformation options (experts only)
s       sort partitions
t       change a partition's type code
v       verify disk
w       write table to disk and exit
x       extra functionality (experts only)
?       print this menu

Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-7814037134, default = 34) or {+-}size{KMGTP}:
Information: Moved requested sector from 34 to 2048 in
order to align on 2048-sector boundaries.
Use 'l' on the experts' menu to adjust alignment
Last sector (2048-7814037134, default = 7814037134) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT).
The operation has completed successfully.
root@callisto:~# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): p
Disk /dev/sdb: 7814037168 sectors, 3.6 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): C5E507F9-E043-4D8E-B1D8-2A7E68EA97D2
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 7814037134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048      7814037134   3.6 TiB     8300  Linux filesystem

Command (? for help): q
Format partition using ext4.

Code: Select all

root@callisto:~# mkfs -t ext4 /dev/sdb1
mke2fs 1.42 (29-Nov-2011)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
244195328 inodes, 976754385 blocks
48837719 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
29809 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Create mountpoint and mount partition. Be aware that this mount will be lost after reboot.

Code: Select all

root@callisto:~# mkdir /media/four_tera
root@callisto:~# mount /dev/sdb1 /media/four_tera
Use /etc/fstab to permanently mount subject partition.

Code: Select all

root@callisto:~# blkid
...
/dev/sdb1: UUID="f4d3ff2e-7d12-4edd-ad15-e029f1aefe97" TYPE="ext4"
...
root@callisto:~# cat /etc/fstab
# added by geohei
UUID="f4d3ff2e-7d12-4edd-ad15-e029f1aefe97"     /media/four_tera    ext4    defaults        0       0
...
If desired, the privileged space can be reduced from 5% (default) to a lower amount. This is only advisable for pure data partitions (as opposed to system partitions). It also works on partitions containing already data. 'df -h' provided before and after ' tune2fs -m 1 /dev/sdb1' for informational purpose.

Code: Select all

root@callisto:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        92G  2.7G   85G   3% /
udev            3.7G  8.0K  3.7G   1% /dev
tmpfs           1.5G  560K  1.5G   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            3.7G     0  3.7G   0% /run/shm
/dev/sdb1       3.6T  196M  3.4T   1% /media/four_tera
root@callisto:~# tune2fs -m 1 /dev/sdb1
tune2fs 1.42 (29-Nov-2011)
Setting reserved blocks percentage to 1% (9767543 blocks)
root@callisto:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        92G  2.7G   85G   3% /
udev            3.7G  8.0K  3.7G   1% /dev
tmpfs           1.5G  560K  1.5G   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            3.7G     0  3.7G   0% /run/shm
/dev/sdb1       3.6T  196M  3.6T   1% /media/four_tera
References:
https://help.ubuntu.com/community/Insta ... wHardDrive