The subject is not new and nothing beats the device notifier icon in KDE asking you what to do with a newly inserted flash drive. This post however, is meant to serve only as a note to me, regarding the safest procedure of setting up and mounting a flash drive from the command line.
The current state of affairs is like this: We have a 32GB flash drive that is to be plugged in to a remote LAMP server where we want to place daily database backups. We only have access to the server via ssh so in order to automate the procedure, we are going to initially format the drive using the ext4 file system and then label it so that we won't care about the actual SCSI port that he device will use in the future.
Initial formatting and labelling
After the device has been plugged in for the first time, the easiest way to determine the actual SCSI port is to find the lines containing the word SCSI
in the kernel displayed messages. This is as easy as :
[root@skymnos ~]# dmesg | grep SCSI SCSI subsystem initialized Block layer SCSI generic (bsg) driver version 0.4 loaded (major 252) scsi0 : SCSI emulation for USB Mass Storage devices sd 1:0:0:0: [sdb] Attached SCSI disk sd 0:0:0:0: [sda] Attached SCSI removable disk [root@skymnos ~]#
Alternatively we could use the udisks --monitor
command before pluggin in the device. This would produce output like the following:
[root@skymnos-wifi ~]# udisks --monitor Monitoring activity from the disks daemon. Press Ctrl+C to cancel. added: /org/freedesktop/UDisks/devices/sde added: /org/freedesktop/UDisks/devices/sde1So now we know that out flush drive is located under
/dev/sda
and the partition that we are going to work with is /dev/sda1
. To format it we will use the mkfs.ext4
command with the -L option to specify a label for our file-system.
[root@skymnos ~]# mkfs.ext4 -L dbBackups /dev/sda1 mke2fs 1.41.12 (17-May-2010) Filesystem label=dbBackups OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1949696 inodes, 7790336 blocks 389516 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 238 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 39 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@skymnos ~]#
Mounting
The -L dbBackups
switch that we previously used in order to format the drive, tells mkfs to create a file system with a label of dbBackups. Now if you plug this to a system running a decent window manager with udev, this would be automatically mounted under /media/dbBackups
. We are going the mimic the same behaviour.
[root@skymnos ~]# mkdir /media/dbBackups/ [root@skymnos ~]# mount -L dbBackups /media/dbBackups/ [root@skymnos ~]# df -h /media/dbBackups Filesystem Size Used Avail Use% Mounted on /dev/sda1 30G 172M 28G 1% /media/dbBackups [root@skymnos ~]#
A few more details: Since this is going to be backup storage disk, our lives will become much easier if we create a directory with full read-write permissions inside the drive like this:
[root@skymnos ~]# mkdir /media/dbBackups/data [root@skymnos ~]# chmod o+w /media/dbBackups/data/ [root@skymnos ~]#
So to sum it up. Mounting the flash drive on the remote server from my office machine requires -- well, apart from having someone plug the drive into a USB port doing something like this:
[thanassis@skymnos ~]$ sudo mount -L dbBackups /media/dbBackups/ [thanassis@skymnos-wifi ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 68G 5.1G 62G 8% / tmpfs 1006M 88K 1006M 1% /dev/shm /dev/sdb1 30G 172M 28G 1% /media/dbBackups [thanassis@skymnos ~]$
And what if I wanted the system to attempt to mount the drive each time it boots? In that case all I would have to do is add a line like /bin/mount -L dbBackups /media/dbBackups/
in the /etc/rc.d/rc.local
file
No comments :
Post a Comment