mcgyver83
Posts: 358
Joined: Fri Oct 05, 2012 11:49 am

Where put /var/log folder

Wed Feb 19, 2014 9:04 pm

Hi all, I'm coming back with an idea for /var/log folder.
Log files are written often so sd card could not be the best place to store them; moving /var/log folder to external usb hdd could be a problem: I have an external powered hdd plugged so if the power source is interrupted and connected back again the raspberry will restart but the hdd will remain off causing boot problem to the rasp.
One solution could be plug an usb pendrive, any others idea?

Blanks
Posts: 11
Joined: Thu Jan 30, 2014 8:06 pm

Re: Where put /var/log folder

Wed Feb 19, 2014 9:12 pm

I'm a bit of a Linux noob, but I've heard you can have the log folder stored in RAM so the SD is left alone. I guess that would mean you don't get to keep the logs though...

mcgyver83
Posts: 358
Joined: Fri Oct 05, 2012 11:49 am

Re: Where put /var/log folder

Wed Feb 19, 2014 9:27 pm

RAMLog could be a solution but it will loose logs if power was unplugged.
I heard something regarding logs file synch with filesystem but I have to check.

akc42
Posts: 20
Joined: Tue Jan 10, 2012 7:01 pm
Contact: Website

Re: Where put /var/log folder

Tue Feb 25, 2014 10:58 pm

I just popped in here having not been back for about 6 months and saw this post. I thought it perhaps worth mentioning what I am doing with my complete var partition.

Firstly, I bought a couple of very small usb drives like these (actually I bought this one first, and then bought a second at double the size - but that is for another reason)

http://www.amazon.co.uk/gp/product/B005FYNSZA/

I installed lvm2, inserted one of the thumb drives the usb slot and used pvcreate to turn it into an lvm volume. I then created a volume group (which I called "cruz" based on the product name) on it and two logical volumes (one is for /var so was called /dev/cruz/var and the other, much larger for /var/mail is /dev/cruz/mail) . [The reason for a separate lv for mail was that I can use lvm snapshoting to freeze the mail store for a backup program - but that is another story - so I will now ignore its existance for the rest of this post]

I shut down as much of the system that I could - to avoid writing to /var if I could help it then

Code: Select all

pvcreate /dev/sda1
vgcreate cruz /dev/sda1
lvcreate -L 2G -n var /dev/cruz
mkfs -t ext4 /dev/cruz/var
mkdir -p /mnt/var
mount /dev/cruz/var /mnt/var
mkdir -p /mnt/var/log/
to put a filesystem on it and put the /var/log directory
I then placed this trick

Code: Select all

umount /mnt/var
mount /dev/cruz/var /var
mount --bind / /mnt/var
rsync -a /mnt/var/var/ /var/
To extract the files under /var and put on the new lvm volume now mounted at var.

When I was happy everything was still working I put the mount of /var in /etc/fstab and deleted all the files at /mnt/var/var/*

The reason this is useful is when /var is stating to get worn out is that you can take the second thumb drive and pvcreate it. Add it to the same volume group, and then use pvmove to live move everthing from one device to another, before removing the old device from the system.

Code: Select all

pvcreate /dev/sdb1
vgextend cruz /dev/sdb1
pvmove /dev/sda1 /dev/sdb1
vgreduce /dev/sda1
pvremove /dev/sda1
That way you can leave the pi running whatever it is doing (in my case being a mail server) 24/7









create a mount point under /mnt such as /mnt/var




I then mounted

Return to “Advanced users”