Add USB hard drives to Ubuntu server
I have a Ubuntu file server with limited storage space. I want to add a USB hard drive to extend its storage space. I did it in the following step.
- Plug in the USB hard drive to the Ubuntu server
After I plugged the USB hard drive, the server was rebooted. Then I check the device table to find out what is the name of the new drive. I specifically use fdisk to find more information. The following is a snap shot of fdisk output.
# fdisk -l Disk /dev/sda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x7e29f58f Device Boot Start End Blocks Id System /dev/sda1 1 19083 153284166 83 Linux /dev/sda2 19084 19457 3004155 5 Extended /dev/sda5 19084 19457 3004123+ 82 Linux swap / Solaris Disk /dev/sdc: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x93026feb Device Boot Start End Blocks Id System /dev/sdc1 1 19457 156288321 83 Linux
- Create new partitions and format them
Suppose the USB drive is /dev/sdc, you can use fdisk to repartition the drive and format the new partitions. The following is a few command for this purpose.
#fdisk /dev/sdc The number of cylinders for this disk is set to 19457. 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): p Disk /dev/sdc: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x93026feb Device Boot Start End Blocks Id System /dev/sdc1 1 19457 156288321 83 Linux 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):
You can use d to delete the old partition and n to create new partition. Use w to write the new partition table to disk once you are done. Then you can use mkfs.ext3 to create ext3 format partition.
# mkfs.ext3 /dev/sdc1
- Create entries in fstab to mount the new partition at boot time
First you have to use “blkid” or “ls /dev/disk/by-uuid” find the uuid of the new partitions.
# blkid /dev/sda1: UUID="05647485-6314-4603-aa7d-f1f2bf1a7b63" TYPE="ext3" /dev/sdc1: UUID="5eed4bd1-258f-4441-b28c-3e8d9988e656" TYPE="ext3" SEC_TYPE="ext2" /dev/sda5: TYPE="swap" UUID="efb89cfb-53e9-4202-8496-4f4b9eff6295" /dev/sdb1: UUID="5eed4bd1-258f-4441-b28c-3e8d9988e656" SEC_TYPE="ext2" TYPE="ext3"
In this example, our new partition UUID is “5eed4bd1-258f-4441-b28c-3e8d9988e656″. We can go ahead to add this to /etc/fstab.
UUID=5eed4bd1-258f-4441-b28c-3e8d9988e656 /extrastorage ext3 relatime,errors=remount-ro 0 0
Now you can run the following command to refresh your file system.
# mount -a
Check if the new USB partition is mounted and usable by "df".
root@citrice:/dev/disk# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 150877984 44458352 98755424 32% / tmpfs 1032176 0 1032176 0% /lib/init/rw varrun 1032176 844 1031332 1% /var/run varlock 1032176 0 1032176 0% /var/lock udev 1032176 2748 1029428 1% /dev tmpfs 1032176 0 1032176 0% /dev/shm lrm 1032176 2004 1030172 1% /lib/modules/2.6.27-14-generic/volatile /dev/sdc1 153834852 118941832 27078604 82% /extastorage ###### yes it is here tmpfs 1032176 2204 1029972 1% /lib/modules/2.6.27-15-generic/volatile
Now your new USB hard drive is integrated into your Ubuntu server seamlessly. You can use it as you want.
