LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   adding a harddrive for extra space (https://www.linuxquestions.org/questions/linux-hardware-18/adding-a-harddrive-for-extra-space-367169/)

fakie_flip 09-26-2005 09:42 AM

adding a harddrive for extra space
 
I have got another harddrive from someone. It had Win 98/95 on it, and I think I set all the numbers to 0 on it. I am using Ubuntu 5.04. How could I use this harddrive as extra space and mount it for programs installed on Ubuntu to use? It needs to be formatted as ext3 unless there is something better. Is there software for all of this? This is probably easy for most people.

debianmike 09-26-2005 10:06 AM

I wrote this doc a while ago
 
Configuring drive space on a Linux box

This document walks through creating new drive space on a Linux box using either physical drives or SAN LUN's.

Step one is to physically connect the new drive to the server. Since there are several ways of doing so, this document will assume this is already complete.

NOTE: everything that you have to type at the command line is italicized and bold for reference.

Following the general rule, all drives will show up as /dev/controller/device.
For example: /dev/cciss/c0d0 would be the first drive (d0) on the first controller (c0) on the controller labeled “cciss”.
Other examples would be:
/dev/hda, /dev/hdb for the first and second IDE drives.
/dev/sda, /dev/sdb for the first and second SCSI drives. This is where SAN LUN's appear.

NOTE: these are drive assignments, not partitions--sda refers to the entire drive. Partitions are refered to with numbers as sda1, sda2, etc.

NOTE: This document does not address permissioning of this new space.

Read each Scenario carefully as you will most likely need only one set of instructions.

Scenario 1: This will be to simply mount the entire contents of the new drive (/dev/sdb) to a mount point (/newdrive). This is also the method for mounting only a portion of the drive...simply create partitions of the correct size and mount them as follows, remembering that each partition will be labeled /dev/sdb1, sdb2, sdb3, etc., etc.

NOTE: in this scenario, we will assume our new drive is /dev/sdb.

NOTE: you can only have 4 primary partitions! You can have additional partitions but they will be extended partitions. If you create extended partitions, there is normally no partition 4, since partition 4 will contain all the extended partitions, but itself is not addressable. This partition number (4) can actually be 1,2,3 or 4, but is typically 4.

Using your favorite partitioning tool, create your partitions. Here we use fdisk:

# fdisk /dev/sdb

From the partitioning menu's, create a new partition of whatever size you need (in our case the full amount).

Change the partitions system ID from its default to 83 (a simple Linux partition).

Save and exit the fdisk utility by pressing w.

There are some situations that require a reboot for the partition table to be updated. Exiting the fdisk utility will let you know if you need to reboot.

Now we need to format the new partition. There are several ways to do this, depending on the type of file system you want (ext3, ext2, Rieser, etc). We will use the mke2fs command, using the -j option to make an ext3 file system.

# mke2fs -j /dev/sdb1 Note here we format the partition sdb1, not the drive sdb.

There are many options to the mke2fs command, but the above line is all we usually need.
Now that the partition is formatted, we can mount that to our newly created folder:

# mkdir /newdrive
# mount -t ext3 /dev/sdb1 /newdrive

To mount it at boot time, edit the /etc/fstab file as follows:

/dev/sdb1 /newdrive ext3 default 0 0

and enjoy your new space!

NOTE: Since we are not covering permissoins, you will need additional information to allow others to read/write to this space.

Scenario 2: In this scenario, we will create logical volumes out of our new drive. This will give us the flexibility to grow or shrink these volumes in the future. It will also limit any one folder from filling up the entire drive.

Again, connect your new drive as before. In this example, we will use /dev/cciss/c0d1 as our new device, and assume that it is a 72Gig drive. We will create 2 volumes for practice.

Create a partition on the new drive

# fdisk /dev/cciss/c0d1

From the partitioning menu's, create a new partition spanning the entire drive.

Change the partitions system ID from its default to 8e (a Linux LV).

Save and exit the fdisk utility by pressing w.

Now we need to create a physical volume on that partition

# pvcreate -v /dev/cciss/c0d1p1

This prepares the new partition for logical volumes.

Now we will create a volume group, that later we can add additional drives to.

NOTE: in the following example, I use vg01, assuming that vg00 is being used by the system (the OS). vg01 would be the next logical name, and is my standard, however, any name is technically acceptable.

# vgcreate vg01 -v /dev/cciss/c0d1p1

This creates vg01 and adds our new partition to it.

Type vgdisplay vg01 at the # prompt and make note of the Alloc PE / Size and Free PE / Size values.

Next we start creating logical volumes. These are similar to partitions, but offers resizing abilities since they are not tied to physical mappings on the drive.

NOTE: again, we are building a logical volume out of a piece of vg01, which we created earlier. In the example, we are creating a 20Gig volume and calling it lvsales, and will assign this to the /sales folder. We will also create a 50Gig volume for our mp3s.

# lvcreate vg01 -v -L 20G -n lvsales
# lvcreate vg01 -v -L 50G -n lvmp3s

Type vgdisplay vg01 again and compare the values to the previous output. Do you see about 70Gigs missing from the Free PE / Size entry?

Now that we have our 2 logical volumes, we need to format them as we would any new partition:

# mke2fs -j /dev/vg01/lvsales
# mke2fs -j /dev/vg01/lvmp3s

Notice the path to the new volume? /dev/volumegroupname/logicalvolumename

Create our new folders and mount our new space to them:

# mkdir /sales
# mkdir /mp3s
# mount /dev/vg01/lvsales /sales
# mount /dev/vg01/lvmp3s /mp3s

A verbose vgdisplay will give you all the info about your volume groups and logical volumes:

# vgdisplay -v vg01 (you may have to scroll up to see all the info)


Scenario 3: As is the norm, the sales department has outgrown their space, so in this example, we will add a new drive, and then grow the now existing lvsales logical volume by 20Gigs.

NOTE: This process is sometimes destructive!! Always perform quality backups prior to any changes to volumes or partition sizes!!!

Again, we add the new drives or LUN's per other documentation and boot up our server. We will assume we have added an additional 72Gig drive, as the first 72Gig drive was carved up into a sales volume and an mp3 volume and is now full. This will populate at /dev/cciss/c0d2 (NOTE the 2!)

We cannot resize a mounted partition, so we first unmount the sales folder, which will obviously take the data offline during this process. It is sometimes possible to extend these volumes without unmounting them, but that is not covered here.

# umount /sales

Now, lets walk through creating the new space:

Create a partition on the new drive

# fdisk /dev/cciss/c0d2

From the partitioning menu's, create a new partition spanning the entire drive.

Change the partitions system ID from its default to 8e (a Linux LV).

Save and exit the fdisk utility by pressing w.

Now we need to create a physical volume on that partition

# pvcreate -v /dev/cciss/c0d2p1

This prepares the new partition for logical volumes.

Here is the deviation from the previous scenario:

We need to extend the existing volume group (vg01) to include this new physical volume.

# vgextend -v vg01 /dev/cciss/c0d2p1

A vgdipslay -v vg01 command should now show a lot more Free PE / Size to it. Since we max’d out vg01 in the previous scenario, there should be around 72Gigs free since that is the size of the space we just added.

We now need to stretch our filesystem over our new space:

(we are sometimes forced to check out the filesystem first. Do so with:
# e2fsck –f /dev/vg01/lvsales)

Now that our vg01 contains more formated free space, let’s extend the lvsales volume by another 20Gigs.

# lvextend -v -L +20G /dev/vg01/lvsales

Now that the logical volume has been extended, we need to stretch filesystem (or format) across the new space:

# resize2fs /dev/vg01/lvsales

The above command has some options to it, however, with non indicated, resize2fs assume’s the entire space.

A quick vgdisplay –v command will show you the new space assigned to lvsales.

# mount -a will remount all the file systems in the /etc/fstab, including our /sales folder.

# df -h will list all the directory size's and free space. Our sales folder should now be 40Gigs in size and have 20Gigs free.

# vgdisplay –v vg01 should also report 20Gigs missing out of vg01, leaving around 50Gigs available (or Free).

fakie_flip 09-30-2005 07:45 PM

I have the second harddrive plugged into the same cable as the first one, so it is a primary slave. It looks like fdisk found it but the mke2fs -j /dev/hdb1 did not. What did I do wrong? I was following the directions from the first scenario.

Code:

chris@ubuntu:/usr/lib/mozilla-firefox$ sudo fdisk /dev/hdb

The number of cylinders for this disk is set to 1654.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): help
h: unknown command
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): d
No partition is defined yet!

Command (m for help): t
No partition is defined yet!

Command (m for help): n
Command action
  e  extended
  p  primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1-1654, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1654, default 1654):
Using default value 1654

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): t
Selected partition 2
Hex code (type L to list codes): L

 0  Empty          1e  Hidden W95 FAT1 80  Old Minix      be  Solaris boot
 1  FAT12          24  NEC DOS        81  Minix / old Lin bf  Solaris
 2  XENIX root      39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 3  XENIX usr      3c  PartitionMagic  83  Linux          c4  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286    84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 5  Extended        41  PPC PReP Boot  85  Linux extended  c7  Syrinx
 6  FAT16          42  SFS            86  NTFS volume set da  Non-FS data
 7  HPFS/NTFS      4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 8  AIX            4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM      df  BootIt
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e1  DOS access
 b  W95 FAT32      51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          e4  SpeedStor
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD        ee  EFI GPT
10  OPUS            55  EZ-Drive        a6  OpenBSD        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk    a8  Darwin UFS      f1  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor      a9  NetBSD          f4  SpeedStor
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot    f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs        fd  Linux raid auto
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap      fe  LANstep
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid ff  BBT
1c  Hidden W95 FAT3 75  PC/IX
Hex code (type L to list codes): 83

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
chris@ubuntu:/usr/lib/mozilla-firefox$
chris@ubuntu:/usr/lib/mozilla-firefox$ mke2fs -j /dev/hdb1
mke2fs 1.35 (28-Feb-2004)
Could not stat /dev/hdb1 --- No such file or directory

The device apparently does not exist; did you specify it correctly?
chris@ubuntu:/usr/lib/mozilla-firefox$ sudo mke2fs -j /dev/hdb1
mke2fs 1.35 (28-Feb-2004)
Could not stat /dev/hdb1 --- No such file or directory

The device apparently does not exist; did you specify it correctly?
chris@ubuntu:/usr/lib/mozilla-firefox$


WhatsHisName 09-30-2005 11:25 PM

You created hdb2, not hdb1. To see the partition using fdisk, run:

fdisk -l

The command to make ext3 would be:

mke2fs -j /dev/hdb2

debianmike 10-01-2005 10:41 AM

yes, Whatshisname is correct. You created a second primary partition on the drive when you gave it a partition number of 2, not 1.

You can have primary partitions on 2 different drives. The partition tables for each drive are independant of each other. I suspect you assumed that the original drive would be the primary partition...this is incorrect.

fakie_flip 10-02-2005 08:39 PM

I did not know what I was doing. I thought since this is the second primary partition I will have, it needs to be 2. I understand now what I did wrong. First I mounted it to /home/chris/ then my computer had serious problems, and I had to reboot. Then I made a folder called space and mounted the new partition to it /home/chris/space, and that worked. It has a locked, so I need root for it. What is the chmod option to give everyone permissions to it?


All times are GMT -5. The time now is 11:11 AM.