After attaching the hard disk of 20GB capacity, the fdisk -l will give the below output.
New disk added is shown as /dev/xvdc . If we are adding physical disk it will show as /dev/sda based of the disk type. Here I used a virtual disk.
To partition a particular hard disk, for example /dev/xvdc.
Commonly used fdisk commands.
Here since we are creating a partition use n option.
Create either primary/extended partitions. By default we can have upto 4 primary partitions.
Give the partition number as desired. Recommended to go for the default value 1 .
Give the value of the first sector. If it is a new disk, always select default value. If you are creating a second partition on the same disk, we need to add 1 to the last sector of the previous partition.
Give the value of the last sector or the partition size. Always recommended to give the size of the partition. Always prefix + to avoid value out of range error.
Save the changes and exit.
Now format the disk with mkfs command.
Once formatting has been completed, now mount the partition as shown below.
Make an entry in /etc/fstab file for permanent mount at boot time.
/dev/xvdc1 /data ext4 defaults 0 0
Now you know how to partition a raw disk using fdisk command and mount the same.
We need to be extra cautious while working with the partitions especially when you are editing the configured disks. Please share your feedback and suggestions.
Добавление жесткого диска в Linux — операция достаточно легкая, хотя и кажется на первый взгляд достаточно тяжелой. Ниже предоставлена подробная инструкция того, как добавить жесткий диск в операционных системах семейства Linux.
Все действия проводились на компьютере под управлением операционной системы Debian 8.4, однако они должны подойти и к другим дистрибьютивам Linux.
Начнем с того, что найдем под каким именем скрывается жесткий диск в системе. Для этого используем команду ls:
/dev/sda /dev/sda2 /dev/sdb1 /dev/sdc /dev/sda1 /dev/sdb /dev/sdb2 /dev/sdd
Для понимания стоит отметить, что /dev/sda /dev/sdb/ и т. д. (без цифр) — это сами жесткие диски, а вот /dev/sda1, /dev/sda2 — это разделы на жестких дисках.
Если жесткий диск новый, то на нем не должно быть никакой файловой системы. Нам остается лишь получить информацию по этому жесткому диску с помощью утилиты fdisk. Вводим:
Disk /dev/sdc: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Убедившись в том, что это нужный диск, приступаем. Для начала нужно будет создать новый раздел, для этого опять используем программу fdisk:
Welcome to fdisk (util-linux 2.25.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help):
Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)
Если планируется создавать один раздел, или больше (но не более четырех), то выбираем пункт p. У Partition number, First sector и Last sector оставляем все по умолчанию и просто нажимаем Enter. Если все прошло успешно, то появится сообщение примерно следующего содержания:
Created a new partition 1 of type 'Linux' and of size 931.5 GiB.
Теперь нужно сохранить эти изменения — вводим команду w, которая укажет программе fdisk о необходимости выйти, предварительно записав изменения на диск. Если же что-то было сделано не так, то можно выйти без изменений введя команду q. Далее нужно создать файловую систему на жестком диске. Пусть это будет ext4:
Так же может оказаться, что диск уже до этого использовался, и там вполне может быть уже существующая файловая система. В таком случае при форматировании раздела появится следующее сообщение:
/dev/sdc1 contains a ntfs file system Proceed anyway? (y,n)
Если на жестком диске нет никаких нужных данных, и не планируется использование файловой системы NTFS, то нужно ответить y. Осталось смонтировать (добавить) раздел в систему. Допустим это будет папка backup, расположенная в корне. Создаем папку:
/dev/sdc1: UUID="360ca23a-300t-asdd-8c8e-a3xdf46dlpf1" TYPE="ext4"
Находим нужный, и запоминаем его UUID. Теперь открываем /etc/fstab, и добавляем туда следующую строчку:
UUID=360ca23a-300t-asdd-8c8e-a3xdf46dlpf1 /backup ext4 errors=remount-ro 0 1
echo "UUID=360ca23a-300t-asdd-8c8e-a3xdf46dlpf1 /backup ext4 errors=remount-ro 0 1" | sudo tee -a /etc/fstab
Этим мы объясняем системе, что при загрузке следует смонтировать раздел с определенным UUID как папку /backup и файловой системой ext4.
Проверить правильность предыдущих действий можно с помощью команды:
Если никаких ошибок не выявлено, значит все было сделано правильно. Для того, чтобы примонтировать раздел прямо сейчас, можно выполнить следующую команду:
sudo mount -t ext4 /dev/sdc1 /backup
I am going to put an additional (non-USB) hard drive in my system. I already have Ubuntu on my other hard drive so I do not want to install Ubuntu on the additional drive but only use it for storage. How do I add the additional hard drive to my Ubuntu system, e.g. make Ubuntu recognize it and mount it properly?
I thought it would make sense to have a general question for this issue. I tried to find one and asked in chat for one without success. Hint: help.ubuntu.com/community/InstallingANewHardDrive
Good idea! Wish I’d found it before I answered this: askubuntu.com/questions/488213/…. Perhaps they could be merged.
The easiest and user-friendly way is probably to use gparted after you have installed your new HDD and boot your machine:
Then you create partitions, by setting their size and type.
gparted is a very easy to use tool, and yet very advanced.
After you are done creating your partitions (most likely it will be just one ext4 data partition, since this is your additional storage drive), you need to permanently mount it.
At this step you already know what names your new partition(-s) have. If not sure, following command will remind you about existing drives and partitions on them:
This will output something like this (intentionally skipped /dev/sda system drive info):
Disk /dev/sda: 250.1 GB, 250059350016 bytes . Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes 255 heads, 63 sectors/track, 243201 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk identifier: 0x000814e3 Device Boot Start End Blocks Id Syste /dev/sdb1 1 243201 1953512001 83 Linux
Output states, that your new partition is /dev/sdb1 . Now you need to mount it to utilize it’s precious space. To achieve this, you need to perform three simple steps:
Open /etc/fstab file with root permissions:
And add following to the end of the file:
/dev/sdb1 /hdd ext4 defaults 0 0