Linux Raw File system Management
Pretend we have added a new disk to our computer.
The operating system has detected this new disk as device /dev/xvdf.
The following documents the steps we need to take to use this new space.
Partition the device
You may cut the device into separate logical disks.
In my case I want to use the whole disk
sudo fdisk /dev/xvdf # choose needed settings
Format the partition with a filesystem
We want to use ext4 so we do
sudo mkfs.ext4 /dev/xvdf mke2fs 1.42 (29-Nov-2011) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 6553600 inodes, 26214400 blocks 1310720 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 800 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
Mount and test the new filesystem
sudo mount /dev/xvdf1 /mnt touch /mnt/testfile ls /mnt sudo umount /mnt ls /mnt sudo mount /dev/xvdf1 /mnt
Automatically mount partition at system boot
Add an entry into /etc/fstab for new partition.
/dev/xvdf1 /mnt ext4 defaults 0 0
Remount read-only or read-write
Sometimes live disks and rescue modes mount your partitions for you. In my case the rescue was mounting root partition as read-only, and I needed to remove an entry in /etc/fstab. This command will remount a partition with rw:
mount -o remount,rw /dev/mapper/VolGroup00-LogVol0 /
This allowed me to edit /etc/fstab, remove the bad entry and reboot. The server came back online. We still need to figure out what happened to the disk, try to recover it.