Hard Disk Prep From Shell

 
Thread Tools Search this Thread
Operating Systems Linux Fedora Hard Disk Prep From Shell
# 1  
Old 03-23-2012
CPU & Memory Hard Disk Prep From Shell

Hi there. I am a MS experienced admin who has recently been charged with crossing over into the Unix/Linux realms. Years of working with the GUI and DOS have left me somewhat hobbled as I make the transition and try to sift through the mountains of partial information available Smilie... which leads me to my question at hand.

I am working with Fedora 16. My goal is to achieve the following (not necessarily in the order listed) from the shell. The stuff I have already figured out will have notes after that particular action.
  • attach/mount <?> a disk - this seems to be automatic in Fedora... what if I am on an older machine that does not do this automatically?
  • format said disk - easily done from the disk manager GUI but I need to know it from the shell in the event I am on an older machine.
  • label said disk - easily done from the disk manager GUI but I need to know it from the shell in the event I am on an older machine.
  • partition said disk - so far I can do what I need here with fdisk
  • encrypt said disk - easily done from the disk manager GUI but I need to know it from the shell in the event I am on an older machine.
I am grateful for any assistance as I venture into this new world.
# 2  
Old 03-23-2012
Probably best to explain how disks actually work in UNIX first.

You don't get drive letters in UNIX, drives become special files under /dev/. If you had a disk with three partitions in it, you would get something like

/dev/sda -- the raw disk itself, with the contents of all three partitions. This is the device you use when editing partitions.
/dev/sda1,2,3 -- The partitions inside /dev/sda. These are the things you format and mount.

To partition a disk in Linux, you'd probably prefer the commandline parted tool since it's common, supports several partition types, can do things like moving and resizing of partitions, and has a somewhat verbose built-in help. If you don't have it, you can try fdisk on systems with old-fashioned boot labels, but its abilities are more limited, and you must read its options carefully.

When you mount a disk, it doesn't become a drive letter, it takes over a folder, typically an empty folder. Say you had a folder /mnt/disk inside your root partition, you could do mount /dev/sda1 /mnt/disk to have its contents made available inside /mnt/disk. The root partition itself is mounted by the kernel on boot, because it has to start somewhere. You unmount partitions with umount /dev/sda1 or umount /path/to/folder, but can't do that to a partition that's in use.

Automounting of non-removable disks is typically done through /etc/fstab, a text file containing a list of partitions and where they belong. When the system boots, it will attempt to mount anything in this list lacking the 'noauto' option. If any fail to mount, this is considered a severe error. Here's a fstab from one of my systems:
Code:
# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed; notail increases performance of ReiserFS (at the expense of storage
# efficiency).  It's safe to drop the noatime options if you want and to
# switch between notail / tail freely.
#
# The root filesystem should have a pass number of either 0 or 1.
# All other filesystems should have a pass number of 0 or greater than 1.
#
# See the manpage fstab(5) for more information.
#

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

/dev/sda1              /boot           ext2            noauto,noatime  1 2
/dev/sda3              /               ext3            noatime         0 1
/dev/sda2              none            swap            sw              0 0
/dev/sda5              /home           ext3            noatime         0 1
/dev/sda6              /usr            ext3            noatime         0 1
/dev/sda7              /var            ext3            noatime         0 1
/dev/sda8              /var/tmp        xfs             noatime         0 1
/dev/cdrom2            /mnt/cdrom      udf,iso9660     noauto,ro,user  0 0
/dev/sdb4              /opt            xfs             noatime         0 0

# glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
# POSIX shared memory (shm_open, shm_unlink).
# (tmpfs is a dynamically expandable/shrinkable ramdisk, and will
#  use almost no memory if not populated with files)
shm                     /dev/shm        tmpfs           nodev,nosuid,noexec    0 0

Once you've partitioned a disk, you format it with the mkfs command. There's actually many different mkfs commands, since there's many different partition types, but they have a lot in common and can be mostly used the same way. For example:

Code:
mkfs.ext4 -L volume-label /dev/sda1

would reformat /dev/sda1 with the ext4 filesystem. Other common Linux filesystems include ext3 and reiserfs.

Encrypting a disk isn't something I've tried personally. There seem to be quite a lot of steps involved, it's not a single command.

Last edited by Corona688; 03-23-2012 at 01:46 PM..
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-23-2012
Thank you for your prompt response.

Quote:
Originally Posted by Corona688
Probably best to explain how disks actually work in UNIX first.

You don't get drive letters in UNIX, drives become special files under /dev/. If you had a disk with three partitions in it, you would get something like

/dev/sda -- the raw disk itself, with the contents of all three partitions. This is the device you use when editing partitions.
/dev/sda1,2,3 -- The partitions inside /dev/sda. These are the things you format and mount.

*snip*
To make sure I am understanding this correctly, I won't have to configure it to recognize that the disk is plugged in, rather it's a plug and play proposition?
# 4  
Old 03-23-2012
The linux operating system automatically recognizes when disks are attached*, including USB disks and the like, and the corresponding devices under /dev/ ought to appear automatically too. But the only disk Linux automatically mounts is the root partition, right when it boots. From there on out, the kernel only ever mounts the disks it's told to mount.

So, automounting hotplugged drives is something done by application software, not Linux itself. The GNOME window manager tries to automount external disks for instance. Other times, the pmount suite is used to automount, and can also decide who's allowed to automount what.

And quite a few systems don't automount at all. Automount is useful for plugging in flash drives, but there are many situations you do not want disks to be automounted. A system with a software RAID for instance -- you want the RAID to control the disks itself, instead of them being grabbed by the automounter. Or a secure server, which would have no business mounting a strange drive unasked. Or a system being used for data-recovery on a spotty drive which is simply unable to be mounted. And so forth.

* The hardware has to support it of course. Any modern SATA port is technically supposed to be hotswap, but the feature isn't always implemented properly.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Migrate a Hard Disk

hi Has anyone already tried to migrate a hard disk with FreeBSD using recoverdisk? (1 Reply)
Discussion started by: ccc
1 Replies

2. Linux

C++ Code to Access Linux Hard Disk Sectors (with a LoopBack Virtual Hard Disk)

Hi all, I'm kind of new to programming in Linux & c/c++. I'm currently writing a FileManager using Ubuntu Linux(10.10) for Learning Purposes. I've got started on this project by creating a loopback device to be used as my virtual hard disk. After creating the loop back hard disk and mounting it... (23 Replies)
Discussion started by: shen747
23 Replies

3. SCO

declare disk driver for IDE hard disk

hi I've a fresh installation of SCO 5.0.7 on the IDE hard disk. For SCSI hard disk I can declare, for example blc disk driver using: # mkdev hd 0 SCSI-0 0 blc 0but it works for IDE hard disk? (3 Replies)
Discussion started by: ccc
3 Replies

4. UNIX for Dummies Questions & Answers

Hard Disk at 99% Help!

:eek: I use this Solaris to run CMS a call acounting software package for my job. No one could run reports today because it said the this when you logged on "The following file systems are low, and could adversely affect server performance: File system /: 99%full" Can some one please explain... (9 Replies)
Discussion started by: mannyisme
9 Replies

5. UNIX Desktop Questions & Answers

Hard Disk

I have a cuestion. How Can I to add other hard disk to my computer? I need to configurate anyone? (4 Replies)
Discussion started by: hmaraver
4 Replies

6. Filesystems, Disks and Memory

hard disk problems

i have recently recieved a new hard drive which i needed for lack of space. i installed a newer version of my previous operating system, suse 8.2. i saved my old drive just in case. anyway this thing only boots sporadically. the person who gave it to me forgot to tell me there was problems with... (2 Replies)
Discussion started by: norsk hedensk
2 Replies

7. Filesystems, Disks and Memory

Adding hard Disk

Hi all, I am using SCO Openserver V and I want to add one more harddisk (/dev/hd1) Hw can I do it? (1 Reply)
Discussion started by: skant
1 Replies

8. Filesystems, Disks and Memory

hard disk meltdown

I had an issue with a second hard disk in my machine. I have a sparc station running solaris 7. It was working fine but now it wont mount on boot up and when you try to mount it manually it gives an I/O error. I tried a different disk as a control which was fine. What I want to know is if my... (3 Replies)
Discussion started by: Henrik
3 Replies

9. UNIX for Dummies Questions & Answers

Divvy a hard disk

What is the general rule for a divvy of a hard disk, I know that the boot is 20 megs swap is times 2 of ram. I am learning unix :) for the first time and at work i cant get this divvy thing down pat yet. boot 1 to 19999 swap 20000 to 122499 (512 megs of ram) root ... (2 Replies)
Discussion started by: DjWolfman
2 Replies

10. Filesystems, Disks and Memory

Divvy a hard disk

What is the general rule for a divvy of a hard disk, I know that the boot is 20 megs swap is times 2 of ram. I am learning unix for the first time and at work i cant get this divvy thing down pat yet. boot 1 to 19999 swap 20000 to 122499 (512 megs of ram) root 122500 to ? u ? u2 ? ... (1 Reply)
Discussion started by: DjWolfman
1 Replies
Login or Register to Ask a Question