Working with Partitions
Note Packet # 16
CSN115 – Operating Systems Ken Mead Genesee Community College
Commands Covered
Overview of the Process
Overview of the Process
Using dmesg
● If you attached a new hard disk to the system, you can use the dmesg command to get information on its "whereabouts"
$ dmesg |grep ^hd ## for ide disks $ dmesg |grep ^sd ## for scsi/sata disks
will grep all system information spit out out by dmesg that starts with the letters hd. The ^sd means "lines that start with sd".
The fdisk utility
● Used to add, remove, or view disk partitions
● Use as root.
● $fdisk /dev/sda will allow you to modify or view information about the first scsi (sata) disk.
[root@gateway root]# fdisk /dev/sda The number of cylinders for this disk is set to 14589. 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):
fdisk (option m - help)
Output of fdisk -l (or menu item p) current partition info – disk geometry
fdisk command (option l) partition types
mkfs command
● Once a partition is available to the system, you need to assign a filesystem to it.
● mkfs command general form: mkfs.
● you can add additional file system types to your kernel if required.
Examples of mkfs
# mkfs.ext4 /dev/sdb2 (makes standard ext4 filesystem on /dev/sdb2)
# mkfs -t ext4 /dev/sdb2 (same)
# mkfs.vfat /dev/sda1 (vfat filesystem, on sda1)
# mkfs. (then hit tab twice to see supported filesystems) mkfs.ext2 mkfs.ext4 mkfs.ntfs mkfs.xfs mkfs.cramfs mkfs.ext3 mkfs.msdos mkfs.vfat
/etc/fstab
● /etc/fstab configuration file specifies default settings to be used when mounting a partition ● Examples: – what partition to mount as /var ? – as what user should the vfat filesystem be mounted ? – what mount point to use for /dev/cdrom ? – which filesystems to check for errors after a crash ?
/etc/fstab
● First Column: partition to mount – use either UUID, device name (/dev/hda10) or label for that device (LABEL=/boot) – create (or view) labels for partitions using the e2label command: e2label /dev/somepartition [newlabel]
/etc/fstab
● Second Column: mount point (a directory somewhere on the filesystem). ● Third Column: filesystem type – use "auto" to allow the kernel to automatically recognize the file system type.
/etc/fstab
● Fourth Column: mount options – use "defaults" to allow the kernel to mount the filesystem according to the system defaults – noauto: don't automatically mount at boot time – owner: mount as the user who performs the mount command
/etc/fstab
● Column 5: dump frequency (we won't worry about this) ● Column 6: fsck order column (we won't worry about this either).
mount command
● mount (no arguments) : spits out current mounted filesystems
● mount -a : mounts all filesystems in /etc/fstab
● mount with a single argument (partition name, label, or mount point): looks up the information in /etc/fstab and mounts according to specs).
mount /dev/sda3 looks up /dev/sda3 in /etc/fstab
mount /opt looks up /opt in /etc/fstab
mount /dev/sdb2 /mnt/b2 manually mount, don't use fstab
umount and df
● umount: – unmounts a filesystem – nobody can be "in" this filesystem when umount is performed, or you'll get "device is busy" message.
● df: displays information about the currently mounted filesystems.